public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jinyang He <hejinyang@loongson.cn>
To: Chenghua Xu <xuchenghua@loongson.cn>,
	Zhensong Liu <liuzhensong@loongson.cn>,
	mengqinggang <mengqinggang@loongson.cn>
Cc: WANG Xuerui <i.swmail@xen0n.name>, Xi Ruoyao <xry111@xry111.site>,
	binutils@sourceware.org, Jinyang He <hejinyang@loongson.cn>,
	Lulu Cai <cailulu@loongson.cn>
Subject: [PATCH v2] LoongArch: gas: Simplify relocations in sections without code flag
Date: Wed, 17 Apr 2024 15:00:20 +0800	[thread overview]
Message-ID: <20240417070020.9354-1-hejinyang@loongson.cn> (raw)

Gas should not emit ADD/SUB relocation pairs for label differences
if they are in the same section without code flag even relax enabled.
Because the real value is not be affected by relaxation and it can be
compute out in assembly stage. Thus, correct the `TC_FORCE_RELOCATION
_SUB_SAME` and the label differences in same section without code
flag can be resolved in fixup_segment().
---
v2: Improve the commit info.

 gas/config/tc-loongarch.h                      |  4 +---
 gas/testsuite/gas/loongarch/relax_debug_line.d | 11 +++++++++++
 gas/testsuite/gas/loongarch/relax_debug_line.s |  6 ++++++
 3 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 gas/testsuite/gas/loongarch/relax_debug_line.d
 create mode 100644 gas/testsuite/gas/loongarch/relax_debug_line.s

diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h
index e0d0962e5f0..e1ef42c1314 100644
--- a/gas/config/tc-loongarch.h
+++ b/gas/config/tc-loongarch.h
@@ -91,9 +91,7 @@ extern bool loongarch_frag_align_code (int, int);
 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEC)	\
   (LARCH_opts.relax ?  \
     (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC)	\
-      || ((SEC)->flags & SEC_CODE) != 0		\
-      || ((SEC)->flags & SEC_DEBUGGING) != 0	\
-      || TC_FORCE_RELOCATION (FIX)) \
+      || ((SEC)->flags & SEC_CODE) != 0)		\
     : (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC))) \
 
 #define TC_LINKRELAX_FIXUP(seg) ((seg->flags & SEC_CODE)  \
diff --git a/gas/testsuite/gas/loongarch/relax_debug_line.d b/gas/testsuite/gas/loongarch/relax_debug_line.d
new file mode 100644
index 00000000000..0099eb5b79e
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/relax_debug_line.d
@@ -0,0 +1,11 @@
+#as: --gdwarf-5
+#readelf: -r --wide
+
+Relocation section '\.rela\.debug_line' at offset .* contains 5 entries:
+#...
+0+22.*R_LARCH_32[ \t]+[0-9]+.*
+0+2c.*R_LARCH_32[ \t]+[0-9]+.*
+0+36.*R_LARCH_64[ \t]+[0-9]+.*
+0+42.*R_LARCH_ADD16[ \t]+[0-9]+.*
+0+42.*R_LARCH_SUB16[ \t]+[0-9]+.*
+#pass
diff --git a/gas/testsuite/gas/loongarch/relax_debug_line.s b/gas/testsuite/gas/loongarch/relax_debug_line.s
new file mode 100644
index 00000000000..d2852bb91e2
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/relax_debug_line.s
@@ -0,0 +1,6 @@
+  .file 0 "test"
+  .text
+  .loc 0 10 0
+  nop
+
+.section .debug_line, "", @progbits
-- 
2.43.0


                 reply	other threads:[~2024-04-17  7:00 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=20240417070020.9354-1-hejinyang@loongson.cn \
    --to=hejinyang@loongson.cn \
    --cc=binutils@sourceware.org \
    --cc=cailulu@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --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).