[PATCH v1 0/5] LoongArch tls le model linker relaxation support.

changjiachen changjiachen@stu.xupt.edu.cn
Fri Dec 1 09:07:25 GMT 2023


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

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)

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

-- 
2.40.0



More information about the Binutils mailing list