[binutils-gdb/binutils-2_42-branch] Backport commits 969f5c0e1 (LoongArch: gas: Add support for s9 register) and a0aa6f4ab (LoongArch: l

Nick Clifton nickc@sourceware.org
Fri Jan 26 10:51:59 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3988bf614f9f8761f51a5c7922977a60cb8402ff

commit 3988bf614f9f8761f51a5c7922977a60cb8402ff
Author: mengqinggang <mengqinggang@loongson.cn>
Date:   Fri Jan 26 10:50:57 2024 +0000

    Backport commits 969f5c0e1 (LoongArch: gas: Add support for s9 register) and a0aa6f4ab (LoongArch: ld: Add support for TLS LE symbol with addend) to 2.42 branch.

Diff:
---
 bfd/elfnn-loongarch.c                              |  5 ++---
 gas/config/tc-loongarch.c                          |  7 +++++--
 gas/testsuite/gas/loongarch/loongarch.exp          |  1 +
 gas/testsuite/gas/loongarch/reg-s9.l               |  1 +
 gas/testsuite/gas/loongarch/reg-s9.s               |  2 ++
 include/opcode/loongarch.h                         |  1 +
 ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp |  1 +
 ld/testsuite/ld-loongarch-elf/tls-le.d             | 14 ++++++++++++++
 ld/testsuite/ld-loongarch-elf/tls-le.s             | 18 ++++++++++++++++++
 opcodes/loongarch-opc.c                            |  9 +++++++++
 10 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 64ccc559952..4035ea2fa65 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -3496,14 +3496,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:
@@ -3684,6 +3682,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;
 
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index e6a9901673f..e0aff36bbbb 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -316,8 +316,11 @@ loongarch_after_parse_args ()
   /* Init ilp32/lp64 registers alias.  */
   r_abi_names = loongarch_r_alias;
   for (i = 0; i < ARRAY_SIZE (loongarch_r_alias); i++)
-    str_hash_insert (r_htab, loongarch_r_alias[i], (void *) (i + 1),
-	0);
+    str_hash_insert (r_htab, loongarch_r_alias[i], (void *) (i + 1), 0);
+
+  for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_1); i++)
+    str_hash_insert (r_htab, loongarch_r_alias_1[i], (void *) (i + 1), 0);
+
   for (i = 0; i < ARRAY_SIZE (loongarch_r_alias_deprecated); i++)
     str_hash_insert (r_deprecated_htab, loongarch_r_alias_deprecated[i],
 	(void *) (i + 1), 0);
diff --git a/gas/testsuite/gas/loongarch/loongarch.exp b/gas/testsuite/gas/loongarch/loongarch.exp
index 9ece4e810ff..422b858917e 100644
--- a/gas/testsuite/gas/loongarch/loongarch.exp
+++ b/gas/testsuite/gas/loongarch/loongarch.exp
@@ -31,4 +31,5 @@ if [istarget loongarch*-*-*] {
     }
 
   run_list_test "align"
+  run_list_test "reg-s9"
 }
diff --git a/gas/testsuite/gas/loongarch/reg-s9.l b/gas/testsuite/gas/loongarch/reg-s9.l
new file mode 100644
index 00000000000..8ea739b7641
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/reg-s9.l
@@ -0,0 +1 @@
+# No warning or error expected.
diff --git a/gas/testsuite/gas/loongarch/reg-s9.s b/gas/testsuite/gas/loongarch/reg-s9.s
new file mode 100644
index 00000000000..74f40481ff2
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/reg-s9.s
@@ -0,0 +1,2 @@
+# Add support for $s9 register
+addi.d $t0, $s9, 0
diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h
index 17de85c38b0..251daf13943 100644
--- a/include/opcode/loongarch.h
+++ b/include/opcode/loongarch.h
@@ -196,6 +196,7 @@ dec2 : [1-9][0-9]?
 
   extern const char *const loongarch_r_normal_name[32];
   extern const char *const loongarch_r_alias[32];
+  extern const char *const loongarch_r_alias_1[32];
   extern const char *const loongarch_r_alias_deprecated[32];
   extern const char *const loongarch_f_normal_name[32];
   extern const char *const loongarch_f_alias[32];
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index 1b5994c7d84..3ae0d9df3b4 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -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
index 00000000000..cbd6adb8b41
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/tls-le.d
@@ -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
index 00000000000..2e6a9de42ac
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/tls-le.s
@@ -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
diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c
index 490c689259c..6bd436fa1fe 100644
--- a/opcodes/loongarch-opc.c
+++ b/opcodes/loongarch-opc.c
@@ -49,6 +49,15 @@ const char *const loongarch_r_alias[32] =
   "$s1",   "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8",
 };
 
+/* Add support for $s9.  */
+const char *const loongarch_r_alias_1[32] =
+{
+  "", "", "", "", "", "", "", "",
+  "", "", "", "", "", "", "", "",
+  "", "", "", "", "", "", "$s9", "",
+  "", "", "", "", "", "", "", "",
+};
+
 const char *const loongarch_r_alias_deprecated[32] =
 {
   "", "", "", "", "$v0", "$v1", "", "", "", "", "", "", "", "", "", "",


More information about the Binutils-cvs mailing list