aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorXi Ruoyao <xry111@xry111.site>2025-08-06 12:19:22 +0800
committercailulu <cailulu@loongson.cn>2025-08-07 09:21:38 +0800
commit3eede6b04a30243fdc4acece156be95b17c16f83 (patch)
treec0da5f315d3bcf6e91065847c84b4a789d8dd482 /ld
parent081bf6a3a18da20293693bf30617c5736ef270bc (diff)
downloadbinutils-3eede6b04a30243fdc4acece156be95b17c16f83.zip
binutils-3eede6b04a30243fdc4acece156be95b17c16f83.tar.gz
binutils-3eede6b04a30243fdc4acece156be95b17c16f83.tar.bz2
LoongArch: Fix symbol size after relaxation
There's a logic error in loongarch_relax_perform_deletes: when there's not any delete operation of which the start address is strictly smaller than the symbol address, splay_tree_predecessor() will return nullptr and the symbol size will be unchanged even if some bytes of it are removed. Make the logic more complete to fix this issue. Also factor out the symbol size adjustment logic into a function to avoid code bloating. Tested-by: WANG Xuerui <git@xen0n.name> Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp2
-rw-r--r--ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d7
-rw-r--r--ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s8
-rw-r--r--ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d7
-rw-r--r--ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s19
5 files changed, 43 insertions, 0 deletions
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index e23cdc8..a33727f 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -48,6 +48,8 @@ if [istarget "loongarch64-*-*"] {
run_dump_test "relax-after-alignment"
run_dump_test "relax-medium-call"
run_dump_test "relax-medium-call-1"
+ run_dump_test "relax-sym-size-1"
+ run_dump_test "relax-sym-size-2"
run_dump_test "check_got_relax"
}
diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d
new file mode 100644
index 0000000..eec989f
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d
@@ -0,0 +1,7 @@
+#source: relax-sym-size-1.s
+#ld:
+#readelf: -s
+
+#...
+ *[0-9]+: [0-9a-z]+ +8 .* _start
+#...
diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s
new file mode 100644
index 0000000..c70ac71
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s
@@ -0,0 +1,8 @@
+.p2align 2
+bar:
+ nop
+.globl _start
+_start:
+ la.pcrel $a0, bar
+ ret
+.size _start, . - _start
diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d
new file mode 100644
index 0000000..1388099
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d
@@ -0,0 +1,7 @@
+#source: relax-sym-size-2.s
+#ld:
+#readelf: -s
+
+#...
+ *[0-9]+: [0-9a-z]+ +64 .* _start
+#...
diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s
new file mode 100644
index 0000000..e02e16b
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s
@@ -0,0 +1,19 @@
+bar:
+ nop
+.p2align 6
+
+.reloc ., R_LARCH_ALIGN, 60
+.rept 15
+ 1: nop
+.endr
+ la.pcrel $a0, bar
+ ret
+
+.reloc ., R_LARCH_ALIGN, 60
+.rept 15
+ 2: nop
+.endr
+
+.globl _start
+.set _start, 1b
+.size _start, 2b - 1b