]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Fix wrong relocation handling of symbols defined by PROVIDE
authorLulu Cai <cailulu@loongson.cn>
Fri, 9 Aug 2024 09:40:59 +0000 (17:40 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 26 Aug 2024 09:25:45 +0000 (17:25 +0800)
If the symbol defined by PROVIDE in the link script is not in SECTION,
the symbol is placed in the ABS section. The linker considers that
symbols in the ABS section do not need to calculate PC relative offsets.

Symbols in ABS sections should calculate PC relative offsets normally
based on relocations.

bfd/elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
ld/testsuite/ld-loongarch-elf/provide_abs.d [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/provide_abs.ld [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/provide_noabs.d [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/provide_noabs.ld [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/provide_sym.s [new file with mode: 0644]

index f58ced30ac3037118a68d9282c836251e8ed802f..6de101b35f7b9401663cc9b98921c77f38d28824 100644 (file)
@@ -3313,7 +3313,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
       /* The r_symndx will be STN_UNDEF (zero) only for relocs against symbols
         from removed linkonce sections, or sections discarded by a linker
         script.  Also for R_*_SOP_PUSH_ABSOLUTE and PCREL to specify const.  */
-      if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
+      if (r_symndx == STN_UNDEF)
        {
          defined_local = false;
          resolved_local = false;
index d80014d9563cefe8fb4d9cce2f4e897e9b1ca22a..4328f6e941e58b49497d08f88c1c122df1f70508 100644 (file)
@@ -184,5 +184,8 @@ if [istarget "loongarch64-*-*"] {
   run_dump_test "ie-le-relax"
   run_dump_test "tlsdesc_abs"
   run_dump_test "tlsdesc_extreme"
+  run_dump_test "provide_abs"
+  run_dump_test "provide_noabs"
+
 }
 
diff --git a/ld/testsuite/ld-loongarch-elf/provide_abs.d b/ld/testsuite/ld-loongarch-elf/provide_abs.d
new file mode 100644 (file)
index 0000000..1514fb1
--- /dev/null
@@ -0,0 +1,12 @@
+#source: provide_sym.s
+#as:
+#ld: -T provide_abs.ld
+#objdump: -d
+
+.*: +file format .*
+
+#...
+   0:  58001085        beq             \$a0, \$a1, 16  # 10 <fun1>
+   4:  40000c80        beqz            \$a0, 12        # 10 <fun1>
+   8:  54000800        bl              8       # 10 <fun1>
+#pass
diff --git a/ld/testsuite/ld-loongarch-elf/provide_abs.ld b/ld/testsuite/ld-loongarch-elf/provide_abs.ld
new file mode 100644 (file)
index 0000000..473476c
--- /dev/null
@@ -0,0 +1 @@
+PROVIDE(fun1 = 0x10);
diff --git a/ld/testsuite/ld-loongarch-elf/provide_noabs.d b/ld/testsuite/ld-loongarch-elf/provide_noabs.d
new file mode 100644 (file)
index 0000000..7d6bc4d
--- /dev/null
@@ -0,0 +1,13 @@
+#source: provide_sym.s
+#as:
+#ld: -T provide_noabs.ld
+#objdump: -d
+
+.*: +file format .*
+
+
+#...
+   0:  58001085        beq             \$a0, \$a1, 16  # 10 <fun1>
+   4:  40000c80        beqz            \$a0, 12        # 10 <fun1>
+   8:  54000800        bl              8       # 10 <fun1>
+#pass
diff --git a/ld/testsuite/ld-loongarch-elf/provide_noabs.ld b/ld/testsuite/ld-loongarch-elf/provide_noabs.ld
new file mode 100644 (file)
index 0000000..0154c6f
--- /dev/null
@@ -0,0 +1,7 @@
+SECTIONS
+{
+  .text :
+  {
+    PROVIDE(fun1 = 0x10);
+  }
+}
diff --git a/ld/testsuite/ld-loongarch-elf/provide_sym.s b/ld/testsuite/ld-loongarch-elf/provide_sym.s
new file mode 100644 (file)
index 0000000..6610894
--- /dev/null
@@ -0,0 +1,7 @@
+       .text
+       .globl  main
+       .type   main, @function
+main:
+       beq     $a0,$a1,%b16(fun1)
+       beqz    $a0,%b21(fun1)
+       bl      %b26(fun1)