From: mengqinggang <mengqinggang@loongson.cn>
To: binutils@sourceware.org
Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn,
liuzhensong@loongson.cn, cailulu@loongson.cn, xry111@xry111.site,
i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn,
wanglei@loongson.cn, hejinyang@loongson.cn,
mengqinggang@loongson.cn
Subject: [PATCH] LoongArch: ld: Add support for TLS LE symbol with addend
Date: Thu, 25 Jan 2024 19:32:24 +0800 [thread overview]
Message-ID: <20240125113224.2083508-1-mengqinggang@loongson.cn> (raw)
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 | 5 ++---
.../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 ++++++++++++++++++
4 files changed, 35 insertions(+), 3 deletions(-)
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-le.d
create mode 100644 ld/testsuite/ld-loongarch-elf/tls-le.s
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index b2caa5fc3e1..cf497762b94 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -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;
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
--
2.36.0
reply other threads:[~2024-01-25 11:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240125113224.2083508-1-mengqinggang@loongson.cn \
--to=mengqinggang@loongson.cn \
--cc=binutils@sourceware.org \
--cc=cailulu@loongson.cn \
--cc=chenglulu@loongson.cn \
--cc=hejinyang@loongson.cn \
--cc=i.swmail@xen0n.name \
--cc=liuzhensong@loongson.cn \
--cc=luweining@loongson.cn \
--cc=maskray@google.com \
--cc=wanglei@loongson.cn \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).