diff options
author | Alan Modra <amodra@gmail.com> | 2017-01-24 08:43:01 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2017-01-24 12:15:54 +1030 |
commit | f0158f44168c29338e0b4424c69589f79bf58b19 (patch) | |
tree | 6dc86299e189f17a526e41b275c1be42d303a391 /ld | |
parent | 741bcbe94d7811caa1efa500dacd047c428cce61 (diff) | |
download | gdb-f0158f44168c29338e0b4424c69589f79bf58b19.zip gdb-f0158f44168c29338e0b4424c69589f79bf58b19.tar.gz gdb-f0158f44168c29338e0b4424c69589f79bf58b19.tar.bz2 |
PowerPC dynamic relocations
This patch fixes a number of issues with powerpc dynamic relocations.
1) Both ppc and ppc64 were emitting more dynamic symbols and
relocations than necessary, due to not supporting static linker
resolution of tls_index entries for __tls_get_addr_opt. This meant
that any @got@tlsgd or @got@tlsld reloc needed to make their symbols
dynamic and generate dptmod and dtprel relocs for the dynamic linker.
That would have been passable, but what happened was that practically
all @got relocations resulted in their symbols being made dynamic and
dynamic relocations emitted against the GOT entries. (Mostly visible
on ppc32 executables since ppc64 gcc really only uses @got style
relocs for TLS.)
2) The PowerOpen syntax was not supported with __tls_get_addr_opt.
DTPMOD/DTPREL relocs on tls_index TOC entries did not use the trick of
forcing dynamic symbols and relocations so those entries always
resulted in the full __tls_get_addr processing. gcc doesn't use the
PowerOpen syntax for TLS, and normally such code would be optimized to
TLS IE or LE so the impact of missing this support was minimal.
3) In an executable, relocations against GNU indirect functions always
used the value of their PLT stub. While this is correct, it is
better in some cases to use a dynamic relocation. An extra dynamic
relocation can mean that calls via function pointers need not bounce
through the PLT stub at runtime.
The patch also tidies the PLT handling code in ppc32
allocate_dynrelocs. Allocating PLT entries after other dynamic relocs
allows the PLT loop to omit special handling for undefined weak
symbols, and that in turn allows the loop to be simplified.
bfd/
* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Merge two cases
where dynamic relocs are preferable. Allow ifunc too.
(ensure_undefweak_dynamic): New function.
(allocate_dynrelocs): Use it here. Move plt handling last and
don't make symbols dynamic, simplifying loop. Only make undef
weak symbols with GOT entries dynamic. Correct condition
for GOT relocs. Handle dynamic relocs on ifuncs. Correct
comments. Remove goto.
(ppc_elf_relocate_section): Correct test for using dynamic
symbol on GOT relocs. Rearrange test for emitting GOT relocs
to suit. Set up explicit tls_index entries and implicit GOT
tls_index entries resolvable at link time for
__tls_get_addr_opt. Simplify test to clear mem for prelink.
* elf64-ppc.c (allocate_got): Correct condition for GOT relocs.
(ensure_undefweak_dynamic): New function.
(allocate_dynrelocs): Use it here. Only make undef weak symbols
with GOT entries dynamic. Remove unnecessary test of
WILL_CALL_FINISH_DYNAMIC_SYMBOL in PLT handling.
(ppc64_elf_relocate_section): Correct test for using dynamic
symbol on GOT relocs. Rearrange test for emitting GOT relocs
to suit. Set up explicit tls_index entries and implicit GOT
tls_index entries resolvable at link time for __tls_get_addr_opt.
Simplify expression to clear mem for prelink.
ld/
* testsuite/ld-powerpc/tlsexe.r: Update for fewer dynamic relocs
and symbols.
* testsuite/ld-powerpc/tlsexe.d: Likewise.
* testsuite/ld-powerpc/tlsexe.g: Likewise.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-powerpc/tlsexe.d | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-powerpc/tlsexe.g | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-powerpc/tlsexe.r | 4 |
4 files changed, 12 insertions, 7 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index cf1d670..f2566a2 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2017-01-24 Alan Modra <amodra@gmail.com> + + * testsuite/ld-powerpc/tlsexe.r: Update for fewer dynamic relocs + and symbols. + * testsuite/ld-powerpc/tlsexe.d: Likewise. + * testsuite/ld-powerpc/tlsexe.g: Likewise. + 2017-01-23 Yury Norov <ynorov@caviumnetworks.com> * testsuite/ld-aarch64/aarch64-elf.exp: Run new tests. diff --git a/ld/testsuite/ld-powerpc/tlsexe.d b/ld/testsuite/ld-powerpc/tlsexe.d index 5a449f7..b536622 100644 --- a/ld/testsuite/ld-powerpc/tlsexe.d +++ b/ld/testsuite/ld-powerpc/tlsexe.d @@ -67,8 +67,8 @@ Disassembly of section \.text: .* (e9 4d 90 2a|2a 90 4d e9) lwa r10,-28632\(r13\) .* (3d 2d 00 00|00 00 2d 3d) addis r9,r13,0 .* (a9 49 90 30|30 90 49 a9) lha r10,-28624\(r9\) -.* (00 00 00 00|e0 02 01 00) .* -.* (00 01 02 e0|00 00 00 00) .* +.* (00 00 00 00|20 02 01 00) .* +.* (00 01 02 20|00 00 00 00) .* .* <__glink_PLTresolve>: .* (7d 88 02 a6|a6 02 88 7d) mflr r12 .* (42 9f 00 05|05 00 9f 42) bcl 20,4\*cr7\+so,.* diff --git a/ld/testsuite/ld-powerpc/tlsexe.g b/ld/testsuite/ld-powerpc/tlsexe.g index 8c15244..8bb3dea 100644 --- a/ld/testsuite/ld-powerpc/tlsexe.g +++ b/ld/testsuite/ld-powerpc/tlsexe.g @@ -7,6 +7,6 @@ .* Contents of section \.got: - 10010700 (00000000|00870110) (10018700|00000000) (ffffffff|1880ffff) (ffff8018|ffffffff) .* -.* 00000000 00000000 00000000 00000000 .* + 10010600 (00000000|00860110) (10018600|00000000) (ffffffff|1880ffff) (ffff8018|ffffffff) .* .* 00000000 00000000 00000000 00000000 .* +.* 00000000 00000000 (ffffffff|5080ffff) (ffff8050|ffffffff) .* diff --git a/ld/testsuite/ld-powerpc/tlsexe.r b/ld/testsuite/ld-powerpc/tlsexe.r index 11da4a8..f51b17e 100644 --- a/ld/testsuite/ld-powerpc/tlsexe.r +++ b/ld/testsuite/ld-powerpc/tlsexe.r @@ -51,11 +51,10 @@ Program Headers: +04 +\.dynamic * +05 +\.tdata \.tbss * -Relocation section '\.rela\.dyn' at offset .* contains 3 entries: +Relocation section '\.rela\.dyn' at offset .* contains 2 entries: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend [0-9a-f ]+R_PPC64_TPREL64 +0+ gd \+ 0 [0-9a-f ]+R_PPC64_DTPMOD64 +0+ ld \+ 0 -[0-9a-f ]+R_PPC64_DTPREL64 +0+50 ld2 \+ 0 Relocation section '\.rela\.plt' at offset .* contains 1 entries: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend @@ -66,7 +65,6 @@ Symbol table '\.dynsym' contains [0-9]+ entries: .* NOTYPE +LOCAL +DEFAULT +UND * .* TLS +GLOBAL +DEFAULT +UND gd .* TLS +GLOBAL +DEFAULT +UND ld -.* TLS +GLOBAL +DEFAULT +9 ld2 .* NOTYPE +GLOBAL +DEFAULT +13 __bss_start .* FUNC +GLOBAL +DEFAULT +UND __tls_get_addr_opt .* NOTYPE +GLOBAL +DEFAULT +13 _edata |