[PATCH v1 0/5] LoongArch tls le model linker relaxation support.
Jinyang He
hejinyang@loongson.cn
Sat Dec 2 01:55:14 GMT 2023
On 2023-12-01 17:07, changjiachen wrote:
> This is the v1 version of patches to support loongarch linker tls le model relax.
>
> This support does three main things:
>
> 1. Modify LoongArch tls le model assembly instruction sequence.
>
> This change is mainly implemented in gcc. Due to the characteristics
> of st.w instruction in Loongarch and the unique addressing mode of
> tls le model, in order to implement tls le model linker relax, it is
> decided to change the tls le model instruction sequence.
>
> The specific changes are as follows:
>
> example: __thread int a = 1;
>
> old insn sequence:
>
> lu12i.w $r12,%le_hi20_r(a)
> ori $r12,$r12,%le_lo12_r(a)
> add.d $r12,$r12,$r2,%le_add_r(a)
> li.w $r13,$r0,1
> stptr.w $r13,$r12,0
Hi,
It's more complex than I thought as you said it is mainly implemented
in gcc. Now I compile it, in archlinux, by gcc 13.2.1, and insn sequence
like follows,
lu12i.w $r12,%le_hi20(a)
ori $r12,$r12,%le_lo12(a)
addi.w $r13,$r0,1
stx.w $r13,$r12,$r2
It use `stx.w` rather than `st.w` or `stptr.w`. Will the gcc implementation
change this sequence?
>
> new insn sequence:
>
> lu12i.w $r12,%le_hi20_r(a)
> add.d $r12,$r12,$r2,%le_add_r(a)
> li.w $r13,$r0,1
> st.w $r13,$r12,%le_lo12_r(a)
In old sequence, $r12 is the real address of "a". In new sequence, $r12 is
not the real address of "a". How about we use $r12 after this sequence?
> 2. Added LoongArch three relocations related to tls le model relax.
>
> In order to ensure forward compatibility of binutils versions and
> implement tls le model relax, it was decided to add three relocation items.
>
> The relocation items are as follows:
>
> R_LARCH_TLS_LE_HI20_R
> R_LARCH_TLS_LE_LO12_R
> R_LARCH_TLS_LE_ADD_R
>
> 3. Implement Loongarch tls le model relax in ld.
>
> This change will add a loongarch_relax_tls_le function to relax tls le model.
>
> The instructions before and after relax change as follows:
>
> example: __thread int a = 1;
>
> before relax insn:
>
> lu12i.w $t0, 0
> add.d $t0, $t0, $tp
> li.w $t1, 1
> st.w $t1, $t0, 0
>
> after relax insn:
>
> li.w $t1, 1
> st.w $t1, $tp, 0
>
> changjiachen (5):
> LoongArch: bfd: Add support for tls le relax.
> LoongArch: include: Add support for tls le relax.
> LoongArch: opcodes: Add support for tls le relax.
> LoongArch: gas: Add support for tls le relax.
> LoongArch: ld: Add support for tls le relax.
>
> bfd/bfd-in2.h | 4 +
> bfd/elfnn-loongarch.c | 74 +++++++++
> bfd/elfxx-loongarch.c | 50 ++++++
> bfd/libbfd.h | 3 +
> bfd/reloc.c | 6 +
> gas/config/tc-loongarch.c | 12 +-
> gas/testsuite/gas/loongarch/reloc.d | 18 +++
> gas/testsuite/gas/loongarch/reloc.s | 11 ++
> include/elf/loongarch.h | 13 ++
> ld/testsuite/ld-loongarch-elf/old-tls-le.s | 19 +++
> .../relax-bound-check-tls-le.s | 48 ++++++
> .../ld-loongarch-elf/relax-check-tls-le.s | 43 ++++++
> ld/testsuite/ld-loongarch-elf/relax-tls-le.s | 17 ++
> ld/testsuite/ld-loongarch-elf/relax.exp | 146 +++++++++++++++++-
> .../tls-relax-compatible-check-old.s | 39 +++++
> opcodes/loongarch-opc.c | 1 +
> 16 files changed, 501 insertions(+), 3 deletions(-)
> create mode 100644 ld/testsuite/ld-loongarch-elf/old-tls-le.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/relax-tls-le.s
> create mode 100644 ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s
>
More information about the Binutils
mailing list