PowerPC PIC vs. DLL TLS issues
authorAlan Modra <amodra@gmail.com>
Thu, 3 Oct 2019 23:18:41 +0000 (08:48 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 8 Oct 2019 14:03:38 +0000 (00:33 +1030)
commit1b1bf9a89a20ab627dbe8d421d55fe32b27e7106
treee2baf96b00a405c0e0337c2e81ba6ceaf548d51e
parent7cb2dcb804d0af6b5fa9981907bc1f097730ac1b
PowerPC PIC vs. DLL TLS issues

1) GOT entries generated for any of the GOT TLS relocations don't need
dynamic relocations for locally defined symbols in PIEs.  In the case
of a tls_index doubleword, the dtpmod entry is known to be 1, and the
dtprel entry is also known at link time and relative.  Similarly,
dtprel and tprel words are known at link time and relative.  (GOT
entries for other than TLS symbols are not relative and thus need
dynamic relocations in PIEs.)
2) Local dynamic TLS code is really only meant for accesses local to
the current binary.  There was a cheapskate test for this before using
the common tlsld_got slot, but the test wasn't exactly correct and
might confuse anyone looking at the code.  The proper test,
SYMBOL_REFERENCES_LOCAL isn't so expensive that it should be avoided.
3) The same cheap test for local syms when optimising TLS sequences
should be SYMBOL_REFERENCES_LOCAL too.

bfd/
* elf64-ppc.c (ppc64_elf_check_relocs): Move initialisation of vars.
(ppc64_elf_tls_optimize): Correct is_local condition.
(allocate_got): Don't reserve dynamic relocations for any of the
tls got relocs in PIEs when the symbol is local.
(allocate_dynrelocs): Correct validity test for local sym using
tlsld_got slot.
(ppc64_elf_size_dynamic_sections): Don't reserve dynamic relocations
for any of the tls got relocs in PIEs.
(ppc64_elf_layout_multitoc): Likewise.
(ppc64_elf_relocate_section): Correct validity test for local sym
using tlsld_got slot.  Don't emit dynamic relocations for any of
the tls got relocs in PIEs when the symbol is local.
* elf32-ppc.c (ppc_elf_tls_optimize): Correct is_local condition.
(got_relocs_needed): Delete.
(allocate_dynrelocs): Correct validity test for local sym using
tlsld_got slot.  Don't reserve dynamic relocations for any of the
tls got relocs in PIEs when the symbol is local.
(ppc_elf_size_dynamic_sections): Don't reserve dynamic relocations
for any of the tls got relocs in PIEs.
(ppc_elf_relocate_section): Correct validity test for local sym
using tlsld_got slot.  Don't emit dynamic relocations for any of
the tls got relocs in PIEs when the symbol is local.
ld/
* testsuite/ld-powerpc/tlsso.d: Adjust to suit tlsld_got usage change.
* testsuite/ld-powerpc/tlsso.g: Likewise.
* testsuite/ld-powerpc/tlsso.r: Likewise.
* testsuite/ld-powerpc/tlsso32.d: Likewise.
* testsuite/ld-powerpc/tlsso32.g: Likewise.
* testsuite/ld-powerpc/tlsso32.r: Likewise.

(cherry picked from commit f749f26eea052459c27e21d0d15f5fac060961dc)
bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c
ld/ChangeLog
ld/testsuite/ld-powerpc/tlsso.d
ld/testsuite/ld-powerpc/tlsso.g
ld/testsuite/ld-powerpc/tlsso.r
ld/testsuite/ld-powerpc/tlsso32.d
ld/testsuite/ld-powerpc/tlsso32.g
ld/testsuite/ld-powerpc/tlsso32.r