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 <mengqinggang@loongson.cn>
Subject: [PATCH] LoongArch: Fix linker generate PLT entry for data symbol
Date: Fri, 22 Dec 2023 16:31:12 +0800 [thread overview]
Message-ID: <20231222083112.1060582-1-mengqinggang@loongson.cn> (raw)
With old "medium" code model, we call a function with a pair of PCALAU12I
and JIRL instructions. Currently the assembler produces something like:
8: 1a00000c pcalau12i $t0, 0
8: R_LARCH_PCALA_HI20 g
c: 4c000181 jirl $ra, $t0, 0
c: R_LARCH_PCALA_LO12 g
Before the linker generates a "PLT entry" for data without any diagnostic.
If "g" is a data symbol, it may load two instructions in the PLT.
For R_LARCH_PCALA_HI20 reloc, linker only generate PLT entry for STT_FUNC and
STT_GNU_IFUNC symbol.
bfd/ChangeLog:
* testsuite/ld-loongarch-elf/libjirl.s: Add function type.
* elfnn-loongarch.c (loongarch_elf_check_relocs): Add function
condition for R_LARCH_PCALA_HI20 reloc.
---
bfd/elfnn-loongarch.c | 6 +++++-
ld/testsuite/ld-loongarch-elf/libjirl.s | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 87eb65ab9f7..7302930ae01 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -762,8 +762,12 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
h->non_got_ref = 1;
break;
+ /* For normal cmodel, pcalau12i + addi.d/w used to data.
+ For first version medium cmodel, pcalau12i + jirl are used to
+ function call, it need to creat PLT entry for STT_FUNC and
+ STT_GNU_IFUNC type symbol. */
case R_LARCH_PCALA_HI20:
- if (h != NULL)
+ if (h != NULL && (STT_FUNC == h->type || STT_GNU_IFUNC == h->type))
{
/* For pcalau12i + jirl. */
h->needs_plt = 1;
diff --git a/ld/testsuite/ld-loongarch-elf/libjirl.s b/ld/testsuite/ld-loongarch-elf/libjirl.s
index 4d963870df0..de028c5a44b 100644
--- a/ld/testsuite/ld-loongarch-elf/libjirl.s
+++ b/ld/testsuite/ld-loongarch-elf/libjirl.s
@@ -1,2 +1,3 @@
+.type func @function
pcalau12i $r12, %pc_hi20(func)
jirl $r1,$r12, %pc_lo12(func)
--
2.36.0
reply other threads:[~2023-12-22 8:31 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=20231222083112.1060582-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).