ld --gc-sections fail with __tls_get_addr_opt

When --gc-sections is active, __tls_get_addr_opt is marked as not
needed and forced local before ppc*_elf_tls_setup is run.

bfd/
	PR 20060
	* elf64-ppc.c (ppc64_elf_tls_setup): Clear forced_local.
	* elf32-ppc.c (ppc_elf_tls_setup): Likewise.
ld/
	PR 20060
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/tlsdll.s: New.
	* testsuite/ld-powerpc/tlsdll.ver: New.
	* testsuite/ld-powerpc/tlsdll_32.s: New.
	* testsuite/ld-powerpc/tlsopt5.d: New.
	* testsuite/ld-powerpc/tlsopt5.s: New.
	* testsuite/ld-powerpc/tlsopt5_32.d: New.
	* testsuite/ld-powerpc/tlsopt5_32.s: New.
This commit is contained in:
Alan Modra 2016-05-11 21:54:05 +09:30
parent a6684f0ddd
commit 3bd43ebcb6
12 changed files with 190 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2016-05-11 Alan Modra <amodra@gmail.com>
PR 20060
* elf64-ppc.c (ppc64_elf_tls_setup): Clear forced_local.
* elf32-ppc.c (ppc_elf_tls_setup): Likewise.
2016-05-10 Jiong Wang <jiong.wang@arm.com> 2016-05-10 Jiong Wang <jiong.wang@arm.com>
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Remove redundant * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Remove redundant

View File

@ -5164,6 +5164,7 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
tga->root.type = bfd_link_hash_indirect; tga->root.type = bfd_link_hash_indirect;
tga->root.u.i.link = &opt->root; tga->root.u.i.link = &opt->root;
ppc_elf_copy_indirect_symbol (info, opt, tga); ppc_elf_copy_indirect_symbol (info, opt, tga);
opt->forced_local = 0;
if (opt->dynindx != -1) if (opt->dynindx != -1)
{ {
/* Use __tls_get_addr_opt in dynamic relocations. */ /* Use __tls_get_addr_opt in dynamic relocations. */

View File

@ -8226,6 +8226,7 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
tga_fd->root.type = bfd_link_hash_indirect; tga_fd->root.type = bfd_link_hash_indirect;
tga_fd->root.u.i.link = &opt_fd->root; tga_fd->root.u.i.link = &opt_fd->root;
ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd); ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
opt_fd->forced_local = 0;
if (opt_fd->dynindx != -1) if (opt_fd->dynindx != -1)
{ {
/* Use __tls_get_addr_opt in dynamic relocations. */ /* Use __tls_get_addr_opt in dynamic relocations. */
@ -8242,6 +8243,7 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
tga->root.type = bfd_link_hash_indirect; tga->root.type = bfd_link_hash_indirect;
tga->root.u.i.link = &opt->root; tga->root.u.i.link = &opt->root;
ppc64_elf_copy_indirect_symbol (info, opt, tga); ppc64_elf_copy_indirect_symbol (info, opt, tga);
opt->forced_local = 0;
_bfd_elf_link_hash_hide_symbol (info, opt, _bfd_elf_link_hash_hide_symbol (info, opt,
tga->forced_local); tga->forced_local);
htab->tls_get_addr = (struct ppc_link_hash_entry *) opt; htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;

View File

@ -1,3 +1,15 @@
2016-05-11 Alan Modra <amodra@gmail.com>
PR 20060
* testsuite/ld-powerpc/powerpc.exp: Run new tests.
* testsuite/ld-powerpc/tlsdll.s: New.
* testsuite/ld-powerpc/tlsdll.ver: New.
* testsuite/ld-powerpc/tlsdll_32.s: New.
* testsuite/ld-powerpc/tlsopt5.d: New.
* testsuite/ld-powerpc/tlsopt5.s: New.
* testsuite/ld-powerpc/tlsopt5_32.d: New.
* testsuite/ld-powerpc/tlsopt5_32.s: New.
2016-05-10 Thomas Preud'homme <thomas.preudhomme@arm.com> 2016-05-10 Thomas Preud'homme <thomas.preudhomme@arm.com>
* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Use * emultempl/armelf.em (gld${EMULATION_NAME}_finish): Use

View File

@ -138,6 +138,11 @@ set ppcelftests {
{"TLS32 opt 4" "-melf32ppc" "" "-a32" {tlsopt4_32.s tlslib32.s} {"TLS32 opt 4" "-melf32ppc" "" "-a32" {tlsopt4_32.s tlslib32.s}
{{objdump -dr tlsopt4_32.d}} {{objdump -dr tlsopt4_32.d}}
"tlsopt4_32"} "tlsopt4_32"}
{"TLS32 DLL" "-shared -melf32ppc --version-script tlsdll.ver" "" "-a32" {tlsdll_32.s}
{} "tlsdll32.so"}
{"TLS32 opt 5" "-melf32ppc --gc-sections --secure-plt tmpdir/tlsdll32.so" "" "-a32" {tlsopt5_32.s}
{{objdump -dr tlsopt5_32.d}}
"tlsopt5_32"}
{"Shared library with global symbol" "-shared -melf32ppc" "" "-a32" {sdalib.s} {"Shared library with global symbol" "-shared -melf32ppc" "" "-a32" {sdalib.s}
{} "sdalib.so"} {} "sdalib.so"}
{"Dynamic application with SDA" "-melf32ppc tmpdir/sdalib.so" "" "-a32" {sdadyn.s} {"Dynamic application with SDA" "-melf32ppc tmpdir/sdalib.so" "" "-a32" {sdadyn.s}
@ -203,6 +208,11 @@ set ppc64elftests {
{"TLS opt 4" "-melf64ppc" "" "-a64" {tlsopt4.s tlslib.s} {"TLS opt 4" "-melf64ppc" "" "-a64" {tlsopt4.s tlslib.s}
{{objdump -dr tlsopt4.d}} {{objdump -dr tlsopt4.d}}
"tlsopt4"} "tlsopt4"}
{"TLS DLL" "-shared -melf64ppc --version-script tlsdll.ver" "" "-a64" {tlsdll.s}
{} "tlsdll.so"}
{"TLS opt 5" "-melf64ppc --gc-sections tmpdir/tlsdll.so" "" "-a64" {tlsopt5.s}
{{objdump -dr tlsopt5.d}}
"tlsopt5"}
{"sym@tocbase" "-shared -melf64ppc" "" "-a64" {symtocbase-1.s symtocbase-2.s} {"sym@tocbase" "-shared -melf64ppc" "" "-a64" {symtocbase-1.s symtocbase-2.s}
{{objdump -dj.data symtocbase.d}} "symtocbase.so"} {{objdump -dj.data symtocbase.d}} "symtocbase.so"}
{"TOC opt" "-melf64ppc" "" "-a64" {tocopt.s} {"TOC opt" "-melf64ppc" "" "-a64" {tocopt.s}

View File

@ -0,0 +1,19 @@
.abiversion 2
.global __tls_get_addr,__tls_get_addr_opt,gd,ld
.type __tls_get_addr,@function
.type __tls_get_addr_opt,@function
.text
__tls_get_addr:
__tls_get_addr_opt:
blr
.size __tls_get_addr,. - __tls_get_addr
.size __tls_get_addr_opt,. - __tls_get_addr_opt
.section ".tbss","awT",@nobits
.p2align 3
gd: .space 8
.section ".tdata","awT",@progbits
.p2align 2
ld: .long 0xc0ffee

View File

@ -0,0 +1,7 @@
GLIBC_2.3 {
__tls_get_addr;
};
GLIBC_2.22 {
__tls_get_addr_opt;
} GLIBC_2.3;

View File

@ -0,0 +1,18 @@
.global __tls_get_addr,__tls_get_addr_opt,gd,ld
.type __tls_get_addr,@function
.type __tls_get_addr_opt,@function
.text
__tls_get_addr:
__tls_get_addr_opt:
blr
.size __tls_get_addr,. - __tls_get_addr
.size __tls_get_addr_opt,. - __tls_get_addr_opt
.section ".tbss","awT",@nobits
.p2align 2
gd: .space 4
.section ".tdata","awT",@progbits
.p2align 2
ld: .long 0xc0ffee

View File

@ -0,0 +1,54 @@
#source: tlsopt5.s
#as: -a64
#ld: --gc-sections tlsdll.so
#objdump: -dr
#target: powerpc64*-*-*
.*
Disassembly of section \.text:
0000000010000300 <.*\.plt_call\.__tls_get_addr_opt@@GLIBC_2\.22>:
.*: (00 00 63 e9|e9 63 00 00) ld r11,0\(r3\)
.*: (08 00 83 e9|e9 83 00 08) ld r12,8\(r3\)
.*: (78 1b 60 7c|7c 60 1b 78) mr r0,r3
.*: (00 00 2b 2c|2c 2b 00 00) cmpdi r11,0
.*: (14 6a 6c 7c|7c 6c 6a 14) add r3,r12,r13
.*: (20 00 82 4d|4d 82 00 20) beqlr
.*: (78 03 03 7c|7c 03 03 78) mr r3,r0
.*: (a6 02 68 7d|7d 68 02 a6) mflr r11
.*: (08 00 61 f9|f9 61 00 08) std r11,8\(r1\)
.*: (18 00 41 f8|f8 41 00 18) std r2,24\(r1\)
.*: (28 80 82 e9|e9 82 80 28) ld r12,-32728\(r2\)
.*: (a6 03 89 7d|7d 89 03 a6) mtctr r12
.*: (21 04 80 4e|4e 80 04 21) bctrl
.*: (18 00 41 e8|e8 41 00 18) ld r2,24\(r1\)
.*: (08 00 61 e9|e9 61 00 08) ld r11,8\(r1\)
.*: (a6 03 68 7d|7d 68 03 a6) mtlr r11
.*: (20 00 80 4e|4e 80 00 20) blr
0000000010000344 <_start>:
.*: (08 80 62 38|38 62 80 08) addi r3,r2,-32760
.*: (b9 ff ff 4b|4b ff ff b9) bl .*
.*: (00 00 00 60|60 00 00 00) nop
.*: (b8 02 01 00|00 00 00 00) .*
.*: (00 00 00 00|00 01 02 b8) .*
0000000010000358 <__glink_PLTresolve>:
.*: (a6 02 08 7c|7c 08 02 a6) mflr r0
.*: (05 00 9f 42|42 9f 00 05) bcl .*
.*: (a6 02 68 7d|7d 68 02 a6) mflr r11
.*: (f0 ff 4b e8|e8 4b ff f0) ld r2,-16\(r11\)
.*: (a6 03 08 7c|7c 08 03 a6) mtlr r0
.*: (50 60 8b 7d|7d 8b 60 50) subf r12,r11,r12
.*: (14 5a 62 7d|7d 62 5a 14) add r11,r2,r11
.*: (d0 ff 0c 38|38 0c ff d0) addi r0,r12,-48
.*: (00 00 8b e9|e9 8b 00 00) ld r12,0\(r11\)
.*: (82 f0 00 78|78 00 f0 82) rldicl r0,r0,62,2
.*: (a6 03 89 7d|7d 89 03 a6) mtctr r12
.*: (08 00 6b e9|e9 6b 00 08) ld r11,8\(r11\)
.*: (20 04 80 4e|4e 80 04 20) bctr
.*: (00 00 00 60|60 00 00 00) nop
0000000010000390 <__tls_get_addr_opt@plt>:
.*: (c8 ff ff 4b|4b ff ff c8) b .*

View File

@ -0,0 +1,5 @@
.globl _start
_start:
addi 3,2,gd@got@tlsgd
bl __tls_get_addr(gd@tlsgd)
nop

View File

@ -0,0 +1,52 @@
#source: tlsopt5_32.s
#as: -a32
#ld: --gc-sections --secure-plt tlsdll32.so
#objdump: -dr
#target: powerpc*-*-*
.*
Disassembly of section \.text:
01800230 <_start>:
.*: (f8 ff 6d 38|38 6d ff f8) addi r3,r13,-8
.*: (0d 00 00 48|48 00 00 0d) bl 1800240 <__tls_get_addr_opt@plt>
\.\.\.
01800240 <__tls_get_addr_opt@plt>:
.*: (00 00 63 81|81 63 00 00) lwz r11,0\(r3\)
.*: (04 00 83 81|81 83 00 04) lwz r12,4\(r3\)
.*: (78 1b 60 7c|7c 60 1b 78) mr r0,r3
.*: (00 00 0b 2c|2c 0b 00 00) cmpwi r11,0
.*: (14 12 6c 7c|7c 6c 12 14) add r3,r12,r2
.*: (20 00 82 4d|4d 82 00 20) beqlr
.*: (78 03 03 7c|7c 03 03 78) mr r3,r0
.*: (00 00 00 60|60 00 00 00) nop
.*: (81 01 60 3d|3d 60 01 81) lis r11,385
.*: (9c 03 6b 81|81 6b 03 9c) lwz r11,924\(r11\)
.*: (a6 03 69 7d|7d 69 03 a6) mtctr r11
.*: (20 04 80 4e|4e 80 04 20) bctr
01800270 <__glink>:
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
01800280 <__glink_PLTresolve>:
.*: (81 01 80 3d|3d 80 01 81) lis r12,385
.*: (80 fe 6b 3d|3d 6b fe 80) addis r11,r11,-384
.*: (94 03 0c 80|80 0c 03 94) lwz r0,916\(r12\)
.*: (90 fd 6b 39|39 6b fd 90) addi r11,r11,-624
.*: (a6 03 09 7c|7c 09 03 a6) mtctr r0
.*: (14 5a 0b 7c|7c 0b 5a 14) add r0,r11,r11
.*: (98 03 8c 81|81 8c 03 98) lwz r12,920\(r12\)
.*: (14 5a 60 7d|7d 60 5a 14) add r11,r0,r11
.*: (20 04 80 4e|4e 80 04 20) bctr
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop
.*: (00 00 00 60|60 00 00 00) nop

View File

@ -0,0 +1,4 @@
.globl _start
_start:
addi 3,13,gd@got@tlsgd
bl __tls_get_addr(gd@tlsgd)