diff mbox

Fix 64-bit Solaris 2/x86 IE TLS code sequence (PR target/43309)

Message ID AANLkTi=NXsqPg=ea4jTDH05nRnH6eoCEkECSY37MjLJ7@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Dec. 25, 2010, 6:48 p.m. UTC
On Wed, Dec 22, 2010 at 3:34 PM, Rainer Orth
<ro@cebitec.uni-bielefeld.de> wrote:
> Richard Henderson <rth@redhat.com> writes:
>
>> I thought that might happen, Uros.  You can't split the patterns
>> for Sun ld.
>
> How should we proceed from here?  Return to my version of the patch?
> While performing a x86_64-unknown-linux-gnu bootstrap for good measure,
> I noticed that there's a problem there: bootstrap fails like this:
>
> /var/gcc/src/hg/trunk/solaris/gcc/config/i386/i386.c: In function 'legitimize_tls_address':
> /var/gcc/src/hg/trunk/solaris/gcc/config/i386/i386.c:12551:4: error: implicit declaration of function 'gen_tls_initial_exec_64_sun' [-Werror=implicit-function-declaration]
> /var/gcc/src/hg/trunk/solaris/gcc/config/i386/i386.c:12551:4: error: passing argument 1 of 'emit_insn' makes pointer from integer without a cast [-Werror]
> /var/gcc/src/hg/trunk/solaris/gcc/rtl.h:1725:12: note: expected 'rtx' but argument is of type 'int'
> cc1: all warnings being treated as errors
>
> make[3]: *** [i386.o] Error 1
>
> gen_tls_initial_exec_64_sun isn't declared in insn-flags.h, probably
> because TARGET_SUN_TLS is 0 in i386.h.  What's the best way to avoid
> this?  Wrap the TARGET_64BIT && TARGET_SUN_TLS section in i386.c
> (legitimize_tls_address) in #if TARGET_SUN_TLS?

Attached variant of your original patch works for me - I have
bootstrapped and regression test the patch on x86_64-pc-linux-gnu.

Uros.
diff mbox

Patch

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 168243)
+++ config/i386/i386.md	(working copy)
@@ -93,6 +93,7 @@ 
   UNSPEC_TLS_GD
   UNSPEC_TLS_LD_BASE
   UNSPEC_TLSDESC
+  UNSPEC_TLS_IE_SUN
 
   ;; Other random patterns
   UNSPEC_SCAS
@@ -12686,6 +12687,18 @@ 
    (set_attr "memory" "load")
    (set_attr "imm_disp" "false")])
 
+;; The SUN linker took the AMD64 TLS spec literally and can only handle
+;; %rax as destination of the initial executable code sequence.
+(define_insn "tls_initial_exec_64_sun"
+  [(set (match_operand:DI 0 "register_operand" "=a")
+	(unspec:DI
+	 [(match_operand:DI 1 "tls_symbolic_operand" "")]
+	 UNSPEC_TLS_IE_SUN))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_64BIT && TARGET_SUN_TLS"
+  "mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}\n\tadd{q}\t{%a1@gottpoff(%%rip), %0|%0, %a1@gottpoff[rip]}"
+  [(set_attr "type" "multi")])
+
 ;; GNU2 TLS patterns can be split.
 
 (define_expand "tls_dynamic_gnu2_32"
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 168243)
+++ config/i386/i386.c	(working copy)
@@ -12542,6 +12542,17 @@ 
     case TLS_MODEL_INITIAL_EXEC:
       if (TARGET_64BIT)
 	{
+	  if (TARGET_SUN_TLS)
+	    {
+	      /* The SUN linker took the AMD64 TLS spec literally
+		 and can only handle %rax as destination of the
+		 initial executable code sequence.  */
+
+	      dest = gen_reg_rtx (Pmode);
+	      emit_insn (gen_tls_initial_exec_64_sun (dest, x));
+	      return dest;
+	    }
+
 	  pic = NULL;
 	  type = UNSPEC_GOTNTPOFF;
 	}