From 663a1470e1a7af58a3d0691f480bc5621bd0c54f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 23 Mar 2011 15:25:06 +0000 Subject: [PATCH] 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. --- bfd/ChangeLog | 8 ++ bfd/elf32-ppc.c | 44 ++++++++-- bfd/elf64-ppc.c | 125 ++++++++++++++++++--------- ld/testsuite/ChangeLog | 16 ++++ ld/testsuite/ld-powerpc/powerpc.exp | 27 +++++- ld/testsuite/ld-powerpc/tlsmark.d | 9 +- ld/testsuite/ld-powerpc/tlsmark.s | 9 -- ld/testsuite/ld-powerpc/tlsmark32.d | 8 +- ld/testsuite/ld-powerpc/tlsmark32.s | 8 -- ld/testsuite/ld-powerpc/tlsopt1.d | 25 ++++++ ld/testsuite/ld-powerpc/tlsopt1.s | 14 +++ ld/testsuite/ld-powerpc/tlsopt1_32.d | 24 +++++ ld/testsuite/ld-powerpc/tlsopt1_32.s | 12 +++ ld/testsuite/ld-powerpc/tlsopt2.d | 23 +++++ ld/testsuite/ld-powerpc/tlsopt2.s | 11 +++ ld/testsuite/ld-powerpc/tlsopt2_32.d | 23 +++++ ld/testsuite/ld-powerpc/tlsopt2_32.s | 10 +++ ld/testsuite/ld-powerpc/tlsopt3.d | 26 ++++++ ld/testsuite/ld-powerpc/tlsopt3.s | 19 ++++ ld/testsuite/ld-powerpc/tlsopt3_32.d | 25 ++++++ ld/testsuite/ld-powerpc/tlsopt3_32.s | 17 ++++ ld/testsuite/ld-powerpc/tlsopt4.d | 48 ++++++++++ ld/testsuite/ld-powerpc/tlsopt4.s | 39 +++++++++ ld/testsuite/ld-powerpc/tlsopt4_32.d | 44 ++++++++++ ld/testsuite/ld-powerpc/tlsopt4_32.s | 34 ++++++++ 25 files changed, 568 insertions(+), 80 deletions(-) create mode 100644 ld/testsuite/ld-powerpc/tlsopt1.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt1.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt1_32.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt1_32.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt2.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt2.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt2_32.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt2_32.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt3.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt3.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt3_32.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt3_32.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt4.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt4.s create mode 100644 ld/testsuite/ld-powerpc/tlsopt4_32.d create mode 100644 ld/testsuite/ld-powerpc/tlsopt4_32.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e202e4bd7b8..b4eaf7a5a00 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2011-03-24 Alan Modra + + * 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. + 2011-03-22 Eric B. Weddington * bfd-in2.h: Regenerate. diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index fcbfa8337bf..9e097ad624d 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -4631,10 +4631,15 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, 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 +4651,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, 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 +4668,6 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, 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 +4682,34 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, 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 +4786,13 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, /* 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) diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index f17402fad27..4cbd941baa2 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -7473,6 +7473,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) bfd *ibfd; asection *sec; struct ppc_link_hash_table *htab; + unsigned char *toc_ref; int pass; if (info->relocatable || !info->executable) @@ -7482,23 +7483,25 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7523,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7538,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms)) free (locsyms); - return FALSE; + return ret; } if (h != NULL) @@ -7545,7 +7549,10 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7579,34 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) } 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 +7626,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7655,14 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) } 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 +7671,17 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7702,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7717,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7769,13 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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 +7786,12 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) /* 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 +7877,18 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info) 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; } diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index dafac0a6a20..6a824e38e10 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,19 @@ +2011-03-24 Alan Modra + + * 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. + 2011-03-15 Mike Frysinger * ld-elfvers/vers.exp (vers19): Add -Wl,-rpath-link,. to linker flags. diff --git a/ld/testsuite/ld-powerpc/powerpc.exp b/ld/testsuite/ld-powerpc/powerpc.exp index 6cb797e8513..ef0a6e16da1 100644 --- a/ld/testsuite/ld-powerpc/powerpc.exp +++ b/ld/testsuite/ld-powerpc/powerpc.exp @@ -1,5 +1,6 @@ # Expect script for ld-powerpc tests -# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009 Free Software Foundation +# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +# Free Software Foundation # # This file is part of the GNU Binutils. # @@ -123,6 +124,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 +189,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} diff --git a/ld/testsuite/ld-powerpc/tlsmark.d b/ld/testsuite/ld-powerpc/tlsmark.d index 8ba350e24a1..d892f3490c8 100644 --- a/ld/testsuite/ld-powerpc/tlsmark.d +++ b/ld/testsuite/ld-powerpc/tlsmark.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsmark.s b/ld/testsuite/ld-powerpc/tlsmark.s index dc42327747a..1bda55c89ae 100644 --- a/ld/testsuite/ld-powerpc/tlsmark.s +++ b/ld/testsuite/ld-powerpc/tlsmark.s @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsmark32.d b/ld/testsuite/ld-powerpc/tlsmark32.d index 74b74e31f68..548c1d51005 100644 --- a/ld/testsuite/ld-powerpc/tlsmark32.d +++ b/ld/testsuite/ld-powerpc/tlsmark32.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsmark32.s b/ld/testsuite/ld-powerpc/tlsmark32.s index 2fa48ae0d72..966d1b3f9f3 100644 --- a/ld/testsuite/ld-powerpc/tlsmark32.s +++ b/ld/testsuite/ld-powerpc/tlsmark32.s @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt1.d b/ld/testsuite/ld-powerpc/tlsopt1.d new file mode 100644 index 00000000000..ab1e1f778c0 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt1.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt1.s b/ld/testsuite/ld-powerpc/tlsopt1.s new file mode 100644 index 00000000000..e66e315c2fc --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt1.s @@ -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: diff --git a/ld/testsuite/ld-powerpc/tlsopt1_32.d b/ld/testsuite/ld-powerpc/tlsopt1_32.d new file mode 100644 index 00000000000..ae77639cb8c --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt1_32.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt1_32.s b/ld/testsuite/ld-powerpc/tlsopt1_32.s new file mode 100644 index 00000000000..aba2bbcaaae --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt1_32.s @@ -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: diff --git a/ld/testsuite/ld-powerpc/tlsopt2.d b/ld/testsuite/ld-powerpc/tlsopt2.d new file mode 100644 index 00000000000..097e8a43217 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt2.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt2.s b/ld/testsuite/ld-powerpc/tlsopt2.s new file mode 100644 index 00000000000..adfbfa87c64 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt2.s @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt2_32.d b/ld/testsuite/ld-powerpc/tlsopt2_32.d new file mode 100644 index 00000000000..5121f748772 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt2_32.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt2_32.s b/ld/testsuite/ld-powerpc/tlsopt2_32.s new file mode 100644 index 00000000000..bca12476d30 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt2_32.s @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt3.d b/ld/testsuite/ld-powerpc/tlsopt3.d new file mode 100644 index 00000000000..dee9b662a3d --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt3.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt3.s b/ld/testsuite/ld-powerpc/tlsopt3.s new file mode 100644 index 00000000000..9730ceb68f0 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt3.s @@ -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: diff --git a/ld/testsuite/ld-powerpc/tlsopt3_32.d b/ld/testsuite/ld-powerpc/tlsopt3_32.d new file mode 100644 index 00000000000..eba96d97249 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt3_32.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt3_32.s b/ld/testsuite/ld-powerpc/tlsopt3_32.s new file mode 100644 index 00000000000..6432c241561 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt3_32.s @@ -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: diff --git a/ld/testsuite/ld-powerpc/tlsopt4.d b/ld/testsuite/ld-powerpc/tlsopt4.d new file mode 100644 index 00000000000..cb81abeb755 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt4.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt4.s b/ld/testsuite/ld-powerpc/tlsopt4.s new file mode 100644 index 00000000000..f84dee5ac77 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt4.s @@ -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: diff --git a/ld/testsuite/ld-powerpc/tlsopt4_32.d b/ld/testsuite/ld-powerpc/tlsopt4_32.d new file mode 100644 index 00000000000..4b667f6d208 --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt4_32.d @@ -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 diff --git a/ld/testsuite/ld-powerpc/tlsopt4_32.s b/ld/testsuite/ld-powerpc/tlsopt4_32.s new file mode 100644 index 00000000000..9643fcb202c --- /dev/null +++ b/ld/testsuite/ld-powerpc/tlsopt4_32.s @@ -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: -- 2.30.2