This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Disabling TLS optimization for PowerPC


Someone sent me a testcase recently (code generated by xlc not using
TLS_GD and TLS_LD marker relocs) showing ld incorrectly optimizing TLS
sequences.  This was due to ld looking for a __tls_get_addr call after
the __tls_get_addr arg setup insn, but not vice versa.  When fixing
this I realized that you can't reliably disable the TLS optimization
for individual sections.  Since the actual code optimization is done
in relocate_section using flags attached to a symbol, a "bad" section
might still be optimized if a "good" section references the same TLS
symbols.

bfd/
	* elf32-ppc.c (ppc_elf_tls_optimize): Catch more cases where
	old-style __tls_get_addr calls without marker relocs don't match
	their arg setup insn one for one.  If such mismatches are found
	report the reloc and don't do any tls optimization.
	* elf64-ppc.c (ppc64_elf_tls_optimize): Likewise.
ld/testsuite/
	* ld-powerpc/tlsmark.s: Delete non-optimizable section.
	* ld-powerpc/tlsmark32.s: Likewise.
	* ld-powerpc/tlsmark.d: Adjust to suit.
	* ld-powerpc/tlsmark32.d: Likewise.
	* ld-powerpc/tlsopt1.d, * ld-powerpc/tlsopt1.s: New.
	* ld-powerpc/tlsopt2.d, * ld-powerpc/tlsopt2.s: New.
	* ld-powerpc/tlsopt3.d, * ld-powerpc/tlsopt3.s: New.
	* ld-powerpc/tlsopt4.d, * ld-powerpc/tlsopt4.s: New.
	* ld-powerpc/tlsopt1_32.d, * ld-powerpc/tlsopt1_32.s: New.
	* ld-powerpc/tlsopt2_32.d, * ld-powerpc/tlsopt2_32.s: New.
	* ld-powerpc/tlsopt3_32.d, * ld-powerpc/tlsopt3_32.s: New.
	* ld-powerpc/tlsopt4_32.d, * ld-powerpc/tlsopt4_32.s: New.
	* ld-powerpc/powerpc.exp: Run new tests.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.291
diff -u -p -r1.291 elf32-ppc.c
--- bfd/elf32-ppc.c	29 Jan 2011 00:12:52 -0000	1.291
+++ bfd/elf32-ppc.c	23 Mar 2011 14:16:12 -0000
@@ -4631,10 +4628,15 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUT
     return TRUE;
 
   htab = ppc_elf_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   /* Make two passes through the relocs.  First time check that tls
      relocs involved in setting up a tls_get_addr call are indeed
-     followed by such a call.  If they are not, exclude them from
-     the optimizations done on the second pass.  */
+     followed by such a call.  If they are not, don't do any tls
+     optimization.  On the second pass twiddle tls_mask flags to
+     notify relocate_section that optimization can be done, and
+     adjust got and plt refcounts.  */
   for (pass = 0; pass < 2; ++pass)
     for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
       {
@@ -4646,6 +4648,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUT
 	  if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
 	    {
 	      Elf_Internal_Rela *relstart, *rel, *relend;
+	      int expecting_tls_get_addr = 0;
 
 	      /* Read the relocations.  */
 	      relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
@@ -4662,7 +4665,6 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUT
 		  char *tls_mask;
 		  char tls_set, tls_clear;
 		  bfd_boolean is_local;
-		  int expecting_tls_get_addr;
 		  bfd_signed_vma *got_count;
 
 		  r_symndx = ELF32_R_SYM (rel->r_info);
@@ -4677,13 +4679,34 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUT
 			h = (struct elf_link_hash_entry *) h->root.u.i.link;
 		    }
 
-		  expecting_tls_get_addr = 0;
 		  is_local = FALSE;
 		  if (h == NULL
 		      || !h->def_dynamic)
 		    is_local = TRUE;
 
 		  r_type = ELF32_R_TYPE (rel->r_info);
+		  /* If this section has old-style __tls_get_addr calls
+		     without marker relocs, then check that each
+		     __tls_get_addr call reloc is preceded by a reloc
+		     that conceivably belongs to the __tls_get_addr arg
+		     setup insn.  If we don't find matching arg setup
+		     relocs, don't do any tls optimization.  */
+		  if (pass == 0
+		      && sec->has_tls_get_addr_call
+		      && h != NULL
+		      && h == htab->tls_get_addr
+		      && !expecting_tls_get_addr
+		      && is_branch_reloc (r_type))
+		    {
+		      info->callbacks->minfo ("%C __tls_get_addr lost arg, "
+					      "TLS optimization disabled\n",
+					      ibfd, sec, rel->r_offset);
+		      if (elf_section_data (sec)->relocs != relstart)
+			free (relstart);
+		      return TRUE;
+		    }
+
+		  expecting_tls_get_addr = 0;
 		  switch (r_type)
 		    {
 		    case R_PPC_GOT_TLSLD16:
@@ -4760,9 +4783,13 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUT
 		      /* Uh oh, we didn't find the expected call.  We
 			 could just mark this symbol to exclude it
 			 from tls optimization but it's safer to skip
-			 the entire section.  */
-		      sec->has_tls_reloc = 0;
-		      break;
+			 the entire optimization.  */
+		      info->callbacks->minfo (_("%C arg lost __tls_get_addr, "
+						"TLS optimization disabled\n"),
+					      ibfd, sec, rel->r_offset);
+		      if (elf_section_data (sec)->relocs != relstart)
+			free (relstart);
+		      return TRUE;
 		    }
 
 		  if (expecting_tls_get_addr)
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.345
diff -u -p -r1.345 elf64-ppc.c
--- bfd/elf64-ppc.c	10 Mar 2011 09:26:18 -0000	1.345
+++ bfd/elf64-ppc.c	23 Mar 2011 14:16:17 -0000
@@ -7473,6 +7474,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
   bfd *ibfd;
   asection *sec;
   struct ppc_link_hash_table *htab;
+  unsigned char *toc_ref;
   int pass;
 
   if (info->relocatable || !info->executable)
@@ -7482,23 +7484,25 @@ ppc64_elf_tls_optimize (struct bfd_link_
   if (htab == NULL)
     return FALSE;
 
-  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
-    {
-      Elf_Internal_Sym *locsyms = NULL;
-      asection *toc = bfd_get_section_by_name (ibfd, ".toc");
-      unsigned char *toc_ref = NULL;
-
-      /* Look at all the sections for this file.  Make two passes over
-	 the relocs.  On the first pass, mark toc entries involved
-	 with tls relocs, and check that tls relocs involved in
-	 setting up a tls_get_addr call are indeed followed by such a
-	 call.  If they are not, exclude them from the optimizations
-	 done on the second pass.  */
-      for (pass = 0; pass < 2; ++pass)
+  /* Make two passes over the relocs.  On the first pass, mark toc
+     entries involved with tls relocs, and check that tls relocs
+     involved in setting up a tls_get_addr call are indeed followed by
+     such a call.  If they are not, we can't do any tls optimization.
+     On the second pass twiddle tls_mask flags to notify
+     relocate_section that optimization can be done, and adjust got
+     and plt refcounts.  */
+  toc_ref = NULL;
+  for (pass = 0; pass < 2; ++pass)
+    for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+      {
+	Elf_Internal_Sym *locsyms = NULL;
+	asection *toc = bfd_get_section_by_name (ibfd, ".toc");
+
 	for (sec = ibfd->sections; sec != NULL; sec = sec->next)
 	  if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
 	    {
 	      Elf_Internal_Rela *relstart, *rel, *relend;
+	      bfd_boolean found_tls_get_addr_arg = 0;
 
 	      /* Read the relocations.  */
 	      relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
@@ -7520,6 +7524,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		  bfd_boolean ok_tprel, is_local;
 		  long toc_ref_index = 0;
 		  int expecting_tls_get_addr = 0;
+		  bfd_boolean ret = FALSE;
 
 		  r_symndx = ELF64_R_SYM (rel->r_info);
 		  if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
@@ -7534,7 +7539,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
 			  && (elf_symtab_hdr (ibfd).contents
 			      != (unsigned char *) locsyms))
 			free (locsyms);
-		      return FALSE;
+		      return ret;
 		    }
 
 		  if (h != NULL)
@@ -7545,7 +7550,10 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		      else if (h->root.type == bfd_link_hash_undefweak)
 			value = 0;
 		      else
-			continue;
+			{
+			  found_tls_get_addr_arg = 0;
+			  continue;
+			}
 		    }
 		  else
 		    /* Symbols referenced by TLS relocs must be of type
@@ -7572,11 +7580,34 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		    }
 
 		  r_type = ELF64_R_TYPE (rel->r_info);
+		  /* If this section has old-style __tls_get_addr calls
+		     without marker relocs, then check that each
+		     __tls_get_addr call reloc is preceded by a reloc
+		     that conceivably belongs to the __tls_get_addr arg
+		     setup insn.  If we don't find matching arg setup
+		     relocs, don't do any tls optimization.  */
+		  if (pass == 0
+		      && sec->has_tls_get_addr_call
+		      && h != NULL
+		      && (h == &htab->tls_get_addr->elf
+			  || h == &htab->tls_get_addr_fd->elf)
+		      && !found_tls_get_addr_arg
+		      && is_branch_reloc (r_type))
+		    {
+		      info->callbacks->minfo (_("%C __tls_get_addr lost arg, "
+						"TLS optimization disabled\n"),
+					      ibfd, sec, rel->r_offset);
+		      ret = TRUE;
+		      goto err_free_rel;
+		    }
+
+		  found_tls_get_addr_arg = 0;
 		  switch (r_type)
 		    {
 		    case R_PPC64_GOT_TLSLD16:
 		    case R_PPC64_GOT_TLSLD16_LO:
 		      expecting_tls_get_addr = 1;
+		      found_tls_get_addr_arg = 1;
 		      /* Fall thru */
 
 		    case R_PPC64_GOT_TLSLD16_HI:
@@ -7596,6 +7627,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		    case R_PPC64_GOT_TLSGD16:
 		    case R_PPC64_GOT_TLSGD16_LO:
 		      expecting_tls_get_addr = 1;
+		      found_tls_get_addr_arg = 1;
 		      /* Fall thru */
 
 		    case R_PPC64_GOT_TLSGD16_HI:
@@ -7624,11 +7656,14 @@ ppc64_elf_tls_optimize (struct bfd_link_
 			}
 		      continue;
 
-		    case R_PPC64_TOC16:
-		    case R_PPC64_TOC16_LO:
-		    case R_PPC64_TLS:
 		    case R_PPC64_TLSGD:
 		    case R_PPC64_TLSLD:
+		      found_tls_get_addr_arg = 1;
+		      /* Fall thru */
+
+		    case R_PPC64_TLS:
+		    case R_PPC64_TOC16:
+		    case R_PPC64_TOC16_LO:
 		      if (sym_sec == NULL || sym_sec != toc)
 			continue;
 
@@ -7637,18 +7672,17 @@ ppc64_elf_tls_optimize (struct bfd_link_
 			 case of R_PPC64_TLS, and after checking for
 			 tls_get_addr for the TOC16 relocs.  */
 		      if (toc_ref == NULL)
-			{
-			  toc_ref = bfd_zmalloc (toc->size / 8);
-			  if (toc_ref == NULL)
-			    goto err_free_rel;
-			}
+			toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
+		      if (toc_ref == NULL)
+			goto err_free_rel;
+
 		      if (h != NULL)
 			value = h->root.u.def.value;
 		      else
 			value = sym->st_value;
 		      value += rel->r_addend;
 		      BFD_ASSERT (value < toc->size && value % 8 == 0);
-		      toc_ref_index = value / 8;
+		      toc_ref_index = (value + toc->output_offset) / 8;
 		      if (r_type == R_PPC64_TLS
 			  || r_type == R_PPC64_TLSGD
 			  || r_type == R_PPC64_TLSLD)
@@ -7669,7 +7703,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		      if (pass == 0
 			  || sec != toc
 			  || toc_ref == NULL
-			  || !toc_ref[rel->r_offset / 8])
+			  || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
 			continue;
 		      if (ok_tprel)
 			{
@@ -7684,7 +7718,7 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		      if (pass == 0
 			  || sec != toc
 			  || toc_ref == NULL
-			  || !toc_ref[rel->r_offset / 8])
+			  || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
 			continue;
 		      if (rel + 1 < relend
 			  && (rel[1].r_info
@@ -7736,8 +7770,13 @@ ppc64_elf_tls_optimize (struct bfd_link_
 						     rel, ibfd);
 			      if (retval == 0)
 				goto err_free_rel;
-			      if (retval > 1 && toc_tls != NULL)
-				toc_ref[toc_ref_index] = 1;
+			      if (toc_tls != NULL)
+				{
+				  if ((*toc_tls & (TLS_GD | TLS_LD)) != 0)
+				    found_tls_get_addr_arg = 1;
+				  if (retval > 1)
+				    toc_ref[toc_ref_index] = 1;
+				}
 			    }
 			  continue;
 			}
@@ -7748,9 +7787,12 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		      /* Uh oh, we didn't find the expected call.  We
 			 could just mark this symbol to exclude it
 			 from tls optimization but it's safer to skip
-			 the entire section.  */
-		      sec->has_tls_reloc = 0;
-		      break;
+			 the entire optimization.  */
+		      info->callbacks->minfo (_("%C arg lost __tls_get_addr, "
+						"TLS optimization disabled\n"),
+					      ibfd, sec, rel->r_offset);
+		      ret = TRUE;
+		      goto err_free_rel;
 		    }
 
 		  if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
@@ -7836,18 +7878,18 @@ ppc64_elf_tls_optimize (struct bfd_link_
 		free (relstart);
 	    }
 
-      if (toc_ref != NULL)
-	free (toc_ref);
+	if (locsyms != NULL
+	    && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
+	  {
+	    if (!info->keep_memory)
+	      free (locsyms);
+	    else
+	      elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
+	  }
+      }
 
-      if (locsyms != NULL
-	  && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
-	{
-	  if (!info->keep_memory)
-	    free (locsyms);
-	  else
-	    elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
-	}
-    }
+  if (toc_ref != NULL)
+    free (toc_ref);
   return TRUE;
 }
 
Index: ld/testsuite/ld-powerpc/powerpc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/powerpc.exp,v
retrieving revision 1.32
diff -u -p -r1.32 powerpc.exp
--- ld/testsuite/ld-powerpc/powerpc.exp	5 Aug 2010 14:38:10 -0000	1.32
+++ ld/testsuite/ld-powerpc/powerpc.exp	23 Mar 2011 14:20:40 -0000
@@ -123,6 +123,18 @@ set ppcelftests {
     {"TLS32 markers" "-melf32ppc" "-a32"  {tlsmark32.s tlslib32.s}
      {{objdump -dr tlsmark32.d}}
       "tlsmark32"}
+    {"TLS32 opt 1" "-melf32ppc" "-a32"  {tlsopt1_32.s tlslib32.s}
+     {{objdump -dr tlsopt1_32.d}}
+      "tlsopt1_32"}
+    {"TLS32 opt 2" "-melf32ppc" "-a32"  {tlsopt2_32.s tlslib32.s}
+     {{objdump -dr tlsopt2_32.d}}
+      "tlsopt2_32"}
+    {"TLS32 opt 3" "-melf32ppc" "-a32"  {tlsopt3_32.s tlslib32.s}
+     {{objdump -dr tlsopt3_32.d}}
+      "tlsopt3_32"}
+    {"TLS32 opt 4" "-melf32ppc" "-a32"  {tlsopt4_32.s tlslib32.s}
+     {{objdump -dr tlsopt4_32.d}}
+      "tlsopt4_32"}
     {"Shared library with global symbol" "-shared -melf32ppc" "-a32" {sdalib.s}
      {} "sdalib.so"}
     {"Dynamic application with SDA" "-melf32ppc tmpdir/sdalib.so" "-a32" {sdadyn.s}
@@ -176,6 +188,18 @@ set ppc64elftests {
     {"TLS markers" "-melf64ppc" "-a64"  {tlsmark.s tlslib.s}
      {{objdump -dr tlsmark.d}}
       "tlsmark"}
+    {"TLS opt 1" "-melf64ppc" "-a64"  {tlsopt1.s tlslib.s}
+     {{objdump -dr tlsopt1.d}}
+      "tlsopt1"}
+    {"TLS opt 2" "-melf64ppc" "-a64"  {tlsopt2.s tlslib.s}
+     {{objdump -dr tlsopt2.d}}
+      "tlsopt2"}
+    {"TLS opt 3" "-melf64ppc" "-a64"  {tlsopt3.s tlslib.s}
+     {{objdump -dr tlsopt3.d}}
+      "tlsopt3"}
+    {"TLS opt 4" "-melf64ppc" "-a64"  {tlsopt4.s tlslib.s}
+     {{objdump -dr tlsopt4.d}}
+      "tlsopt4"}
     {"sym@tocbase" "-shared -melf64ppc" "-a64" {symtocbase-1.s symtocbase-2.s}
 	{{objdump -dj.data symtocbase.d}} "symtocbase.so"}
     {"TOC opt" "-melf64ppc" "-a64"  {tocopt.s}
Index: ld/testsuite/ld-powerpc/tlsmark.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsmark.d,v
retrieving revision 1.1
diff -u -p -r1.1 tlsmark.d
--- ld/testsuite/ld-powerpc/tlsmark.d	4 Mar 2009 05:50:50 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsmark.d	23 Mar 2011 14:20:40 -0000
@@ -32,11 +32,6 @@ Disassembly of section \.text:
     10000134:	60 00 00 00 	nop
     10000138:	38 63 10 00 	addi    r3,r3,4096
     1000013c:	e8 a3 80 04 	ld      r5,-32764\(r3\)
-    10000140:	38 62 80 28 	addi    r3,r2,-32728
-    10000144:	3f a0 10 01 	lis     r29,4097
-    10000148:	3b bd 01 68 	addi    r29,r29,360
-    1000014c:	48 00 00 09 	bl      10000154 <\.__tls_get_addr>
-    10000150:	60 00 00 00 	nop
 
-0+10000154 <\.__tls_get_addr>:
-    10000154:	4e 80 00 20 	blr
+0+10000140 <\.__tls_get_addr>:
+    10000140:	4e 80 00 20 	blr
Index: ld/testsuite/ld-powerpc/tlsmark.s
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsmark.s,v
retrieving revision 1.1
diff -u -p -r1.1 tlsmark.s
--- ld/testsuite/ld-powerpc/tlsmark.s	4 Mar 2009 05:50:50 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsmark.s	23 Mar 2011 14:20:40 -0000
@@ -44,12 +44,3 @@ _start:
 	bl .__tls_get_addr(.LC1@tlsld)
 	nop
 	ld 5,y@dtprel(3)
-
-
-	.section ".text.no","ax",@progbits
-	.p2align 2
-	addi 3,2,gd@got@tlsgd
-	lis 29,__tls_get_addr@ha
-	addi 29,29,__tls_get_addr@l
-	bl __tls_get_addr
-	nop
Index: ld/testsuite/ld-powerpc/tlsmark32.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsmark32.d,v
retrieving revision 1.1
diff -u -p -r1.1 tlsmark32.d
--- ld/testsuite/ld-powerpc/tlsmark32.d	4 Mar 2009 05:50:50 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsmark32.d	23 Mar 2011 14:20:40 -0000
@@ -19,11 +19,7 @@ Disassembly of section \.text:
  18000ac:	4b ff ff ec 	b       1800098 <_start\+0x4>
  18000b0:	38 63 10 00 	addi    r3,r3,4096
  18000b4:	80 83 80 00 	lwz     r4,-32768\(r3\)
- 18000b8:	38 7f ff f4 	addi    r3,r31,-12
- 18000bc:	3f a0 01 80 	lis     r29,384
- 18000c0:	3b bd 00 c8 	addi    r29,r29,200
- 18000c4:	48 00 00 05 	bl      18000c8 <__tls_get_addr>
 
-0+18000c8 <__tls_get_addr>:
- 18000c8:	4e 80 00 20 	blr
+0+18000b8 <__tls_get_addr>:
+ 18000b8:	4e 80 00 20 	blr
 #pass
\ No newline at end of file
Index: ld/testsuite/ld-powerpc/tlsmark32.s
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsmark32.s,v
retrieving revision 1.1
diff -u -p -r1.1 tlsmark32.s
--- ld/testsuite/ld-powerpc/tlsmark32.s	4 Mar 2009 05:50:50 -0000	1.1
+++ ld/testsuite/ld-powerpc/tlsmark32.s	23 Mar 2011 14:20:40 -0000
@@ -17,11 +17,3 @@ _start:
 .L3:
 	bl __tls_get_addr(x@tlsld)
 	lwz 4,x@dtprel(3)
-
-
-	.section ".text.no","ax",@progbits
-	.p2align 2
-	addi 3,31,gd@got@tlsgd
-	lis 29,__tls_get_addr@ha
-	addi 29,29,__tls_get_addr@l
-	bl __tls_get_addr
Index: ld/testsuite/ld-powerpc/tlsopt1.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt1.d
diff -N ld/testsuite/ld-powerpc/tlsopt1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt1.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,25 @@
+#source: tlsopt1.s
+#source: tlslib.s
+#as: -a64
+#ld: -melf64ppc
+#objdump: -dr
+#target: powerpc64*-*-*
+
+.*: +file format elf64-powerpc
+
+Disassembly of section \.text:
+
+0+100000e8 <\.__tls_get_addr>:
+    100000e8:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt1:
+
+0+100000ec <\.no_opt1>:
+    100000ec:	38 62 80 08 	addi    r3,r2,-32760
+    100000f0:	2c 24 00 00 	cmpdi   r4,0
+    100000f4:	41 82 00 10 	beq-    .*
+    100000f8:	4b ff ff f1 	bl      100000e8 <\.__tls_get_addr>
+    100000fc:	60 00 00 00 	nop
+    10000100:	48 00 00 0c 	b       .*
+    10000104:	4b ff ff e5 	bl      100000e8 <\.__tls_get_addr>
+    10000108:	60 00 00 00 	nop
Index: ld/testsuite/ld-powerpc/tlsopt1.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt1.s
diff -N ld/testsuite/ld-powerpc/tlsopt1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt1.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,14 @@
+ .section ".no_opt1", "ax", %progbits
+# this section should not be optimised since we have old-style
+# __tls_get_addr without marker relocs, and the arg setup insn
+# is shared with two __tls_get_addr calls.
+ addi 3,2,gd@got@tlsgd
+ cmpdi 4,0
+ beq 0f
+ bl __tls_get_addr
+ nop
+ b 1f
+0:
+ bl __tls_get_addr
+ nop
+1:
Index: ld/testsuite/ld-powerpc/tlsopt1_32.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt1_32.d
diff -N ld/testsuite/ld-powerpc/tlsopt1_32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt1_32.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,24 @@
+#source: tlsopt1_32.s
+#source: tlslib32.s
+#as: -a32
+#ld: -melf32ppc
+#objdump: -dr
+#target: powerpc*-*-*
+
+.*: +file format elf32-powerpc
+
+Disassembly of section \.text:
+
+0+1800094 <__tls_get_addr>:
+ 1800094:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt1:
+
+0+1800098 <\.no_opt1>:
+ 1800098:	38 6d ff f4 	addi    r3,r13,-12
+ 180009c:	2c 04 00 00 	cmpwi   r4,0
+ 18000a0:	41 82 00 0c 	beq-    .*
+ 18000a4:	4b ff ff f1 	bl      1800094 <__tls_get_addr>
+ 18000a8:	48 00 00 08 	b       .*
+ 18000ac:	4b ff ff e9 	bl      1800094 <__tls_get_addr>
+#pass
Index: ld/testsuite/ld-powerpc/tlsopt1_32.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt1_32.s
diff -N ld/testsuite/ld-powerpc/tlsopt1_32.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt1_32.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,12 @@
+ .section ".no_opt1", "ax", %progbits
+# this section should not be optimised since we have old-style
+# __tls_get_addr without marker relocs, and the arg setup insn
+# is shared with two __tls_get_addr calls.
+ addi 3,13,gd@got@tlsgd
+ cmpwi 4,0
+ beq 0f
+ bl __tls_get_addr
+ b 1f
+0:
+ bl __tls_get_addr
+1:
Index: ld/testsuite/ld-powerpc/tlsopt2.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt2.d
diff -N ld/testsuite/ld-powerpc/tlsopt2.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt2.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,23 @@
+#source: tlsopt2.s
+#source: tlslib.s
+#as: -a64
+#ld: -melf64ppc
+#objdump: -dr
+#target: powerpc64*-*-*
+
+.*: +file format elf64-powerpc
+
+Disassembly of section \.text:
+
+0+100000e8 <\.__tls_get_addr>:
+    100000e8:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt2:
+
+0+100000ec <\.no_opt2>:
+    100000ec:	38 62 80 08 	addi    r3,r2,-32760
+    100000f0:	2c 24 00 00 	cmpdi   r4,0
+    100000f4:	41 82 00 08 	beq-    .*
+    100000f8:	38 62 80 08 	addi    r3,r2,-32760
+    100000fc:	4b ff ff ed 	bl      100000e8 <\.__tls_get_addr>
+    10000100:	60 00 00 00 	nop
Index: ld/testsuite/ld-powerpc/tlsopt2.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt2.s
diff -N ld/testsuite/ld-powerpc/tlsopt2.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt2.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,11 @@
+ .section ".no_opt2", "ax", %progbits
+# this section should not be optimised since we have old-style
+# __tls_get_addr without marker relocs, and two arg setup insns
+# feed into one __tls_get_addr call.
+ addi 3,2,gd@got@tlsgd
+ cmpdi 4,0
+ beq 0f
+ addi 3,2,gd@got@tlsgd
+0:
+ bl __tls_get_addr
+ nop
Index: ld/testsuite/ld-powerpc/tlsopt2_32.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt2_32.d
diff -N ld/testsuite/ld-powerpc/tlsopt2_32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt2_32.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,23 @@
+#source: tlsopt2_32.s
+#source: tlslib32.s
+#as: -a32
+#ld: -melf32ppc
+#objdump: -dr
+#target: powerpc*-*-*
+
+.*: +file format elf32-powerpc
+
+Disassembly of section \.text:
+
+0+1800094 <__tls_get_addr>:
+ 1800094:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt2:
+
+0+1800098 <\.no_opt2>:
+ 1800098:	38 6d ff f4 	addi    r3,r13,-12
+ 180009c:	2c 04 00 00 	cmpwi   r4,0
+ 18000a0:	41 82 00 08 	beq-    .*
+ 18000a4:	38 6d ff f4 	addi    r3,r13,-12
+ 18000a8:	4b ff ff ed 	bl      1800094 <__tls_get_addr>
+#pass
Index: ld/testsuite/ld-powerpc/tlsopt2_32.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt2_32.s
diff -N ld/testsuite/ld-powerpc/tlsopt2_32.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt2_32.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,10 @@
+ .section ".no_opt2", "ax", %progbits
+# this section should not be optimised since we have old-style
+# __tls_get_addr without marker relocs, and two arg setup insns
+# feed into one __tls_get_addr call.
+ addi 3,13,gd@got@tlsgd
+ cmpwi 4,0
+ beq 0f
+ addi 3,13,gd@got@tlsgd
+0:
+ bl __tls_get_addr
Index: ld/testsuite/ld-powerpc/tlsopt3.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt3.d
diff -N ld/testsuite/ld-powerpc/tlsopt3.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt3.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,26 @@
+#source: tlsopt3.s
+#source: tlslib.s
+#as: -a64
+#ld: -melf64ppc
+#objdump: -dr
+#target: powerpc64*-*-*
+
+.*: +file format elf64-powerpc
+
+Disassembly of section \.text:
+
+00000000100000e8 <\.__tls_get_addr>:
+    100000e8:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt3:
+
+00000000100000ec <\.no_opt3>:
+    100000ec:	38 62 80 08 	addi    r3,r2,-32760
+    100000f0:	48 00 00 0c 	b       .*
+    100000f4:	38 62 80 18 	addi    r3,r2,-32744
+    100000f8:	48 00 00 10 	b       .*
+    100000fc:	4b ff ff ed 	bl      100000e8 <\.__tls_get_addr>
+    10000100:	60 00 00 00 	nop
+    10000104:	48 00 00 0c 	b       .*
+    10000108:	4b ff ff e1 	bl      100000e8 <\.__tls_get_addr>
+    1000010c:	60 00 00 00 	nop
Index: ld/testsuite/ld-powerpc/tlsopt3.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt3.s
diff -N ld/testsuite/ld-powerpc/tlsopt3.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt3.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,19 @@
+ .section ".tbss","awT",@nobits
+ .global gd0
+ .align 3
+gd0: .space 8
+
+ .section ".no_opt3", "ax", %progbits
+# this section should also not be optimised
+ addi 3,2,gd@got@tlsgd
+ b 0f
+ addi 3,2,gd0@got@tlsgd
+ b 1f
+0:
+ bl __tls_get_addr
+ nop
+ b 2f
+1:
+ bl __tls_get_addr
+ nop
+2:
Index: ld/testsuite/ld-powerpc/tlsopt3_32.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt3_32.d
diff -N ld/testsuite/ld-powerpc/tlsopt3_32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt3_32.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,25 @@
+#source: tlsopt3_32.s
+#source: tlslib32.s
+#as: -a32
+#ld: -melf32ppc
+#objdump: -dr
+#target: powerpc*-*-*
+
+.*: +file format elf32-powerpc
+
+Disassembly of section \.text:
+
+0+1800094 <__tls_get_addr>:
+ 1800094:	4e 80 00 20 	blr
+
+Disassembly of section \.no_opt3:
+
+0+1800098 <\.no_opt3>:
+ 1800098:	38 6d ff ec 	addi    r3,r13,-20
+ 180009c:	48 00 00 0c 	b       .*
+ 18000a0:	38 6d ff f4 	addi    r3,r13,-12
+ 18000a4:	48 00 00 0c 	b       .*
+ 18000a8:	4b ff ff ed 	bl      1800094 <__tls_get_addr>
+ 18000ac:	48 00 00 08 	b       .*
+ 18000b0:	4b ff ff e5 	bl      1800094 <__tls_get_addr>
+#pass
Index: ld/testsuite/ld-powerpc/tlsopt3_32.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt3_32.s
diff -N ld/testsuite/ld-powerpc/tlsopt3_32.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt3_32.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,17 @@
+ .section ".tbss","awT",@nobits
+ .global gd0
+ .align 3
+gd0: .space 8
+
+ .section ".no_opt3", "ax", %progbits
+# this section should also not be optimised
+ addi 3,13,gd@got@tlsgd
+ b 0f
+ addi 3,13,gd0@got@tlsgd
+ b 1f
+0:
+ bl __tls_get_addr
+ b 2f
+1:
+ bl __tls_get_addr
+2:
Index: ld/testsuite/ld-powerpc/tlsopt4.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt4.d
diff -N ld/testsuite/ld-powerpc/tlsopt4.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt4.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,48 @@
+#source: tlsopt4.s
+#source: tlslib.s
+#as: -a64
+#ld: -melf64ppc
+#objdump: -dr
+#target: powerpc64*-*-*
+
+.*: +file format elf64-powerpc
+
+Disassembly of section \.text:
+
+0+100000e8 <\.__tls_get_addr>:
+    100000e8:	4e 80 00 20 	blr
+
+Disassembly of section \.opt1:
+
+0+100000ec <\.opt1>:
+    100000ec:	3c 6d 00 00 	addis   r3,r13,0
+    100000f0:	2c 24 00 00 	cmpdi   r4,0
+    100000f4:	41 82 00 10 	beq-    .*
+    100000f8:	60 00 00 00 	nop
+    100000fc:	38 63 90 10 	addi    r3,r3,-28656
+    10000100:	48 00 00 0c 	b       .*
+    10000104:	60 00 00 00 	nop
+    10000108:	38 63 90 10 	addi    r3,r3,-28656
+
+Disassembly of section \.opt2:
+
+0+1000010c <\.opt2>:
+    1000010c:	3c 6d 00 00 	addis   r3,r13,0
+    10000110:	2c 24 00 00 	cmpdi   r4,0
+    10000114:	41 82 00 08 	beq-    .*
+    10000118:	3c 6d 00 00 	addis   r3,r13,0
+    1000011c:	60 00 00 00 	nop
+    10000120:	38 63 90 10 	addi    r3,r3,-28656
+
+Disassembly of section \.opt3:
+
+0+10000124 <\.opt3>:
+    10000124:	3c 6d 00 00 	addis   r3,r13,0
+    10000128:	48 00 00 0c 	b       .*
+    1000012c:	3c 6d 00 00 	addis   r3,r13,0
+    10000130:	48 00 00 10 	b       .*
+    10000134:	60 00 00 00 	nop
+    10000138:	38 63 90 10 	addi    r3,r3,-28656
+    1000013c:	48 00 00 0c 	b       .*
+    10000140:	60 00 00 00 	nop
+    10000144:	38 63 90 08 	addi    r3,r3,-28664
Index: ld/testsuite/ld-powerpc/tlsopt4.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt4.s
diff -N ld/testsuite/ld-powerpc/tlsopt4.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt4.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,39 @@
+ .section ".tbss","awT",@nobits
+ .global gd0
+ .align 3
+gd0: .space 8
+
+ .section ".opt1", "ax", %progbits
+ addi 3,2,gd@got@tlsgd
+ cmpdi 4,0
+ beq 0f
+ bl __tls_get_addr(gd@tlsgd)
+ nop
+ b 1f
+0:
+ bl __tls_get_addr(gd@tlsgd)
+ nop
+1:
+
+ .section ".opt2", "ax", %progbits
+ addi 3,2,gd@got@tlsgd
+ cmpdi 4,0
+ beq 0f
+ addi 3,2,gd@got@tlsgd
+0:
+ bl __tls_get_addr(gd@tlsgd)
+ nop
+
+ .section ".opt3", "ax", %progbits
+ addi 3,2,gd@got@tlsgd
+ b 0f
+ addi 3,2,gd0@got@tlsgd
+ b 1f
+0:
+ bl __tls_get_addr(gd@tlsgd)
+ nop
+ b 2f
+1:
+ bl __tls_get_addr(gd0@tlsgd)
+ nop
+2:
Index: ld/testsuite/ld-powerpc/tlsopt4_32.d
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt4_32.d
diff -N ld/testsuite/ld-powerpc/tlsopt4_32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt4_32.d	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,44 @@
+#source: tlsopt4_32.s
+#source: tlslib32.s
+#as: -a32
+#ld: -melf32ppc
+#objdump: -dr
+#target: powerpc*-*-*
+
+.*: +file format elf32-powerpc
+
+Disassembly of section \.text:
+
+0+1800094 <__tls_get_addr>:
+ 1800094:	4e 80 00 20 	blr
+
+Disassembly of section \.opt1:
+
+0+1800098 <\.opt1>:
+ 1800098:	3c 62 00 00 	addis   r3,r2,0
+ 180009c:	2c 04 00 00 	cmpwi   r4,0
+ 18000a0:	41 82 00 0c 	beq-    .*
+ 18000a4:	38 63 90 10 	addi    r3,r3,-28656
+ 18000a8:	48 00 00 08 	b       .*
+ 18000ac:	38 63 90 10 	addi    r3,r3,-28656
+
+Disassembly of section \.opt2:
+
+0+18000b0 <\.opt2>:
+ 18000b0:	3c 62 00 00 	addis   r3,r2,0
+ 18000b4:	2c 04 00 00 	cmpwi   r4,0
+ 18000b8:	41 82 00 08 	beq-    .*
+ 18000bc:	3c 62 00 00 	addis   r3,r2,0
+ 18000c0:	38 63 90 10 	addi    r3,r3,-28656
+
+Disassembly of section \.opt3:
+
+0+18000c4 <\.opt3>:
+ 18000c4:	3c 62 00 00 	addis   r3,r2,0
+ 18000c8:	48 00 00 0c 	b       .*
+ 18000cc:	3c 62 00 00 	addis   r3,r2,0
+ 18000d0:	48 00 00 0c 	b       .*
+ 18000d4:	38 63 90 10 	addi    r3,r3,-28656
+ 18000d8:	48 00 00 08 	b       .*
+ 18000dc:	38 63 90 08 	addi    r3,r3,-28664
+#pass
Index: ld/testsuite/ld-powerpc/tlsopt4_32.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/tlsopt4_32.s
diff -N ld/testsuite/ld-powerpc/tlsopt4_32.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-powerpc/tlsopt4_32.s	23 Mar 2011 14:20:40 -0000
@@ -0,0 +1,34 @@
+ .section ".tbss","awT",@nobits
+ .global gd0
+ .align 3
+gd0: .space 8
+
+ .section ".opt1", "ax", %progbits
+ addi 3,13,gd@got@tlsgd
+ cmpwi 4,0
+ beq 0f
+ bl __tls_get_addr(gd@tlsgd)
+ b 1f
+0:
+ bl __tls_get_addr(gd@tlsgd)
+1:
+
+ .section ".opt2", "ax", %progbits
+ addi 3,13,gd@got@tlsgd
+ cmpwi 4,0
+ beq 0f
+ addi 3,13,gd@got@tlsgd
+0:
+ bl __tls_get_addr(gd@tlsgd)
+
+ .section ".opt3", "ax", %progbits
+ addi 3,13,gd@got@tlsgd
+ b 0f
+ addi 3,13,gd0@got@tlsgd
+ b 1f
+0:
+ bl __tls_get_addr(gd@tlsgd)
+ b 2f
+1:
+ bl __tls_get_addr(gd0@tlsgd)
+2:

-- 
Alan Modra
Australia Development Lab, IBM


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