mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-03 04:12:10 +08:00
c213164ad2
This patch supports using pcrel instructions in TLS code sequences. A number of new relocations are needed, gas operand modifiers to generate those relocations, and new TLS optimisation. For optimisation it turns out that the new pcrel GD and LD sequences can be distinguished from the non-pcrel GD and LD sequences by there being different relocations on the new sequence. The final "add ra,rb,13" on IE sequences similarly needs a new relocation, or as I chose, a modification of R_PPC64_TLS. On pcrel IE code, the R_PPC64_TLS points one byte into the "add" instruction rather than being on the instruction boundary. GD: pla 3,z@got@tlsgd@pcrel # R_PPC64_GOT_TLSGD34 bl __tls_get_addr@notoc(z@tlsgd) # R_PPC64_TLSGD and R_PPC64_REL24_NOTOC edited to IE pld 3,z@got@tprel@pcrel add 3,3,13 edited to LE paddi 3,13,z@tprel nop LD: pla 3,z@got@tlsld@pcrel # R_PPC64_GOT_TLSLD34 bl __tls_get_addr@notoc(z@tlsld) # R_PPC64_TLSLD and R_PPC64_REL24_NOTOC .. paddi 9,3,z2@dtprel pld 10,z3@got@dtprel@pcrel add 10,10,3 edited to LE paddi 3,13,0x1000 nop IE: pld 9,z@got@tprel@pcrel # R_PPC64_GOT_TPREL34 add 3,9,z@tls@pcrel # R_PPC64_TLS at insn+1 ldx 4,9,z@tls@pcrel lwax 5,9,z@tls@pcrel stdx 5,9,z@tls@pcrel edited to LE paddi 9,13,z@tprel nop ld 4,0(9) lwa 5,0(9) std 5,0(9) LE: paddi 10,13,z@tprel include/ * elf/ppc64.h (R_PPC64_TPREL34, R_PPC64_DTPREL34), (R_PPC64_GOT_TLSGD34, R_PPC64_GOT_TLSLD34), (R_PPC64_GOT_TPREL34, R_PPC64_GOT_DTPREL34): Define. (IS_PPC64_TLS_RELOC): Include new tls relocs. bfd/ * reloc.c (BFD_RELOC_PPC64_TPREL34, BFD_RELOC_PPC64_DTPREL34), (BFD_RELOC_PPC64_GOT_TLSGD34, BFD_RELOC_PPC64_GOT_TLSLD34), (BFD_RELOC_PPC64_GOT_TPREL34, BFD_RELOC_PPC64_GOT_DTPREL34), (BFD_RELOC_PPC64_TLS_PCREL): New pcrel tls relocs. * elf64-ppc.c (ppc64_elf_howto_raw): Add howtos for pcrel tls relocs. (ppc64_elf_reloc_type_lookup): Translate pcrel tls relocs. (must_be_dyn_reloc, dec_dynrel_count): Add R_PPC64_TPREL64. (ppc64_elf_check_relocs): Support pcrel tls relocs. (ppc64_elf_tls_optimize, ppc64_elf_relocate_section): Likewise. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): Map "tls@pcrel", "got@tlsgd@pcrel", "got@tlsld@pcrel", "got@tprel@pcrel", and "got@dtprel@pcrel". (fixup_size, md_assemble): Handle pcrel tls relocs. (ppc_force_relocation, ppc_fix_adjustable): Likewise. (md_apply_fix, tc_gen_reloc): Likewise. ld/ * testsuite/ld-powerpc/tlsgd.d, * testsuite/ld-powerpc/tlsgd.s, * testsuite/ld-powerpc/tlsie.d, * testsuite/ld-powerpc/tlsie.s, * testsuite/ld-powerpc/tlsld.d, * testsuite/ld-powerpc/tlsld.s: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
59 lines
959 B
ArmAsm
59 lines
959 B
ArmAsm
.section ".tbss","awT",@nobits
|
|
.p2align 3
|
|
pad: .space 8
|
|
.global a
|
|
a: .space 8
|
|
.global b
|
|
b: .space 8
|
|
.global c
|
|
c: .space 8
|
|
.global d
|
|
d: .space 8
|
|
z2: .space 8
|
|
z3: .space 8
|
|
|
|
.text
|
|
.globl _start
|
|
_start:
|
|
#Small model OpenPower
|
|
addi 3,2,.La@toc
|
|
bl __tls_get_addr(.La@tlsld)
|
|
nop
|
|
.section .toc,"aw",@progbits
|
|
.p2align 3
|
|
.La:
|
|
.quad a@dtpmod
|
|
.quad 0
|
|
.text
|
|
|
|
#Medium mode ELF
|
|
addis 3,2,b@got@tlsld@ha
|
|
addi 3,3,b@got@tlsld@l
|
|
bl __tls_get_addr(b@tlsld)
|
|
nop
|
|
|
|
#PCrel, with dtprel access to vars
|
|
pla 3,c@got@tlsld@pcrel
|
|
bl __tls_get_addr@notoc(c@tlsld)
|
|
paddi 9,3,z2@dtprel
|
|
pld 10,z3@got@dtprel@pcrel
|
|
add 10,10,3
|
|
|
|
#All of the above using the same symbol
|
|
addis 3,2,.Ld@toc@ha
|
|
addi 3,3,.Ld@toc@l
|
|
bl __tls_get_addr(.Ld@tlsld)
|
|
nop
|
|
.section .toc,"aw",@progbits
|
|
.p2align 3
|
|
.Ld:
|
|
.quad d@dtpmod
|
|
.quad 0
|
|
.text
|
|
addis 3,2,d@got@tlsld@ha
|
|
addi 3,3,d@got@tlsld@l
|
|
bl __tls_get_addr(d@tlsld)
|
|
nop
|
|
pla 3,d@got@tlsld@pcrel
|
|
bl __tls_get_addr@notoc(d@tlsld)
|