PowerPC TPREL16_HA/LO reloc optimization
authorAlan Modra <amodra@gmail.com>
Wed, 30 Aug 2017 11:05:35 +0000 (20:35 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 30 Aug 2017 11:13:31 +0000 (20:43 +0930)
commit9a23f96e919ba91587d077b1d399246dde4002dd
tree1eb693e16708eef776aece4643cda8dfde86301c
parentb9f04fe0dfe64bc6224e7bb96378607f17da7446
PowerPC TPREL16_HA/LO reloc optimization

In the TLS GD/LD to LE optimization, ld replaces a sequence like

 addi 3,2,x@got@tlsgd R_PPC64_GOT_TLSGD16 x
 bl __tls_get_addr(x@tlsgd) R_PPC64_TLSGD x
R_PPC64_REL24 __tls_get_addr
 nop

with

 addis 3,13,x@tprel@ha R_PPC64_TPREL16_HA x
 addi 3,3,x@tprel@l R_PPC64_TPREL16_LO x
 nop

When the tprel offset is small, this can be further optimized to

 nop
 addi 3,13,x@tprel
 nop

bfd/
* elf64-ppc.c (struct ppc_link_hash_table): Add do_tls_opt.
(ppc64_elf_tls_optimize): Set it.
(ppc64_elf_relocate_section): Nop addis on TPREL16_HA, and convert
insn on TPREL16_LO and TPREL16_LO_DS relocs to use r13 when
addis would add zero.
* elf32-ppc.c (struct ppc_elf_link_hash_table): Add do_tls_opt.
(ppc_elf_tls_optimize): Set it.
(ppc_elf_relocate_section): Nop addis on TPREL16_HA, and convert
insn on TPREL16_LO relocs to use r2 when addis would add zero.
gold/
* powerpc.cc (Target_powerpc::Relocate::relocate): Nop addis on
TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS
relocs to use r2/r13 when addis would add zero.
ld/
* testsuite/ld-powerpc/tls.s: Add calls with tls markers.
* testsuite/ld-powerpc/tls32.s: Likewise.
* testsuite/ld-powerpc/powerpc.exp: Run tls marker tests.
* testsuite/ld-powerpc/tls.d: Adjust for TPREL16_HA/LO optimization.
* testsuite/ld-powerpc/tlsexe.d: Likewise.
* testsuite/ld-powerpc/tlsexetoc.d: Likewise.
* testsuite/ld-powerpc/tlsld.d: Likewise.
* testsuite/ld-powerpc/tlsmark.d: Likewise.
* testsuite/ld-powerpc/tlsopt4.d: Likewise.
* testsuite/ld-powerpc/tlstoc.d: Likewise.
16 files changed:
bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c
gold/ChangeLog
gold/powerpc.cc
ld/ChangeLog
ld/testsuite/ld-powerpc/powerpc.exp
ld/testsuite/ld-powerpc/tls.d
ld/testsuite/ld-powerpc/tls.s
ld/testsuite/ld-powerpc/tls32.s
ld/testsuite/ld-powerpc/tlsexe.d
ld/testsuite/ld-powerpc/tlsexetoc.d
ld/testsuite/ld-powerpc/tlsld.d
ld/testsuite/ld-powerpc/tlsmark.d
ld/testsuite/ld-powerpc/tlsopt4.d
ld/testsuite/ld-powerpc/tlstoc.d