Blame SOURCES/binutils-2.23.52.0.1-x86-64-mcmodel=large-tls.patch

f55871
2013-08-29  Jakub Jelinek  <jakub@redhat.com>
f55871
f55871
	* elf64-x86-64.c (elf_x86_64_check_tls_transition): Allow
f55871
	64-bit -mcmodel=large -fpic TLS GD and LD sequences.
f55871
	(elf_x86_64_relocate_section): Handle -mcmodel=large -fpic
f55871
	TLS GD and LD sequences in GD->LE, GD->IE and LD->LE transitions.
f55871
ld/testsuite/
f55871
	* ld-x86-64/x86-64.exp: Add tlsld3, tlsgd7 and tlsgd8 tests.
f55871
	* ld-x86-64/tlspic1.s: Add -mcmodel=large -fpic TLS GD and LD
f55871
	sequences.
f55871
	* ld-x86-64/tlspic.dd: Adjusted.
f55871
	* ld-x86-64/tlspic.rd: Adjusted.
f55871
	* ld-x86-64/tlspic-nacl.rd: Adjusted.
f55871
	* ld-x86-64/tlsld3.dd: New test.
f55871
	* ld-x86-64/tlsld3.s: New file.
f55871
	* ld-x86-64/tlsgd7.dd: New test.
f55871
	* ld-x86-64/tlsgd7.s: New file.
f55871
	* ld-x86-64/tlsgd8.dd: New test.
f55871
	* ld-x86-64/tlsgd8.s: New file.
f55871
f55871
--- bfd/elf64-x86-64.c.jj	2013-08-28 17:58:32.549408509 +0200
f55871
+++ bfd/elf64-x86-64.c	2013-08-28 17:33:13.738626828 +0200
f55871
@@ -1089,6 +1089,7 @@ elf_x86_64_check_tls_transition (bfd *ab
f55871
 {
f55871
   unsigned int val;
f55871
   unsigned long r_symndx;
f55871
+  bfd_boolean largepic = FALSE;
f55871
   struct elf_link_hash_entry *h;
f55871
   bfd_vma offset;
f55871
   struct elf_x86_64_link_hash_table *htab;
f55871
@@ -1126,16 +1127,32 @@ elf_x86_64_check_tls_transition (bfd *ab
f55871
 	     can transit to different access model.  For 32bit, only
f55871
 		leaq foo@tlsgd(%rip), %rdi
f55871
 		.word 0x6666; rex64; call __tls_get_addr
f55871
-	     can transit to different access model.  */
f55871
+	     can transit to different access model.  For largepic
f55871
+	     we also support:
f55871
+	        leaq foo@tlsgd(%rip), %rdi
f55871
+	        movabsq $__tls_get_addr@pltoff, %rax
f55871
+	        addq $rbx, %rax
f55871
+	        call *%rax.  */
f55871
 
f55871
 	  static const unsigned char call[] = { 0x66, 0x66, 0x48, 0xe8 };
f55871
 	  static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
f55871
 
f55871
-	  if ((offset + 12) > sec->size
f55871
-	      || memcmp (contents + offset + 4, call, 4) != 0)
f55871
+	  if ((offset + 12) > sec->size)
f55871
 	    return FALSE;
f55871
 
f55871
-	  if (ABI_64_P (abfd))
f55871
+	  if (memcmp (contents + offset + 4, call, 4) != 0)
f55871
+	    {
f55871
+	      if (!ABI_64_P (abfd)
f55871
+		  || (offset + 19) > sec->size
f55871
+		  || offset < 3
f55871
+		  || memcmp (contents + offset - 3, leaq + 1, 3) != 0
f55871
+		  || memcmp (contents + offset + 4, "\x48\xb8", 2) != 0
f55871
+		  || memcmp (contents + offset + 14, "\x48\x01\xd8\xff\xd0", 5)
f55871
+		     != 0)
f55871
+		return FALSE;
f55871
+	      largepic = TRUE;
f55871
+	    }
f55871
+	  else if (ABI_64_P (abfd))
f55871
 	    {
f55871
 	      if (offset < 4
f55871
 		  || memcmp (contents + offset - 4, leaq, 4) != 0)
f55871
@@ -1153,16 +1170,31 @@ elf_x86_64_check_tls_transition (bfd *ab
f55871
 	  /* Check transition from LD access model.  Only
f55871
 		leaq foo@tlsld(%rip), %rdi;
f55871
 		call __tls_get_addr
f55871
-	     can transit to different access model.  */
f55871
+	     can transit to different access model.  For largepic
f55871
+	     we also support:
f55871
+	        leaq foo@tlsld(%rip), %rdi
f55871
+	        movabsq $__tls_get_addr@pltoff, %rax
f55871
+	        addq $rbx, %rax
f55871
+	        call *%rax.  */
f55871
 
f55871
 	  static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
f55871
 
f55871
 	  if (offset < 3 || (offset + 9) > sec->size)
f55871
 	    return FALSE;
f55871
 
f55871
-	  if (memcmp (contents + offset - 3, lea, 3) != 0
f55871
-	      || 0xe8 != *(contents + offset + 4))
f55871
+	  if (memcmp (contents + offset - 3, lea, 3) != 0)
f55871
 	    return FALSE;
f55871
+
f55871
+	  if (0xe8 != *(contents + offset + 4))
f55871
+	    {
f55871
+	      if (!ABI_64_P (abfd)
f55871
+		  || (offset + 19) > sec->size
f55871
+		  || memcmp (contents + offset + 4, "\x48\xb8", 2) != 0
f55871
+		  || memcmp (contents + offset + 14, "\x48\x01\xd8\xff\xd0", 5)
f55871
+		     != 0)
f55871
+		return FALSE;
f55871
+	      largepic = TRUE;
f55871
+	    }
f55871
 	}
f55871
 
f55871
       r_symndx = htab->r_sym (rel[1].r_info);
f55871
@@ -1174,8 +1206,10 @@ elf_x86_64_check_tls_transition (bfd *ab
f55871
 	 may be versioned.  */
f55871
       return (h != NULL
f55871
 	      && h->root.root.string != NULL
f55871
-	      && (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
f55871
-		  || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
f55871
+	      && (largepic
f55871
+		  ? ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLTOFF64
f55871
+		  : (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
f55871
+		     || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32))
f55871
 	      && (strncmp (h->root.root.string,
f55871
 			   "__tls_get_addr", 14) == 0));
f55871
 
f55871
@@ -3949,8 +3983,26 @@ direct:
f55871
 		     .word 0x6666; rex64; call __tls_get_addr
f55871
 		     into:
f55871
 		     movl %fs:0, %eax
f55871
-		     leaq foo@tpoff(%rax), %rax */
f55871
-		  if (ABI_64_P (output_bfd))
f55871
+		     leaq foo@tpoff(%rax), %rax
f55871
+		     For largepic, change:
f55871
+		     leaq foo@tlsgd(%rip), %rdi
f55871
+		     movabsq $__tls_get_addr@pltoff, %rax
f55871
+		     addq %rbx, %rax
f55871
+		     call *%rax
f55871
+		     into:
f55871
+		     movq %fs:0, %rax
f55871
+		     leaq foo@tpoff(%rax), %rax
f55871
+		     nopw 0x0(%rax,%rax,1) */
f55871
+		  int largepic = 0;
f55871
+		  if (ABI_64_P (output_bfd)
f55871
+		      && contents[roff + 5] == (bfd_byte) '\xb8')
f55871
+		    {
f55871
+		      memcpy (contents + roff - 3,
f55871
+			      "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
f55871
+			      "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
f55871
+		      largepic = 1;
f55871
+		    }
f55871
+		  else if (ABI_64_P (output_bfd))
f55871
 		    memcpy (contents + roff - 4,
f55871
 			    "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
f55871
 			    16);
f55871
@@ -3960,8 +4012,8 @@ direct:
f55871
 			    15);
f55871
 		  bfd_put_32 (output_bfd,
f55871
 			      elf_x86_64_tpoff (info, relocation),
f55871
-			      contents + roff + 8);
f55871
-		  /* Skip R_X86_64_PC32/R_X86_64_PLT32.  */
f55871
+			      contents + roff + 8 + largepic);
f55871
+		  /* Skip R_X86_64_PC32/R_X86_64_PLT32/R_X86_64_PLTOFF64.  */
f55871
 		  rel++;
f55871
 		  continue;
f55871
 		}
f55871
@@ -4196,8 +4248,26 @@ direct:
f55871
 		     .word 0x6666; rex64; call __tls_get_addr@plt
f55871
 		     into:
f55871
 		     movl %fs:0, %eax
f55871
-		     addq foo@gottpoff(%rip), %rax */
f55871
-		  if (ABI_64_P (output_bfd))
f55871
+		     addq foo@gottpoff(%rip), %rax
f55871
+		     For largepic, change:
f55871
+		     leaq foo@tlsgd(%rip), %rdi
f55871
+		     movabsq $__tls_get_addr@pltoff, %rax
f55871
+		     addq %rbx, %rax
f55871
+		     call *%rax
f55871
+		     into:
f55871
+		     movq %fs:0, %rax
f55871
+		     addq foo@gottpoff(%rax), %rax
f55871
+		     nopw 0x0(%rax,%rax,1) */
f55871
+		  int largepic = 0;
f55871
+		  if (ABI_64_P (output_bfd)
f55871
+		      && contents[roff + 5] == (bfd_byte) '\xb8')
f55871
+		    {
f55871
+		      memcpy (contents + roff - 3,
f55871
+			      "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
f55871
+			      "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
f55871
+		      largepic = 1;
f55871
+		    }
f55871
+		  else if (ABI_64_P (output_bfd))
f55871
 		    memcpy (contents + roff - 4,
f55871
 			    "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
f55871
 			    16);
f55871
@@ -4209,12 +4279,13 @@ direct:
f55871
 		  relocation = (htab->elf.sgot->output_section->vma
f55871
 				+ htab->elf.sgot->output_offset + off
f55871
 				- roff
f55871
+				- largepic
f55871
 				- input_section->output_section->vma
f55871
 				- input_section->output_offset
f55871
 				- 12);
f55871
 		  bfd_put_32 (output_bfd, relocation,
f55871
-			      contents + roff + 8);
f55871
-		  /* Skip R_X86_64_PLT32.  */
f55871
+			      contents + roff + 8 + largepic);
f55871
+		  /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64.  */
f55871
 		  rel++;
f55871
 		  continue;
f55871
 		}
f55871
@@ -4276,16 +4347,29 @@ direct:
f55871
 		 For 64bit, we change it into:
f55871
 		 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
f55871
 		 For 32bit, we change it into:
f55871
-		 nopl 0x0(%rax); movl %fs:0, %eax.  */
f55871
+		 nopl 0x0(%rax); movl %fs:0, %eax.
f55871
+		 For largepic, change:
f55871
+		 leaq foo@tlsgd(%rip), %rdi
f55871
+		 movabsq $__tls_get_addr@pltoff, %rax
f55871
+		 addq %rbx, %rax
f55871
+		 call *%rax
f55871
+		 into:
f55871
+		 data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)
f55871
+		 movq %fs:0, %eax */
f55871
 
f55871
 	      BFD_ASSERT (r_type == R_X86_64_TPOFF32);
f55871
-	      if (ABI_64_P (output_bfd))
f55871
+	      if (ABI_64_P (output_bfd)
f55871
+		  && contents[rel->r_offset + 5] == (bfd_byte) '\xb8')
f55871
+		memcpy (contents + rel->r_offset - 3,
f55871
+			"\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
f55871
+			"\x64\x48\x8b\x04\x25\0\0\0", 22);
f55871
+	      else if (ABI_64_P (output_bfd))
f55871
 		memcpy (contents + rel->r_offset - 3,
f55871
 			"\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
f55871
 	      else
f55871
 		memcpy (contents + rel->r_offset - 3,
f55871
 			"\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
f55871
-	      /* Skip R_X86_64_PC32/R_X86_64_PLT32.  */
f55871
+	      /* Skip R_X86_64_PC32/R_X86_64_PLT32/R_X86_64_PLTOFF64.  */
f55871
 	      rel++;
f55871
 	      continue;
f55871
 	    }
f55871
--- ld/testsuite/ld-x86-64/tlsgd7.dd.jj	2013-08-28 18:57:11.655623528 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsgd7.dd	2013-08-28 20:46:30.469141384 +0200
f55871
@@ -0,0 +1,23 @@
f55871
+#source: tlsgd7.s
f55871
+#as: --64
f55871
+#ld: -melf_x86_64 tmpdir/tlsgd7
f55871
+#objdump: -drw
f55871
+#target: x86_64-*-linux*
f55871
+
f55871
+.*: +file format .*
f55871
+
f55871
+Disassembly of section .text:
f55871
+
f55871
+[a-f0-9]+ <_start>:
f55871
+[ 	]*[a-f0-9]+:	49 bb ([0-9a-f]{2} ){8}	movabs \$0x[0-9a-f]+,%r11
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	48 8d 1d ed ff ff ff 	lea    -0x13\(%rip\),%rbx        # [0-9a-f]+ <_start>
f55871
+[ 	]*[a-f0-9]+:	4c 01 db             	add    %r11,%rbx
f55871
+[ 	]*[a-f0-9]+:	64 48 8b 04 25 00 00 00 00 	mov    %fs:0x0,%rax
f55871
+[ 	]*[a-f0-9]+:	48 8d 80 fc ff ff ff 	lea    -0x4\(%rax\),%rax
f55871
+[ 	]*[a-f0-9]+:	66 0f 1f 44 00 00    	nopw   0x0\(%rax,%rax,1\)
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	c3                   	retq   
f55871
+#pass
f55871
--- ld/testsuite/ld-x86-64/tlspic.dd.jj	2013-08-13 13:42:26.000000000 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlspic.dd	2013-08-29 12:12:18.724775938 +0200
f55871
@@ -224,6 +224,163 @@ Disassembly of section .text:
f55871
  +11a5:	90[ 	]+nop *
f55871
  +11a6:	90[ 	]+nop *
f55871
  +11a7:	90[ 	]+nop *
f55871
- +11a8:	c9[ 	]+leaveq *
f55871
- +11a9:	c3[ 	]+retq *
f55871
- +11aa:	66 90[ 	]+xchg   %ax,%ax
f55871
+ +11a8:	49 bb ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%r11
f55871
+ +11af:	([0-9a-f]{2} ){3}
f55871
+ +11b2:	53[ 	]+push   %rbx
f55871
+ +11b3:	53[ 	]+push   %rbx
f55871
+ +11b4:	48 8d 1d ed ff ff ff[ 	]+lea    -0x13\(%rip\),%rbx +# [0-9a-f]+ <fn1\+0x[0-9a-f]+>
f55871
+ +11bb:	4c 01 db[ 	]+add    %r11,%rbx
f55871
+ +11be:	90[ 	]+nop *
f55871
+ +11bf:	90[ 	]+nop *
f55871
+ +11c0:	90[ 	]+nop *
f55871
+ +11c1:	90[ 	]+nop *
f55871
+# -mcmodel=large sequences
f55871
+#
f55871
+#  -mcmodel=large GD
f55871
+ +11c2:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x180>
f55871
+#				-> R_X86_64_DTPMOD64	sg1
f55871
+ +11c9:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +11d0:	([0-9a-f]{2} ){3}
f55871
+ +11d3:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +11d6:	ff d0[ 	]+callq  \*%rax
f55871
+ +11d8:	90[ 	]+nop *
f55871
+ +11d9:	90[ 	]+nop *
f55871
+ +11da:	90[ 	]+nop *
f55871
+ +11db:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD -> IE because variable is referenced through IE too
f55871
+#				-> R_X86_64_TPOFF64	sg2
f55871
+ +11dc:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
f55871
+ +11e3:	00 00 
f55871
+ +11e5:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <_DYNAMIC\+0x1a0>
f55871
+#				-> R_X86_64_TPOFF64	sg2
f55871
+ +11ec:	66 0f 1f 44 00 00[ 	]+nopw   0x0\(%rax,%rax,1\)
f55871
+ +11f2:	90[ 	]+nop *
f55871
+ +11f3:	90[ 	]+nop *
f55871
+ +11f4:	90[ 	]+nop *
f55871
+ +11f5:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD against local variable
f55871
+ +11f6:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x130>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x2000000000000000]
f55871
+ +11fd:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +1204:	([0-9a-f]{2} ){3}
f55871
+ +1207:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +120a:	ff d0[ 	]+callq  \*%rax
f55871
+ +120c:	90[ 	]+nop *
f55871
+ +120d:	90[ 	]+nop *
f55871
+ +120e:	90[ 	]+nop *
f55871
+ +120f:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD -> IE against local variable referenced through IE too
f55871
+ +1210:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
f55871
+ +1217:	00 00 
f55871
+ +1219:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <_DYNAMIC\+0x140>
f55871
+#				-> R_X86_64_TPOFF64	*ABS*+0x24
f55871
+ +1220:	66 0f 1f 44 00 00[ 	]+nopw   0x0\(%rax,%rax,1\)
f55871
+ +1226:	90[ 	]+nop *
f55871
+ +1227:	90[ 	]+nop *
f55871
+ +1228:	90[ 	]+nop *
f55871
+ +1229:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD against hidden and local variable
f55871
+ +122a:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x1a8>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x4000000000000000]
f55871
+ +1231:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +1238:	([0-9a-f]{2} ){3}
f55871
+ +123b:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +123e:	ff d0[ 	]+callq  \*%rax
f55871
+ +1240:	90[ 	]+nop *
f55871
+ +1241:	90[ 	]+nop *
f55871
+ +1242:	90[ 	]+nop *
f55871
+ +1243:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD -> IE against hidden and local variable referenced through IE too
f55871
+ +1244:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
f55871
+ +124b:	00 00 
f55871
+ +124d:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <_DYNAMIC\+0x1b8>
f55871
+#				-> R_X86_64_TPOFF64	*ABS*+0x44
f55871
+ +1254:	66 0f 1f 44 00 00[ 	]+nopw   0x0\(%rax,%rax,1\)
f55871
+ +125a:	90[ 	]+nop *
f55871
+ +125b:	90[ 	]+nop *
f55871
+ +125c:	90[ 	]+nop *
f55871
+ +125d:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD against hidden but not local variable
f55871
+ +125e:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x160>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x6000000000000000]
f55871
+ +1265:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +126c:	([0-9a-f]{2} ){3}
f55871
+ +126f:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +1272:	ff d0[ 	]+callq  \*%rax
f55871
+ +1274:	90[ 	]+nop *
f55871
+ +1275:	90[ 	]+nop *
f55871
+ +1276:	90[ 	]+nop *
f55871
+ +1277:	90[ 	]+nop *
f55871
+#  -mcmodel=large GD -> IE against hidden but not local variable referenced through IE too
f55871
+ +1278:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
f55871
+ +127f:	00 00 
f55871
+ +1281:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <_DYNAMIC\+0x170>
f55871
+#				-> R_X86_64_TPOFF64	*ABS*+0x64
f55871
+ +1288:	66 0f 1f 44 00 00[ 	]+nopw   0x0\(%rax,%rax,1\)
f55871
+ +128e:	90[ 	]+nop *
f55871
+ +128f:	90[ 	]+nop *
f55871
+ +1290:	90[ 	]+nop *
f55871
+ +1291:	90[ 	]+nop *
f55871
+#  -mcmodel=large LD
f55871
+ +1292:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x150>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x000000000000000]
f55871
+ +1299:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +12a0:	([0-9a-f]{2} ){3}
f55871
+ +12a3:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +12a6:	ff d0[ 	]+callq  \*%rax
f55871
+ +12a8:	90[ 	]+nop *
f55871
+ +12a9:	90[ 	]+nop *
f55871
+ +12aa:	48 8d 90 20 00 00 00[ 	]+lea    0x20\(%rax\),%rdx
f55871
+ +12b1:	90[ 	]+nop *
f55871
+ +12b2:	90[ 	]+nop *
f55871
+ +12b3:	4c 8d 88 26 00 00 00[ 	]+lea    0x26\(%rax\),%r9
f55871
+ +12ba:	90[ 	]+nop *
f55871
+ +12bb:	90[ 	]+nop *
f55871
+ +12bc:	90[ 	]+nop *
f55871
+ +12bd:	90[ 	]+nop *
f55871
+#  -mcmodel=large LD against hidden and local variables
f55871
+ +12be:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x150>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x000000000000000]
f55871
+ +12c5:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +12cc:	([0-9a-f]{2} ){3}
f55871
+ +12cf:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +12d2:	ff d0[ 	]+callq  \*%rax
f55871
+ +12d4:	90[ 	]+nop *
f55871
+ +12d5:	90[ 	]+nop *
f55871
+ +12d6:	48 8d 90 40 00 00 00[ 	]+lea    0x40\(%rax\),%rdx
f55871
+ +12dd:	90[ 	]+nop *
f55871
+ +12de:	90[ 	]+nop *
f55871
+ +12df:	48 8d 88 47 00 00 00[ 	]+lea    0x47\(%rax\),%rcx
f55871
+ +12e6:	90[ 	]+nop *
f55871
+ +12e7:	90[ 	]+nop *
f55871
+ +12e8:	90[ 	]+nop *
f55871
+ +12e9:	90[ 	]+nop *
f55871
+#  -mcmodel=large LD against hidden but not local variables
f55871
+ +12ea:	48 8d 3d ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <_DYNAMIC\+0x150>
f55871
+#				-> R_X86_64_DTPMOD64	[0 0x000000000000000]
f55871
+ +12f1:	48 b8 ([0-9a-f]{2} ){5}[ 	]+movabs \$0x[0-9a-f]+,%rax
f55871
+#				-> R_X86_64_JUMP_SLOT	__tls_get_addr
f55871
+ +12f8:	([0-9a-f]{2} ){3}
f55871
+ +12fb:	48 01 d8[ 	]+add    %rbx,%rax
f55871
+ +12fe:	ff d0[ 	]+callq  \*%rax
f55871
+ +1300:	90[ 	]+nop *
f55871
+ +1301:	90[ 	]+nop *
f55871
+ +1302:	4c 8d a0 60 00 00 00[ 	]+lea    0x60\(%rax\),%r12
f55871
+ +1309:	90[ 	]+nop *
f55871
+ +130a:	90[ 	]+nop *
f55871
+ +130b:	48 8d 88 65 00 00 00[ 	]+lea    0x65\(%rax\),%rcx
f55871
+ +1312:	90[ 	]+nop *
f55871
+ +1313:	90[ 	]+nop *
f55871
+ +1314:	90[ 	]+nop *
f55871
+ +1315:	90[ 	]+nop *
f55871
+ +1316:	5b[ 	]+pop    %rbx
f55871
+ +1317:	5b[ 	]+pop    %rbx
f55871
+ +1318:	c9[ 	]+leaveq *
f55871
+ +1319:	c3[ 	]+retq *
f55871
+ +131a:	66 90[ 	]+xchg   %ax,%ax
f55871
--- ld/testsuite/ld-x86-64/tlsld3.dd.jj	2013-08-28 18:58:29.020210650 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsld3.dd	2013-08-28 20:55:12.959317891 +0200
f55871
@@ -0,0 +1,23 @@
f55871
+#source: tlsld3.s
f55871
+#as: --64
f55871
+#ld: -melf_x86_64 tmpdir/tlsld3
f55871
+#objdump: -drw
f55871
+#target: x86_64-*-linux*
f55871
+
f55871
+.*: +file format .*
f55871
+
f55871
+Disassembly of section .text:
f55871
+
f55871
+[a-f0-9]+ <_start>:
f55871
+[ 	]*[a-f0-9]+:	49 bb ([0-9a-f]{2} ){8}	movabs \$0x[0-9a-f]+,%r11
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	48 8d 1d ed ff ff ff 	lea    -0x13\(%rip\),%rbx        # [0-9a-f]+ <_start>
f55871
+[ 	]*[a-f0-9]+:	4c 01 db             	add    %r11,%rbx
f55871
+[ 	]*[a-f0-9]+:	66 66 66 66 2e 0f 1f 84 00 00 00 00 00 	data32 data32 data32 nopw %cs:0x0\(%rax,%rax,1\)
f55871
+[ 	]*[a-f0-9]+:	64 48 8b 04 25 00 00 00 00 	mov    %fs:0x0,%rax
f55871
+[ 	]*[a-f0-9]+:	8b 80 fc ff ff ff    	mov    -0x4\(%rax\),%eax
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	c3                   	retq   
f55871
+#pass
f55871
--- ld/testsuite/ld-x86-64/tlsld3.s.jj	2013-08-28 18:44:26.341741095 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsld3.s	2013-08-28 20:50:53.190720964 +0200
f55871
@@ -0,0 +1,27 @@
f55871
+	.text
f55871
+	.globl _start
f55871
+_start:
f55871
+1:	movabsq	$_GLOBAL_OFFSET_TABLE_-1b, %r11
f55871
+	pushq	%rbx
f55871
+	pushq	%rbx
f55871
+	leaq	1b(%rip), %rbx
f55871
+	addq	%r11, %rbx
f55871
+
f55871
+	/* LD, -mcmodel=large  */
f55871
+	leaq	foo@tlsld(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+
f55871
+	movl	foo@dtpoff(%rax), %eax
f55871
+
f55871
+	popq	%rbx
f55871
+	popq	%rbx
f55871
+	ret
f55871
+	.globl foo
f55871
+	.section	.tdata,"awT",@progbits
f55871
+	.align 4
f55871
+	.type	foo, @object
f55871
+	.size	foo, 4
f55871
+foo:
f55871
+	.long	100
f55871
--- ld/testsuite/ld-x86-64/tlspic.rd.jj	2013-08-13 13:42:26.000000000 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlspic.rd	2013-08-28 23:16:49.751620744 +0200
f55871
@@ -16,12 +16,12 @@ Section Headers:
f55871
  +\[[ 0-9]+\] .rela.dyn +.*
f55871
  +\[[ 0-9]+\] .rela.plt +.*
f55871
  +\[[ 0-9]+\] .plt +.*
f55871
- +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+1ac 00 +AX +0 +0 4096
f55871
- +\[[ 0-9]+\] .tdata +PROGBITS +0+2011ac 0+11ac 0+60 00 WAT +0 +0 +1
f55871
- +\[[ 0-9]+\] .tbss +NOBITS +0+20120c 0+120c 0+20 00 WAT +0 +0 +1
f55871
- +\[[ 0-9]+\] .dynamic +DYNAMIC +0+201210 0+1210 0+130 10 +WA +3 +0 +8
f55871
- +\[[ 0-9]+\] .got +PROGBITS +0+201340 0+1340 0+90 08 +WA +0 +0 +8
f55871
- +\[[ 0-9]+\] .got.plt +PROGBITS +0+2013d0 0+13d0 0+20 08 +WA +0 +0 +8
f55871
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+31c 00 +AX +0 +0 4096
f55871
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+20131c 0+131c 0+60 00 WAT +0 +0 +1
f55871
+ +\[[ 0-9]+\] .tbss +NOBITS +0+20137c 0+137c 0+20 00 WAT +0 +0 +1
f55871
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+201380 0+1380 0+130 10 +WA +3 +0 +8
f55871
+ +\[[ 0-9]+\] .got +PROGBITS +0+2014b0 0+14b0 0+90 08 +WA +0 +0 +8
f55871
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+201540 0+1540 0+20 08 +WA +0 +0 +8
f55871
  +\[[ 0-9]+\] .shstrtab +.*
f55871
  +\[[ 0-9]+\] .symtab +.*
f55871
  +\[[ 0-9]+\] .strtab +.*
f55871
@@ -37,9 +37,9 @@ There are [0-9]+ program headers, starti
f55871
 Program Headers:
f55871
  +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
f55871
  +LOAD +0x0+ 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
f55871
- +LOAD +0x0+11ac 0x0+2011ac 0x0+2011ac 0x0+244 0x0+244 RW +0x200000
f55871
- +DYNAMIC +0x0+1210 0x0+201210 0x0+201210 0x0+130 0x0+130 RW +0x8
f55871
- +TLS +0x0+11ac 0x0+2011ac 0x0+2011ac 0x0+60 0x0+80 R +0x1
f55871
+ +LOAD +0x0+131c 0x0+20131c 0x0+20131c 0x0+244 0x0+244 RW +0x200000
f55871
+ +DYNAMIC +0x0+1380 0x0+201380 0x0+201380 0x0+130 0x0+130 RW +0x8
f55871
+ +TLS +0x0+131c 0x0+20131c 0x0+20131c 0x0+60 0x0+80 R +0x1
f55871
 
f55871
  Section to Segment mapping:
f55871
  +Segment Sections...
f55871
--- ld/testsuite/ld-x86-64/tlspic1.s.jj	2013-04-24 09:05:15.000000000 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlspic1.s	2013-08-28 23:01:42.774606954 +0200
f55871
@@ -183,5 +183,108 @@ fn1:
f55871
 	movq	%fs:(%rcx), %rdx
f55871
 	nop;nop;nop;nop
f55871
 
f55871
+1:	movabsq	$_GLOBAL_OFFSET_TABLE_-1b, %r11
f55871
+	pushq	%rbx
f55871
+	pushq	%rbx
f55871
+	leaq	1b(%rip), %rbx
f55871
+	addq	%r11, %rbx
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large sequences  */
f55871
+
f55871
+	/* -mcmodel=large GD  */
f55871
+	leaq	sg1@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD -> IE because variable is referenced through IE too */
f55871
+	leaq	sg2@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD against local variable */
f55871
+	leaq	sl1@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD -> IE against local variable referenced through IE too */
f55871
+	leaq	sl2@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD against hidden and local variable */
f55871
+	leaq	sh1@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD -> IE against hidden and local variable referenced through
f55871
+	   IE too */
f55871
+	leaq	sh2@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD against hidden but not local variable */
f55871
+	leaq	sH1@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large GD -> IE against hidden but not local variable referenced through
f55871
+	   IE too */
f55871
+	leaq	sH2@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large LD */
f55871
+	leaq	sl1@tlsld(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop
f55871
+	leaq	sl1@dtpoff(%rax), %rdx
f55871
+	nop;nop
f55871
+	leaq	2+sl2@dtpoff(%rax), %r9
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large LD against hidden and local variables */
f55871
+	leaq	sh1@tlsld(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop
f55871
+	leaq	sh1@dtpoff(%rax), %rdx
f55871
+	nop;nop
f55871
+	leaq	sh2@dtpoff+3(%rax), %rcx
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	/* -mcmodel=large LD against hidden but not local variables */
f55871
+	leaq	sH1@tlsld(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+	nop;nop
f55871
+	leaq	sH1@dtpoff(%rax), %r12
f55871
+	nop;nop
f55871
+	leaq	sH2@dtpoff+1(%rax), %rcx
f55871
+	nop;nop;nop;nop
f55871
+
f55871
+	popq	%rbx
f55871
+	popq	%rbx
f55871
+
f55871
 	leave
f55871
 	ret
f55871
--- ld/testsuite/ld-x86-64/x86-64.exp.jj	2013-08-28 17:33:33.000000000 +0200
f55871
+++ ld/testsuite/ld-x86-64/x86-64.exp	2013-08-29 12:02:27.972052125 +0200
f55871
@@ -124,6 +124,15 @@ set x86_64tests {
f55871
     {"TLS X32 LD->LE transition" "-melf32_x86_64" ""
f55871
      "--x32" {tlsld2.s}
f55871
      {{objdump -dwr tlsld2.dd}} "tlsld2"}
f55871
+    {"TLS -mcmodel=large GD->LE transition" "-melf_x86_64" ""
f55871
+     "--64" {tlsgd7.s}
f55871
+     {{objdump -dwr tlsgd7.dd}} "tlsgd7"}
f55871
+    {"TLS -mcmodel=large LD->LE transition" "-melf_x86_64" ""
f55871
+     "--64" {tlsld3.s}
f55871
+     {{objdump -dwr tlsld3.dd}} "tlsld3"}
f55871
+    {"TLS -mcmodel=large GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" ""
f55871
+     "--64" {tlsgd8.s}
f55871
+     {{objdump -dwrj.text tlsgd8.dd}} "tlsgd8"}
f55871
 
f55871
      {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" }
f55871
      {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "" "--64" {64bit.s} {} "dummy" }
f55871
--- ld/testsuite/ld-x86-64/tlsgd8.dd.jj	2013-08-28 19:06:04.610777915 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsgd8.dd	2013-08-29 12:04:31.221378937 +0200
f55871
@@ -0,0 +1,23 @@
f55871
+#source: tlsgd8.s
f55871
+#as: --64
f55871
+#ld: -melf_x86_64 tmpdir/tlsgd8
f55871
+#objdump: -drwj.text
f55871
+#target: x86_64-*-linux* x86_64-*-nacl*
f55871
+
f55871
+.*: +file format .*
f55871
+
f55871
+Disassembly of section .text:
f55871
+
f55871
+[a-f0-9]+ <_start>:
f55871
+[ 	]*[a-f0-9]+:	49 bb ([0-9a-f]{2} ){8}	movabs \$0x[0-9a-f]+,%r11
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
f55871
+[ 	]*[a-f0-9]+:	48 8d 1d ed ff ff ff 	lea    -0x13\(%rip\),%rbx        # [0-9a-f]+ <_start>
f55871
+[ 	]*[a-f0-9]+:	4c 01 db             	add    %r11,%rbx
f55871
+[ 	]*[a-f0-9]+:	64 48 8b 04 25 00 00 00 00 	mov    %fs:0x0,%rax
f55871
+[ 	]*[a-f0-9]+:	48 03 05 ([0-9a-f]{2} ){4}	add    0x[0-9a-f]+\(%rip\),%rax        # [0-9a-f]+ <_DYNAMIC\+0x140>
f55871
+[ 	]*[a-f0-9]+:	66 0f 1f 44 00 00    	nopw   0x0\(%rax,%rax,1\)
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
f55871
+[ 	]*[a-f0-9]+:	c3                   	retq   
f55871
+#pass
f55871
--- ld/testsuite/ld-x86-64/tlsgd7.s.jj	2013-08-28 18:38:50.655538216 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsgd7.s	2013-08-28 19:14:44.906981548 +0200
f55871
@@ -0,0 +1,25 @@
f55871
+	.text
f55871
+	.globl _start
f55871
+_start:
f55871
+1:	movabsq	$_GLOBAL_OFFSET_TABLE_-1b, %r11
f55871
+	pushq	%rbx
f55871
+	pushq	%rbx
f55871
+	leaq	1b(%rip), %rbx
f55871
+	addq	%r11, %rbx
f55871
+
f55871
+	/* GD, -mcmodel=large  */
f55871
+	leaq	foo@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+
f55871
+	popq	%rbx
f55871
+	popq	%rbx
f55871
+	ret
f55871
+	.globl foo
f55871
+	.section	.tdata,"awT",@progbits
f55871
+	.align 4
f55871
+	.type	foo, @object
f55871
+	.size	foo, 4
f55871
+foo:
f55871
+	.long	100
f55871
--- ld/testsuite/ld-x86-64/tlsgd8.s.jj	2013-08-28 19:05:37.528923105 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlsgd8.s	2013-08-28 19:15:22.181782577 +0200
f55871
@@ -0,0 +1,18 @@
f55871
+	.text
f55871
+	.globl _start
f55871
+_start:
f55871
+1:	movabsq	$_GLOBAL_OFFSET_TABLE_-1b, %r11
f55871
+	pushq	%rbx
f55871
+	pushq	%rbx
f55871
+	leaq	1b(%rip), %rbx
f55871
+	addq	%r11, %rbx
f55871
+
f55871
+	/* GD, -mcmodel=large  */
f55871
+	leaq	foo@tlsgd(%rip), %rdi
f55871
+	movabsq	$__tls_get_addr@pltoff, %rax
f55871
+	addq	%rbx, %rax
f55871
+	call	*%rax
f55871
+
f55871
+	popq	%rbx
f55871
+	popq	%rbx
f55871
+	ret
f55871
--- ld/testsuite/ld-x86-64/tlspic-nacl.rd.jj	2013-08-28 17:33:33.000000000 +0200
f55871
+++ ld/testsuite/ld-x86-64/tlspic-nacl.rd	2013-08-29 12:09:37.464675310 +0200
f55871
@@ -11,7 +11,7 @@ Section Headers:
f55871
  +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
f55871
  +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
f55871
  +\[[ 0-9]+\] .plt +.*
f55871
- +\[[ 0-9]+\] .text +PROGBITS +0+1000 [0-9a-f]+ 0+1ac 00 +AX +0 +0 4096
f55871
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 [0-9a-f]+ 0+31c 00 +AX +0 +0 4096
f55871
  +\[[ 0-9]+\] .hash +.*
f55871
  +\[[ 0-9]+\] .dynsym +.*
f55871
  +\[[ 0-9]+\] .dynstr +.*