From: cailulu <cailulu@loongson.cn>
To: binutils@sourceware.org
Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn,
liuzhensong@loongson.cn, mengqinggang@loongson.cn,
xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com,
cailulu <cailulu@loongson.cn>
Subject: [PATCH 1/2] Use 32/64_PCREL to replace a pair of ADD32/64 and SUB32/64.
Date: Fri, 1 Sep 2023 11:09:00 +0800 [thread overview]
Message-ID: <20230901030901.2519730-1-cailulu@loongson.cn> (raw)
Subtraction for labels that require static relocation
usually generates ADD32/64 and SUB32/64.
If subsy of BFD_RELOC_32/64 and PC in same segment,
and disable relax or PC at start of subsy or enable
relax but not in SEC_CODE, we generate 32/64_PCREL
to replace a pair of ADD32/64 and SUB32/64.
---
gas/config/tc-loongarch.c | 22 ++++++++++++----------
gas/config/tc-loongarch.h | 12 ++++++++++--
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index 2e8a259d147..57faffeb14d 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1195,7 +1195,6 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
static int64_t stack_top;
static int last_reloc_is_sop_push_pcrel_1 = 0;
int last_reloc_is_sop_push_pcrel = last_reloc_is_sop_push_pcrel_1;
- segT sub_segment;
last_reloc_is_sop_push_pcrel_1 = 0;
char *buf = fixP->fx_frag->fr_literal + fixP->fx_where;
@@ -1273,16 +1272,19 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
(use md_number_to_chars (buf, 0, fixP->fx_size)). */
case BFD_RELOC_64:
case BFD_RELOC_32:
- if (fixP->fx_r_type == BFD_RELOC_32
- && fixP->fx_addsy && fixP->fx_subsy
- && (sub_segment = S_GET_SEGMENT (fixP->fx_subsy))
- && strcmp (sub_segment->name, ".eh_frame") == 0
- && S_GET_VALUE (fixP->fx_subsy)
- == fixP->fx_frag->fr_address + fixP->fx_where)
+ if (fixP->fx_pcrel)
{
- fixP->fx_r_type = BFD_RELOC_LARCH_32_PCREL;
- fixP->fx_subsy = NULL;
- break;
+ switch (fixP->fx_r_type)
+ {
+ case BFD_RELOC_64:
+ fixP->fx_r_type = BFD_RELOC_LARCH_64_PCREL;
+ break;
+ case BFD_RELOC_32:
+ fixP->fx_r_type = BFD_RELOC_LARCH_32_PCREL;
+ break;
+ default:
+ break;
+ }
}
if (fixP->fx_addsy && fixP->fx_subsy)
diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h
index a9f2a0a17cc..d353f18d0d2 100644
--- a/gas/config/tc-loongarch.h
+++ b/gas/config/tc-loongarch.h
@@ -71,8 +71,16 @@ extern bool loongarch_frag_align_code (int);
relaxation, so do not resolve such expressions in the assembler. */
#define md_allow_local_subtract(l,r,s) 0
-/* Values passed to md_apply_fix don't include symbol values. */
-#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1
+/* If subsy of BFD_RELOC32/64 and PC in same segment, and without relax
+ or PC at start of subsy or with relax but sub_symbol_segment not in
+ SEC_CODE, we generate 32/64_PCREL. */
+#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \
+ (!((BFD_RELOC_32 || BFD_RELOC_64) \
+ &&(!LARCH_opts.relax \
+ || S_GET_VALUE (FIX->fx_subsy) \
+ == FIX->fx_frag->fr_address + FIX->fx_where \
+ || (LARCH_opts.relax \
+ && ((S_GET_SEGMENT (FIX->fx_subsy)->flags & SEC_CODE) == 0)))))
#define TC_VALIDATE_FIX_SUB(FIX, SEG) 1
#define DIFF_EXPR_OK 1
--
2.31.1
next reply other threads:[~2023-09-01 3:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 3:09 cailulu [this message]
2023-09-01 3:09 ` [PATCH 2/2] Add testcase for generation of 32/64_PCREL cailulu
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=20230901030901.2519730-1-cailulu@loongson.cn \
--to=cailulu@loongson.cn \
--cc=binutils@sourceware.org \
--cc=chenglulu@loongson.cn \
--cc=i.swmail@xen0n.name \
--cc=liuzhensong@loongson.cn \
--cc=maskray@google.com \
--cc=mengqinggang@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).