Correct PowerPC64 local-dynamic TLS linker optimization
authorAlan Modra <amodra@gmail.com>
Thu, 29 Jan 2015 00:39:55 +0000 (11:09 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 29 Jan 2015 02:43:02 +0000 (13:13 +1030)
commitb86ac8e3a5a3117696b1760003b8e09ed13f1de9
tree62ef24abc3d0ef13113729ea6f1ae626e556e4af
parent912ae7dd0fa4658133d4fb77954a57c8548c37d6
Correct PowerPC64 local-dynamic TLS linker optimization

The linker hardcoded r3 into a local-dynamic to local-exec TLS
optimization sequence.  This is normally the case since r3 is required
as a parameter to (the optimized out) __tls_get_addr call.  However,
it is possible for a compiler, LLVM in this case, to set up the
parameter value in another register then copy it to r3 before the
call.

When fixing this problem, I noticed that ppc32 had another bug when
optimizing away one of the TLS insns to a nop.

The patch also tidies a mask used by global-dynamic to initial-exec
TLS optimization, to just select the fields needed.  Leaving the
offset in the instruction wasn't a bug since it will be overwritten
anyway.

bfd/
* elf64-ppc.c (ppc64_elf_relocate_section): Correct GOT_TLSLD
optimization.  Tidy mask for GOT_TLSGD optimization.
* elf32-ppc.c (ppc_elf_relocate_section): Likewise.  Correct
location of nop zapping high insn too.
ld/testsuite/
* ld-powerpc/tlsld.d, * ld-powerpc/tlsld.s: New test.
* ld-powerpc/tlsld32.d, * ld-powerpc/tlsld32.s: New test.
* ld-powerpc/powerpc.exp: Run them.  Move tocvar and tocnovar.
bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c
ld/testsuite/ChangeLog
ld/testsuite/ld-powerpc/powerpc.exp
ld/testsuite/ld-powerpc/tlsld.d [new file with mode: 0644]
ld/testsuite/ld-powerpc/tlsld.s [new file with mode: 0644]
ld/testsuite/ld-powerpc/tlsld32.d [new file with mode: 0644]
ld/testsuite/ld-powerpc/tlsld32.s [new file with mode: 0644]