]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: ld: Add support for TLS LE symbol with addend
authormengqinggang <mengqinggang@loongson.cn>
Thu, 25 Jan 2024 01:32:14 +0000 (09:32 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Fri, 26 Jan 2024 08:49:09 +0000 (16:49 +0800)
Add support for TLS LE symbol with addend, such as:
  lu12i.w $t0, %le_hi20(a + 0x8)
  ori   $t0, $t0, %le_lo12(a + 0x8)

bfd/elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
ld/testsuite/ld-loongarch-elf/tls-le.d [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/tls-le.s [new file with mode: 0644]

index b2caa5fc3e1afc8fca7c9c1136a0d90fc7e3cc3a..cf497762b9473e76f343fb5c2af45278150d9b2b 100644 (file)
@@ -3494,14 +3494,12 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
            relocation += rel->r_addend;
 
          RELOCATE_CALC_PC32_HI20 (relocation, pc);
-
          break;
 
        case R_LARCH_TLS_LE_HI20_R:
+         relocation += rel->r_addend;
          relocation -= elf_hash_table (info)->tls_sec->vma;
-
          RELOCATE_TLS_TP32_HI20 (relocation);
-
          break;
 
        case R_LARCH_PCALA_LO12:
@@ -3682,6 +3680,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        case R_LARCH_TLS_LE64_HI12:
          BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec);
 
+         relocation += rel->r_addend;
          relocation -= elf_hash_table (info)->tls_sec->vma;
          break;
 
index 1b5994c7d84ae12523b60ce2e7c6bb6d67f71f12..3ae0d9df3b49399b6adf65c5d07778aa21d42a67 100644 (file)
@@ -34,6 +34,7 @@ if [istarget "loongarch64-*-*"] {
     run_dump_test "local-ifunc-reloc"
     run_dump_test "anno-sym"
     run_dump_test "pcala64"
+    run_dump_test "tls-le"
 }
 
 if [istarget "loongarch32-*-*"] {
diff --git a/ld/testsuite/ld-loongarch-elf/tls-le.d b/ld/testsuite/ld-loongarch-elf/tls-le.d
new file mode 100644 (file)
index 0000000..cbd6adb
--- /dev/null
@@ -0,0 +1,14 @@
+#ld: --no-relax
+#objdump: -d
+
+.*:[    ]+file format .*
+
+
+Disassembly of section .text:
+
+[      ]*00000001200000e8 <_start>:
+[      ]+1200000e8:[   ]+14000004[     ]+lu12i.w[      ]+\$a0, 0
+[      ]+1200000ec:[   ]+03802085[     ]+ori[  ]+\$a1, \$a0, 0x8
+[      ]+1200000f0:[   ]+14000004[     ]+lu12i.w[      ]+\$a0, 0
+[      ]+1200000f4:[   ]+02c02085[     ]+addi.d[       ]+\$a1, \$a0, 8
+[      ]+1200000f8:[   ]+4c000020[     ]+ret
diff --git a/ld/testsuite/ld-loongarch-elf/tls-le.s b/ld/testsuite/ld-loongarch-elf/tls-le.s
new file mode 100644 (file)
index 0000000..2e6a9de
--- /dev/null
@@ -0,0 +1,18 @@
+# Support for TLS LE symbols with addend
+       .text
+       .globl  a
+       .section        .tdata,"awT",@progbits
+       .align  2
+       .type   a, @object
+       .size   a, 4
+a:
+       .word   123
+
+       .text
+       .global _start
+_start:
+       lu12i.w $r4,%le_hi20(a + 0x8)
+       ori     $r5,$r4,%le_lo12(a + 0x8)
+       lu12i.w $r4,%le_hi20_r(a + 0x8)
+       addi.d  $r5,$r4,%le_lo12_r(a + 0x8)
+       jr $ra