mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-12 12:16:04 +08:00
252dcdf432
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.
48 lines
1.7 KiB
Makefile
48 lines
1.7 KiB
Makefile
#source: tls32.s
|
|
#source: tlslib32.s
|
|
#as: -a32
|
|
#ld:
|
|
#objdump: -dr
|
|
#target: powerpc*-*-*
|
|
|
|
.*
|
|
|
|
Disassembly of section \.text:
|
|
|
|
0+18000a0 <_start>:
|
|
.*: (42 9f 00 05|05 00 9f 42) bcl 20,4\*cr7\+so,.* <_start\+0x4>
|
|
.*: (7f c8 02 a6|a6 02 c8 7f) mflr r30
|
|
.*: (3f de 00 02|02 00 de 3f) addis r30,r30,2
|
|
.*: (3b de 80 a0|a0 80 de 3b) addi r30,r30,-32608
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 90 3c|3c 90 62 38) addi r3,r2,-28612
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 10 00|00 10 62 38) addi r3,r2,4096
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 90 20|20 90 62 38) addi r3,r2,-28640
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 10 00|00 10 62 38) addi r3,r2,4096
|
|
.*: (39 23 80 24|24 80 23 39) addi r9,r3,-32732
|
|
.*: (3d 23 00 00|00 00 23 3d) addis r9,r3,0
|
|
.*: (81 49 80 28|28 80 49 81) lwz r10,-32728\(r9\)
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (a1 42 90 30|30 90 42 a1) lhz r10,-28624\(r2\)
|
|
.*: (89 42 90 34|34 90 42 89) lbz r10,-28620\(r2\)
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (99 42 90 38|38 90 42 99) stb r10,-28616\(r2\)
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 90 00|00 90 62 38) addi r3,r2,-28672
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (38 62 10 00|00 10 62 38) addi r3,r2,4096
|
|
.*: (91 43 80 04|04 80 43 91) stw r10,-32764\(r3\)
|
|
.*: (3d 23 00 00|00 00 23 3d) addis r9,r3,0
|
|
.*: (91 49 80 08|08 80 49 91) stw r10,-32760\(r9\)
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (b1 42 90 30|30 90 42 b1) sth r10,-28624\(r2\)
|
|
.*: (a1 42 90 14|14 90 42 a1) lhz r10,-28652\(r2\)
|
|
.*: (60 00 00 00|00 00 00 60) nop
|
|
.*: (a9 42 90 18|18 90 42 a9) lha r10,-28648\(r2\)
|
|
|
|
0+1800120 <__tls_get_addr>:
|
|
.*: (4e 80 00 20|20 00 80 4e) blr
|