public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] LoongArch: Disable linker relaxation if set the address of section or segment
@ 2024-06-04 11:48 liu & zhensong
  0 siblings, 0 replies; only message in thread
From: liu & zhensong @ 2024-06-04 11:48 UTC (permalink / raw)
  To: binutils-cvs

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

commit 07284e5ee02c51f3df2ea8fe2370ca3d1d42d84d
Author: mengqinggang <mengqinggang@loongson.cn>
Date:   Thu May 30 19:52:34 2024 +0800

    LoongArch: Disable linker relaxation if set the address of section or segment
    
    If set the address of section or segment, the offset from pc to symbol
    may become bigger and cause overflow.

Diff:
---
 ld/emultempl/loongarchelf.em                | 16 ++++++++++++++++
 ld/testsuite/ld-loongarch-elf/relax-ttext.s | 13 +++++++++++++
 ld/testsuite/ld-loongarch-elf/relax.exp     | 12 ++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/ld/emultempl/loongarchelf.em b/ld/emultempl/loongarchelf.em
index 3bb5ddf0db4..2da40582008 100644
--- a/ld/emultempl/loongarchelf.em
+++ b/ld/emultempl/loongarchelf.em
@@ -25,6 +25,22 @@ fragment <<EOF
 #include "elf/loongarch.h"
 #include "elfxx-loongarch.h"
 
+EOF
+
+# Disable linker relaxation if set address of section or segment.
+PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
+    case OPTION_SECTION_START:
+    case OPTION_TTEXT:
+    case OPTION_TBSS:
+    case OPTION_TDATA:
+    case OPTION_TTEXT_SEGMENT:
+    case OPTION_TRODATA_SEGMENT:
+    case OPTION_TLDATA_SEGMENT:
+      link_info.disable_target_specific_optimizations = 2;
+      return false;
+'
+
+fragment <<EOF
 static void
 larch_elf_before_allocation (void)
 {
diff --git a/ld/testsuite/ld-loongarch-elf/relax-ttext.s b/ld/testsuite/ld-loongarch-elf/relax-ttext.s
new file mode 100644
index 00000000000..1bbd85a04bb
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/relax-ttext.s
@@ -0,0 +1,13 @@
+# At relax pass 0, offset is 0x120204000-0x12000bff8=0x1f8008 < 0x200000
+# At relax pass 1, delete 0x7ff8 bytes NOP,
+# offset is 0x120204000-0x120004000=0x200000 >= 0x200000, overflow
+.text
+.align 14 # delete at relax pass 1
+.fill 0x4000
+.align 14 # delete at relax pass 1
+la.local $t2, a # relax to pcaddi at relax pass 0
+
+.section ".text1", "ax"
+  .fill 0x4000
+a:	     # 0x120204000
+  ret
diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp
index 35caa73c11d..4771f1eb429 100644
--- a/ld/testsuite/ld-loongarch-elf/relax.exp
+++ b/ld/testsuite/ld-loongarch-elf/relax.exp
@@ -51,6 +51,18 @@ if [istarget loongarch64-*-*] {
     run_dump_test "relax-align-ignore-start"
     run_partial_linking_align_test
 
+    run_ld_link_tests \
+	[list \
+	    [list \
+		"loongarch relax ttext" \
+		"" "" \
+		"" \
+		{relax-ttext.s} \
+		{} \
+		"relax-ttext" \
+	    ] \
+	]
+
     set testname "loongarch relax .exe build"
     set pre_builds [list \
       [list \

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-04 11:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 11:48 [binutils-gdb] LoongArch: Disable linker relaxation if set the address of section or segment liu & zhensong

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).