This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Fix 64-bit Solaris 2/x86 IE TLS code sequence


Jakub Jelinek <jakub@redhat.com> writes:

> This is a bad idea.  Please surround the tls_symbolic_operand into
> some UNSPEC, having naked tls symbolic operands in the IL is a going to
> cause problems earlier or later.

Here's the patch I've currently have: as mentioned in the original
submission, I've redefined the meaning as TARGET_SUN_TLS.  I've since
learned from the Sun linker maintainers that in Solaris 9 they
introduced their own TLS dialect, only to remove that support again in
Solaris 9 4/04 and replace it by the GNU dialect.  Therefore, it makes
no sense to include that stuff in GCC any longer, so I'm ripping it out;
even Sun as doesn't recognize those relocations.  TARGET_SUN_TLS now
means we're targetting Solaris 2, which is necessary due to their
different reading of the TLS spec.

As requested, I've wrapped add<mode>_1_tls_sun and addsi_1_zext_tls_sun
in a new UNSPEC and removed all the  tls_symbolic_operand predicates.
Still, this doesn't work for my simple testcase

int cnt;
#pragma omp threadprivate (cnt)

int
main (void)
{
  cnt = 0;
  return 0;
}

I get 

        movq    %fs:0, %rax
        movq    cnt@gottpoff(%rip), %rdx
        movl    $0, (%rax,%rdx)

while the second movq should be

        addq    cnt@gottpoff(%rip), %rax

I'm obviously missing something: credit this to my complete ignorance of
code generation issues; I've never had to deal with this part of gcc, so
I'm practically flying blind ;-(

Greatful for any help and suggestions.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2010-03-06  Uros Bizjak <ubizjak@gmail.com>
	    Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc:
	* config/i386/i386.c (override_options): Don't accept
	-mtls-dialect=sun any longer.
	* config/i386/i386.h (TARGET_SUN_TLS): Define as 0.
	* config/i386/i386.md (UNSPEC_TLS_SUN): Define.
	(*add<mode>_1_tls_sun): New pattern.
	(*addsi_1_zext_tls_sun): Likewise.
	(*tls_global_dynamic_32_sun): Remove.
	(*tls_local_dynamic_base_32_sun): Likewise.
	(*load_tp_di_sun): New pattern.
	* config/i386/sol2.h (TARGET_SUN_TLS): Redefine.

diff -r b22f75c5d6d2 -r aacba86470aa gcc/config/i386/i386.c
--- a/gcc/config/i386/i386.c	Mon Mar 15 19:56:09 2010 +0100
+++ b/gcc/config/i386/i386.c	Mon Mar 15 19:56:10 2010 +0100
@@ -3192,8 +3192,6 @@
 	ix86_tls_dialect = TLS_DIALECT_GNU;
       else if (strcmp (ix86_tls_dialect_string, "gnu2") == 0)
 	ix86_tls_dialect = TLS_DIALECT_GNU2;
-      else if (strcmp (ix86_tls_dialect_string, "sun") == 0)
-	ix86_tls_dialect = TLS_DIALECT_SUN;
       else
 	error ("bad value (%s) for %stls-dialect=%s %s",
 	       ix86_tls_dialect_string, prefix, suffix, sw);
@@ -10289,7 +10287,10 @@
   if (!to_reg)
     return tp;
 
-  reg = gen_reg_rtx (Pmode);
+  if (TARGET_64BIT && TARGET_SUN_TLS)
+    reg = gen_rtx_REG (Pmode, AX_REG);
+  else
+    reg = gen_reg_rtx (Pmode);
   insn = gen_rtx_SET (VOIDmode, reg, tp);
   insn = emit_insn (insn);
 
diff -r b22f75c5d6d2 -r aacba86470aa gcc/config/i386/i386.h
--- a/gcc/config/i386/i386.h	Mon Mar 15 19:56:09 2010 +0100
+++ b/gcc/config/i386/i386.h	Mon Mar 15 19:56:10 2010 +0100
@@ -1,6 +1,6 @@
 /* Definitions of target machine for GCC for IA-32.
    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -429,7 +429,7 @@
 #define TARGET_GNU_TLS		(ix86_tls_dialect == TLS_DIALECT_GNU)
 #define TARGET_GNU2_TLS		(ix86_tls_dialect == TLS_DIALECT_GNU2)
 #define TARGET_ANY_GNU_TLS	(TARGET_GNU_TLS || TARGET_GNU2_TLS)
-#define TARGET_SUN_TLS		(ix86_tls_dialect == TLS_DIALECT_SUN)
+#define TARGET_SUN_TLS		0
 
 extern int ix86_isa_flags;
 
diff -r b22f75c5d6d2 -r aacba86470aa gcc/config/i386/i386.md
--- a/gcc/config/i386/i386.md	Mon Mar 15 19:56:09 2010 +0100
+++ b/gcc/config/i386/i386.md	Mon Mar 15 19:56:10 2010 +0100
@@ -1,6 +1,6 @@
 ;; GCC machine description for IA-32 and x86-64.
 ;; Copyright (C) 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 ;; Free Software Foundation, Inc.
 ;; Mostly by William Schelter.
 ;; x86_64 support added by Jan Hubicka
@@ -92,6 +92,7 @@
    (UNSPEC_TLS_GD		21)
    (UNSPEC_TLS_LD_BASE		22)
    (UNSPEC_TLSDESC		23)
+   (UNSPEC_TLS_SUN		24)
 
    ; Other random patterns
    (UNSPEC_SCAS			30)
@@ -5981,6 +5982,20 @@
   [(set_attr "type" "lea")
    (set_attr "mode" "SI")])
 
+(define_insn "*add<mode>_1_tls_sun"
+  [(set (match_operand:SWI48 0 "register_operand" "=a")
+	(unspec:SWI48
+	 [(match_operand:SWI48 1 "register_operand" "0")
+	  (match_operand:SWI48 2 "tls_symbolic_operand" "")]
+	  UNSPEC_TLS_SUN))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_SUN_TLS && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
+{
+    return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
+}
+  [(set_attr "type" "alu")
+   (set_attr "mode" "<MODE>")])
+
 (define_insn "*add<mode>_1"
   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,r,r")
 	(plus:SWI48
@@ -6049,6 +6064,21 @@
 	(const_string "*")))
    (set_attr "mode" "<MODE>")])
 
+(define_insn "*addsi_1_zext_tls_sun"
+  [(set (match_operand:DI 0 "register_operand" "=a")
+	(unspec:DI
+	 [(match_operand:SI 1 "register_operand" "0")
+	  (match_operand:SI 2 "tls_symbolic_operand" "")]
+	  UNSPEC_TLS_SUN))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_SUN_TLS && TARGET_64BIT
+   && ix86_binary_operator_ok (PLUS, SImode, operands)"
+{
+  return "add{l}\t{%2, %k0|%k0, %2}";
+}
+  [(set_attr "type" "alu")
+   (set_attr "mode" "SI")])
+
 ;; It may seem that nonimmediate operand is proper one for operand 1.
 ;; The addsi_1 pattern allows nonimmediate operand at that place and
 ;; we take care in ix86_binary_operator_ok to not allow two memory
@@ -14495,21 +14525,6 @@
   [(set_attr "type" "multi")
    (set_attr "length" "12")])
 
-(define_insn "*tls_global_dynamic_32_sun"
-  [(set (match_operand:SI 0 "register_operand" "=a")
-	(unspec:SI [(match_operand:SI 1 "register_operand" "b")
-		    (match_operand:SI 2 "tls_symbolic_operand" "")
-		    (match_operand:SI 3 "call_insn_operand" "")]
-		    UNSPEC_TLS_GD))
-   (clobber (match_scratch:SI 4 "=d"))
-   (clobber (match_scratch:SI 5 "=c"))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && TARGET_SUN_TLS"
-  "lea{l}\t{%a2@DTLNDX(%1), %4|%4, %a2@DTLNDX[%1]}
-	push{l}\t%4\;call\t%a2@TLSPLT\;pop{l}\t%4\;nop"
-  [(set_attr "type" "multi")
-   (set_attr "length" "14")])
-
 (define_expand "tls_global_dynamic_32"
   [(parallel [(set (match_operand:SI 0 "register_operand" "")
 		   (unspec:SI
@@ -14578,20 +14593,6 @@
   [(set_attr "type" "multi")
    (set_attr "length" "11")])
 
-(define_insn "*tls_local_dynamic_base_32_sun"
-  [(set (match_operand:SI 0 "register_operand" "=a")
-	(unspec:SI [(match_operand:SI 1 "register_operand" "b")
-                    (match_operand:SI 2 "call_insn_operand" "")]
-		   UNSPEC_TLS_LD_BASE))
-   (clobber (match_scratch:SI 3 "=d"))
-   (clobber (match_scratch:SI 4 "=c"))
-   (clobber (reg:CC FLAGS_REG))]
-  "!TARGET_64BIT && TARGET_SUN_TLS"
-  "lea{l}\t{%&@TMDNX(%1), %3|%3, %&@TMDNX[%1]}
-	push{l}\t%3\;call\t%&@TLSPLT\;pop{l}\t%3"
-  [(set_attr "type" "multi")
-   (set_attr "length" "13")])
-
 (define_expand "tls_local_dynamic_base_32"
   [(parallel [(set (match_operand:SI 0 "register_operand" "")
 		   (unspec:SI [(match_dup 1) (match_dup 2)]
@@ -14693,6 +14694,17 @@
    (set_attr "memory" "load")
    (set_attr "imm_disp" "false")])
 
+(define_insn "*load_tp_di_sun"
+   [(set (match_operand:DI 0 "register_operand" "=a")
+     (unspec:DI [(const_int 0)] UNSPEC_TP))]
+   "TARGET_64BIT && TARGET_SUN_TLS"
+   "mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}"
+   [(set_attr "type" "imov")
+    (set_attr "modrm" "0")
+    (set_attr "length" "7")
+    (set_attr "memory" "load")
+    (set_attr "imm_disp" "false")])
+
 (define_insn "*load_tp_di"
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(unspec:DI [(const_int 0)] UNSPEC_TP))]
diff -r b22f75c5d6d2 -r aacba86470aa gcc/config/i386/sol2.h
--- a/gcc/config/i386/sol2.h	Mon Mar 15 19:56:09 2010 +0100
+++ b/gcc/config/i386/sol2.h	Mon Mar 15 19:56:10 2010 +0100
@@ -91,6 +91,11 @@
       }							\
   } while (0)
 
+/* Follow Sun requirements for TLS code sequences and use Sun assembler TLS
+   syntax.  */
+#undef TARGET_SUN_TLS
+#define TARGET_SUN_TLS 1
+
 /* The Solaris assembler cannot grok .stabd directives.  */
 #undef NO_DBX_BNSYM_ENSYM
 #define NO_DBX_BNSYM_ENSYM 1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]