From: Alan Modra Date: Thu, 26 Feb 2015 10:56:42 +0000 (+1030) Subject: PowerPC64 thread-safe stubs not needed for iplt X-Git-Tag: binutils-2_25_1~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=642fe3bed585c015f895425450543b5ebf6fa448;p=thirdparty%2Fbinutils-gdb.git PowerPC64 thread-safe stubs not needed for iplt I was looking at a current glibc using objdump today and saw an odd plt call stub. 0000000000044d80 <00000033.plt_call.__strchrnul>: 44d80: f8 41 00 28 std r2,40(r1) 44d84: e9 82 8c f8 ld r12,-29448(r2) 44d88: 7d 89 03 a6 mtctr r12 44d8c: e8 42 8d 00 ld r2,-29440(r2) 44d90: 28 22 00 00 cmpldi r2,0 44d94: 4c e2 04 20 bnectr+ 44d98: 48 13 84 f0 b 17d288 What? It doesn't branch to __strchrnul@plt on finding a zero r2? Turns out this isn't a real problem since the stub is for loading an ifunc, so will not be lazily resolved and thus r2 will never be zero. Of course, that means the thread-safety check is unnecessary. I also tweak the special __tls_get_addr_opt call stub here, to restore r2 immediately after the call. Not doing that might affect eh_frame unwinding. * elf64-ppc.c (plt_stub_size, build_plt_stub): Don't build thread-safe stubs for iplt. (build_tls_get_addr_stub): Restore r2 immediately after call. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 78fe403024c..9ef3b7b5efd 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,6 +1,11 @@ 2015-03-18 Alan Modra Apply from master + 2015-02-26 Alan Modra + * elf64-ppc.c (plt_stub_size, build_plt_stub): Don't build + thread-safe stubs for iplt. + (build_tls_get_addr_stub): Restore r2 immediately after call. + 2015-02-26 Alan Modra * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Heed -z nocopyreloc. Use text relocs rather than giving an error on trying to use diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 3026b4686ac..bcd1f6f8242 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -10206,7 +10206,10 @@ plt_stub_size (struct ppc_link_hash_table *htab, size += 4; if (htab->params->plt_static_chain) size += 4; - if (htab->params->plt_thread_safe) + if (htab->params->plt_thread_safe + && htab->elf.dynamic_sections_created + && stub_entry->h != NULL + && stub_entry->h->elf.dynindx != -1) size += 8; if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off)) size += 4; @@ -10246,16 +10249,18 @@ build_plt_stub (struct ppc_link_hash_table *htab, bfd *obfd = htab->params->stub_bfd; bfd_boolean plt_load_toc = htab->opd_abi; bfd_boolean plt_static_chain = htab->params->plt_static_chain; - bfd_boolean plt_thread_safe = htab->params->plt_thread_safe; + bfd_boolean plt_thread_safe = (htab->params->plt_thread_safe + && htab->elf.dynamic_sections_created + && stub_entry->h != NULL + && stub_entry->h->elf.dynindx != -1); bfd_boolean use_fake_dep = plt_thread_safe; bfd_vma cmp_branch_off = 0; if (!ALWAYS_USE_FAKE_DEP && plt_load_toc && plt_thread_safe - && !(stub_entry->h != NULL - && (stub_entry->h == htab->tls_get_addr_fd - || stub_entry->h == htab->tls_get_addr) + && !((stub_entry->h == htab->tls_get_addr_fd + || stub_entry->h == htab->tls_get_addr) && !htab->params->no_tls_get_addr_opt)) { bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1; @@ -10448,8 +10453,8 @@ build_tls_get_addr_stub (struct ppc_link_hash_table *htab, p = build_plt_stub (htab, stub_entry, p, offset, r); bfd_put_32 (obfd, BCTRL, p - 4); - bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4; bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4; + bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4; bfd_put_32 (obfd, MTLR_R11, p), p += 4; bfd_put_32 (obfd, BLR, p), p += 4;