[PATCH v1 0/4] LoongArch: Add support for TLS Descriptors (TLSDESC)
Lulu Cai
cailulu@loongson.cn
Fri Dec 1 09:04:20 GMT 2023
The LoongArch TLS Descriptors implementation contains several points:
1. The instruction sequences is:
pcalau12i $a0,%desc_pc_hi20(var) #R_LARCH_TLS_DESC_PC_HI20
ld.d $a1,$a0,%desc_ld_pc_lo12(var) #R_LARCH_TLS_DESC_LD_PC_LO12
addi.d $a0,$a0,%desc_add_pc_lo12(var) #R_LARCH_TLS_DESC_ADD_PC_LO12
jirl $ra,$a1,%desc_call(var) #R_LARCH_TLS_DESC_CALL
The linker for each DESC generates a R_LARCH_TLS_DESC64 dynamic relocation,
which relocation is placed at .rela.dyn.
TLSDESC always allocates two GOT slots and one dynamic relocation space to TLSDESC.
2. When using multiple ways to access the same TLS variable, a maximum of 5 GOT
slots are used. For example, using GD, TLSDESC, and IE to access the same TLS
variable,GD always uses the first two of the five GOT, TLSDESC uses the third
and fourth, and IE uses the last.
3. TLSDESC always requires dynamic relocation because of LoongArch does not yet have
a tls type transition. Howerer statically linked programs cannot resolve TLSDESC's
dynamic relocation, so we did a type transition for this case.
DESC -> LE:
pcalau12i $a0,%desc_pc_hi20(var) => lu12i.w $a0,%le_hi20(var)
ld.d $a1,$a0,%desc_ld_pc_lo12(var) => ori $a0,$a0,%le_lo12(var)
addi.d $a0,$a0,%desc_add_pc_lo12(var) => NOP
jirl $ra,$a1,%desc_call(var) => NOP
4. The current code passes the tests of gas ld and glibc.
Lulu Cai (4):
LoongArch: Add new relocs and macro for TLSDESC.
LoongArch: Add support for TLSDESC in ld.
LoongArch: Add transition support for DESC to LE.
LoongArch: Add testsuits for TLSDESC in gas and ld.
bfd/bfd-in2.h | 12 +
bfd/elfnn-loongarch.c | 276 ++++++++++++++++--
bfd/elfxx-loongarch.c | 209 ++++++++++++-
bfd/libbfd.h | 12 +
bfd/reloc.c | 29 ++
gas/config/tc-loongarch.c | 14 +-
gas/testsuite/gas/loongarch/tlsdesc_32.d | 26 ++
gas/testsuite/gas/loongarch/tlsdesc_32.s | 12 +
gas/testsuite/gas/loongarch/tlsdesc_64.d | 26 ++
gas/testsuite/gas/loongarch/tlsdesc_64.s | 12 +
.../gas/loongarch/tlsdesc_large_abs.d | 21 ++
.../gas/loongarch/tlsdesc_large_abs.s | 9 +
.../gas/loongarch/tlsdesc_large_pc.d | 34 +++
.../gas/loongarch/tlsdesc_large_pc.s | 16 +
include/elf/loongarch.h | 22 +-
include/opcode/loongarch.h | 3 +
.../ld-loongarch-elf/ld-loongarch-elf.exp | 16 +
ld/testsuite/ld-loongarch-elf/tls-desc.dd | 74 +++++
ld/testsuite/ld-loongarch-elf/tls-desc.rd | 79 +++++
ld/testsuite/ld-loongarch-elf/tls-desc.s | 102 +++++++
.../ld-loongarch-elf/tls-relax-desc-le.d | 15 +
.../ld-loongarch-elf/tls-relax-desc-le.s | 8 +
opcodes/loongarch-opc.c | 54 ++++
23 files changed, 1054 insertions(+), 27 deletions(-)
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_32.d
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_32.s
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_64.d
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_64.s
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_large_abs.d
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_large_abs.s
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_large_pc.d
create mode 100644 gas/testsuite/gas/loongarch/tlsdesc_large_pc.s
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-desc.dd
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-desc.rd
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-desc.s
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-relax-desc-le.d
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-relax-desc-le.s
--
2.36.0
More information about the Binutils
mailing list