PowerPC TPREL_HA/LO optimisation
authorAlan Modra <amodra@gmail.com>
Mon, 24 Aug 2020 07:02:57 +0000 (16:32 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 24 Aug 2020 11:45:06 +0000 (21:15 +0930)
commit252dcdf432c67f6baafb766ed068c64db1eb2bad
treef065483aba2070e20ef18b2c5cb711b82bb6041c
parentf16c3d4f137ae02fab0982782b2e1c2b2afc8583
PowerPC TPREL_HA/LO optimisation

ppc64 ld optimises sequences like the following
addis 3,13,wot@tprel@ha
lwz 3,wot@tprel@l(3)
to
nop
lwz 3,wot@tprel(13)
when "wot" is located near enough to the thread pointer.
However, the ABI doesn't require that R_PPC64_TPREL16_HA always be on
an addis rt,13,imm instruction, and while ld checked for that on the
high-part instruction it didn't disable the optimisation on the
low-part instruction.  This patch fixes that problem, disabling the
tprel optimisation globally if high-part instructions don't pass
sanity checks.  The optimisation is also enabled for ppc32, where
before ld.bfd had the code in the wrong place and ld.gold had it in a
block only enabled for ppc64.

bfd/
* elf32-ppc.c (ppc_elf_check_relocs): Set has_tls_reloc for
high part tprel16 relocs.
(ppc_elf_tls_optimize): Sanity check high part tprel16 relocs.
Clear do_tls_opt on odd instructions.
(ppc_elf_relocate_section): Move TPREL16_HA/LO optimisation later.
Don't sanity check them here.
* elf64-ppc.c (ppc64_elf_check_relocs): Set has_tls_reloc for
high part tprel16 relocs.
(ppc64_elf_tls_optimize): Sanity check high part tprel16 relocs.
Clear do_tls_opt on odd instructions.
(ppc64_elf_relocate_section): Don't sanity check TPREL16_HA.
ld/
* testsuite/ld-powerpc/tls32.d: Update for TPREL_HA/LO optimisation.
* testsuite/ld-powerpc/tlsexe32.d: Likewise.
* testsuite/ld-powerpc/tlsldopt32.d: Likewise.
* testsuite/ld-powerpc/tlsmark32.d: Likewise.
* testsuite/ld-powerpc/tlsopt4_32.d: Likewise.
* testsuite/ld-powerpc/tprel.s,
* testsuite/ld-powerpc/tprel.d,
* testsuite/ld-powerpc/tprel32.d: New tests.
* testsuite/ld-powerpc/tprelbad.s,
* testsuite/ld-powerpc/tprelbad.d: New test.
* testsuite/ld-powerpc/powerpc.exp: Run them.
gold/
* powerpc.cc (Target_powerpc): Add tprel_opt_ and accessors.
(Target_powerpc::Scan::local): Sanity check tprel high relocs.
(Target_powerpc::Scan::global): Likewise.
(Target_powerpc::Relocate::relocate): Control tprel optimisation
with tprel_opt_ and enable for 32-bit.
17 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/tls32.d
ld/testsuite/ld-powerpc/tlsexe32.d
ld/testsuite/ld-powerpc/tlsldopt32.d
ld/testsuite/ld-powerpc/tlsmark32.d
ld/testsuite/ld-powerpc/tlsopt4_32.d
ld/testsuite/ld-powerpc/tprel.d [new file with mode: 0644]
ld/testsuite/ld-powerpc/tprel.s [new file with mode: 0644]
ld/testsuite/ld-powerpc/tprel32.d [new file with mode: 0644]
ld/testsuite/ld-powerpc/tprelbad.d [new file with mode: 0644]
ld/testsuite/ld-powerpc/tprelbad.s [new file with mode: 0644]