diff options
author | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2018-02-06 18:15:56 +0100 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2018-02-06 18:17:39 +0100 |
commit | c20c30f615756ddfccc4bb75c65ccfc1a399466e (patch) | |
tree | 9b5459a709bf72b5b53986110d56499cff9cdc52 /ld/testsuite/ld-sparc | |
parent | bca65a2394ce11bb4a0b001b8a986961c2e84881 (diff) | |
download | gdb-c20c30f615756ddfccc4bb75c65ccfc1a399466e.zip gdb-c20c30f615756ddfccc4bb75c65ccfc1a399466e.tar.gz gdb-c20c30f615756ddfccc4bb75c65ccfc1a399466e.tar.bz2 |
Fix PR ld/22263 on SPARC.
This is -fpie -pie generating dynamic relocations in the text section,
simply because no TLS transitions are applied in PIE mode. The meat
of the patch is to turn calls to bfd_link_pic (info) in TLS-related code
into !bfd_link_executable (info) and there are quite a lot of them...
bfd/
* elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
into call to !bfd_link_executable and tidy up.
(_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
<R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_IE_HI22>: Likewise.
<GOT relocations>: Remove useless code, tidy and merge blocks.
<R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_WPLT30>: Tidy up.
(_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call
to !bfd_link_executable.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
<R_SPARC_TLS_GD_HI22>: Merge into...
<R_SPARC_TLS_GD_LO10>: ...this. Adjust 4th argument in call to
sparc_elf_tls_transition and remove redundant code.
<R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_LDO_HIX22>: Likewise.
<R_SPARC_TLS_LE_HIX22>: Likewise. Tidy up.
<R_SPARC_TLS_LDM_CALL>: Likewise.
<R_SPARC_TLS_GD_CALL>: Likewise. Tidy up.
<R_SPARC_TLS_GD_ADD>: Likewise.
<R_SPARC_TLS_LDM_ADD>: Likewise.
<R_SPARC_TLS_LDO_ADD>: Likewise.
<R_SPARC_TLS_IE_LD>: Likewise.
ld/
* testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
(pr22263-1): Pass AFLAGS_PIC to the assembler.
* testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie32.dd: Adjust to above.
* testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie64.dd: Adjust to above.
Diffstat (limited to 'ld/testsuite/ld-sparc')
-rw-r--r-- | ld/testsuite/ld-sparc/tlspie32.dd | 55 | ||||
-rw-r--r-- | ld/testsuite/ld-sparc/tlspie32.s | 62 | ||||
-rw-r--r-- | ld/testsuite/ld-sparc/tlspie64.dd | 55 | ||||
-rw-r--r-- | ld/testsuite/ld-sparc/tlspie64.s | 62 |
4 files changed, 214 insertions, 20 deletions
diff --git a/ld/testsuite/ld-sparc/tlspie32.dd b/ld/testsuite/ld-sparc/tlspie32.dd index c31bcf5..a31e11a 100644 --- a/ld/testsuite/ld-sparc/tlspie32.dd +++ b/ld/testsuite/ld-sparc/tlspie32.dd @@ -10,9 +10,56 @@ Disassembly of section .text: -0[0-9a-f]+ <get_gdp>: +0[0-9a-f]+ <foo-0x8>: + +[0-9a-f]+: 81 c3 e0 08 retl + +[0-9a-f]+: ae 03 c0 17 add %o7, %l7, %l7 + +0[0-9a-f]+ <foo>: + +[0-9a-f]+: 9d e3 bf 98 save %sp, -104, %sp + +[0-9a-f]+: 2f 00 00 40 sethi %hi\(0x10000\), %l7 + +[0-9a-f]+: 7f ff ff fc call [0-9a-f]+ <.*> + +[0-9a-f]+: ae 05 e1 60 add %l7, 0x160, %l7 ! 10160 <.*> + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 00 60 04 add %g1, 4, %g1 ! 4 <.*> + +[0-9a-f]+: d0 05 c0 01 ld \[ %l7 \+ %g1 ], %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 90 01 c0 08 add %g7, %o0, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 - +[0-9a-f]+: 82 00 60 04 add %g1, 4, %g1 ! 4 <tls_gd\+0x4> - +[0-9a-f]+: 90 05 c0 01 add %l7, %g1, %o0 - +[0-9a-f]+: 40 00 40 43 call [0-9a-f]+ <__tls_get_addr@plt> + +[0-9a-f]+: 82 18 7f f4 xor %g1, -12, %g1 + +[0-9a-f]+: 90 01 c0 01 add %g7, %g1, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 90 10 00 00 mov %g0, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 18 7f f8 xor %g1, -8, %g1 + +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 18 7f fc xor %g1, -4, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 81 c7 e0 08 ret + +[0-9a-f]+: 81 e8 00 00 restore diff --git a/ld/testsuite/ld-sparc/tlspie32.s b/ld/testsuite/ld-sparc/tlspie32.s index 4d38d30..931aa53 100644 --- a/ld/testsuite/ld-sparc/tlspie32.s +++ b/ld/testsuite/ld-sparc/tlspie32.s @@ -1,20 +1,70 @@ - .section ".text" - .global tls_gd .section .tbss,"awT",@nobits + .global tls_gd .align 4 .type tls_gd, #object .size tls_gd, 4 tls_gd: .skip 4 + .global tls_ld + .align 4 + .type tls_ld, #object + .size tls_ld, 4 +tls_ld: + .skip 4 + .global tls_ie + .align 4 + .type tls_ie, #object + .size tls_ie, 4 +tls_ie: + .skip 4 .section ".text" +.LLGETPC0: + retl + add %o7, %l7, %l7 .align 4 - .global get_gdp - .type get_gdp, #function + .global foo + .type foo, #function .proc 0104 -get_gdp: +foo: + save %sp, -104, %sp + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 + call .LLGETPC0 + add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 + nop;nop;nop;nop + + /* GD -> IE with global variable not defined in executable */ + sethi %tgd_hi22(sG1), %g1 + add %g1, %tgd_lo10(sG1), %g1 + add %l7, %g1, %o0, %tgd_add(sG1) + call __tls_get_addr, %tgd_call(sG1) + nop + nop;nop;nop;nop + + /* GD -> LE with global variable defined in executable */ sethi %tgd_hi22(tls_gd), %g1 add %g1, %tgd_lo10(tls_gd), %g1 add %l7, %g1, %o0, %tgd_add(tls_gd) call __tls_get_addr, %tgd_call(tls_gd) nop - .size get_gdp, .-get_gdp + nop;nop;nop;nop + + /* LD -> LE with global variable defined in executable */ + sethi %tldm_hi22(tls_ld), %g1 + add %g1, %tldm_lo10(tls_ld), %g1 + add %l7, %g1, %o0, %tldm_add(tls_ld) + call __tls_get_addr, %tldm_call(tls_ld) + nop + sethi %tldo_hix22(tls_ld), %g1 + xor %g1, %tldo_lox10(tls_ld), %g1 + add %o0, %g1, %g1, %tldo_add(tls_ld) + nop;nop;nop;nop + + /* IE -> LE with global variable defined in executable */ + sethi %tie_hi22(tls_ie), %g1 + add %g1, %tie_lo10(tls_ie), %g1 + ld [%l7 + %g1], %g1, %tie_ld(tls_ie) + add %g7, %g1, %g1, %tie_add(tls_ie) + nop;nop;nop;nop + + ret + restore diff --git a/ld/testsuite/ld-sparc/tlspie64.dd b/ld/testsuite/ld-sparc/tlspie64.dd index bc4532e..6c8aea9 100644 --- a/ld/testsuite/ld-sparc/tlspie64.dd +++ b/ld/testsuite/ld-sparc/tlspie64.dd @@ -10,9 +10,56 @@ Disassembly of section .text: -0[0-9a-f]+ <get_gdp>: +0[0-9a-f]+ <foo-0x8>: + +[0-9a-f]+: 81 c3 e0 08 retl + +[0-9a-f]+: ae 03 c0 17 add %o7, %l7, %l7 + +0[0-9a-f]+ <foo>: + +[0-9a-f]+: 9d e3 bf 60 save %sp, -160, %sp + +[0-9a-f]+: 2f 00 04 00 sethi %hi\(0x100000\), %l7 + +[0-9a-f]+: 7f ff ff fc call [0-9a-f]+ <.*> + +[0-9a-f]+: ae 05 e2 08 add %l7, 0x208, %l7 ! 100208 <.*> + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 00 60 08 add %g1, 8, %g1 ! 8 <.*> + +[0-9a-f]+: d0 5d c0 01 ldx \[ %l7 \+ %g1 ], %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 90 01 c0 08 add %g7, %o0, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 - +[0-9a-f]+: 82 00 60 08 add %g1, 8, %g1 ! 8 <tls_gd\+0x8> - +[0-9a-f]+: 90 05 c0 01 add %l7, %g1, %o0 - +[0-9a-f]+: 40 04 00 bb call [0-9a-f]+ <__tls_get_addr@plt> + +[0-9a-f]+: 82 18 7f f4 xor %g1, -12, %g1 + +[0-9a-f]+: 90 01 c0 01 add %g7, %g1, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 90 10 00 00 mov %g0, %o0 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 18 7f f8 xor %g1, -8, %g1 + +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1 + +[0-9a-f]+: 82 18 7f fc xor %g1, -4, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1 + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 01 00 00 00 nop +[0-9a-f]+: 01 00 00 00 nop + +[0-9a-f]+: 81 c7 e0 08 ret + +[0-9a-f]+: 81 e8 00 00 restore diff --git a/ld/testsuite/ld-sparc/tlspie64.s b/ld/testsuite/ld-sparc/tlspie64.s index 4d38d30..b8a89e1 100644 --- a/ld/testsuite/ld-sparc/tlspie64.s +++ b/ld/testsuite/ld-sparc/tlspie64.s @@ -1,20 +1,70 @@ - .section ".text" - .global tls_gd .section .tbss,"awT",@nobits + .global tls_gd .align 4 .type tls_gd, #object .size tls_gd, 4 tls_gd: .skip 4 + .global tls_ld + .align 4 + .type tls_ld, #object + .size tls_ld, 4 +tls_ld: + .skip 4 + .global tls_ie + .align 4 + .type tls_ie, #object + .size tls_ie, 4 +tls_ie: + .skip 4 .section ".text" +.LLGETPC0: + retl + add %o7, %l7, %l7 .align 4 - .global get_gdp - .type get_gdp, #function + .global foo + .type foo, #function .proc 0104 -get_gdp: +foo: + save %sp, -160, %sp + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 + call .LLGETPC0 + add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 + nop;nop;nop;nop + + /* GD -> IE with global variable not defined in executable */ + sethi %tgd_hi22(sG1), %g1 + add %g1, %tgd_lo10(sG1), %g1 + add %l7, %g1, %o0, %tgd_add(sG1) + call __tls_get_addr, %tgd_call(sG1) + nop + nop;nop;nop;nop + + /* GD -> LE with global variable defined in executable */ sethi %tgd_hi22(tls_gd), %g1 add %g1, %tgd_lo10(tls_gd), %g1 add %l7, %g1, %o0, %tgd_add(tls_gd) call __tls_get_addr, %tgd_call(tls_gd) nop - .size get_gdp, .-get_gdp + nop;nop;nop;nop + + /* LD -> LE with global variable defined in executable */ + sethi %tldm_hi22(tls_ld), %g1 + add %g1, %tldm_lo10(tls_ld), %g1 + add %l7, %g1, %o0, %tldm_add(tls_ld) + call __tls_get_addr, %tldm_call(tls_ld) + nop + sethi %tldo_hix22(tls_ld), %g1 + xor %g1, %tldo_lox10(tls_ld), %g1 + add %o0, %g1, %g1, %tldo_add(tls_ld) + nop;nop;nop;nop + + /* IE -> LE with global variable defined in executable */ + sethi %tie_hi22(tls_ie), %g1 + add %g1, %tie_lo10(tls_ie), %g1 + ldx [%l7 + %g1], %g1, %tie_ldx(tls_ie) + add %g7, %g1, %g1, %tie_add(tls_ie) + nop;nop;nop;nop + + ret + restore |