[PATCH v2 5/6] LoongArch: handle a local IFUNC referenced only from a non-alloc section
Harshit Kumar
harshit7kr@gmail.com
Sat Nov 14 09:38:28 GMT 2026
A local STT_GNU_IFUNC symbol gets its hash entry from the relocation
scan, which skips non-SEC_ALLOC sections (PR ld/26080). When only such
a section refers to it, loongarch_elf_relocate_section finds no entry
and aborts. This backend relocates a global STT_GNU_IFUNC symbol
without a PLT entry as STT_FUNC, debugging sections included; do the
same for the local one.
bfd/
PR ld/34988
* elfnn-loongarch.c (loongarch_elf_relocate_section): Handle a
local STT_GNU_IFUNC symbol with no hash entry in a non-SEC_ALLOC
section.
ld/
PR ld/34988
* testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.d: New test.
* testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.s: New file.
* testsuite/ld-loongarch-elf/ifunc-note-nonalloc.d: New test.
* testsuite/ld-loongarch-elf/ifunc-note-nonalloc.s: New file.
* testsuite/ld-loongarch-elf/ld-loongarch-elf.exp: Run them.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elfnn-loongarch.c | 19 ++++++++++++++-----
.../ld-loongarch-elf/ifunc-debug-nonalloc.d | 7 +++++++
.../ld-loongarch-elf/ifunc-debug-nonalloc.s | 11 +++++++++++
.../ld-loongarch-elf/ifunc-note-nonalloc.d | 7 +++++++
.../ld-loongarch-elf/ifunc-note-nonalloc.s | 11 +++++++++++
.../ld-loongarch-elf/ld-loongarch-elf.exp | 2 ++
6 files changed, 52 insertions(+), 5 deletions(-)
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.d
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.s
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.s
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 489a717bce..a873b8ab9f 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -3599,11 +3599,20 @@ loongarch_elf_relocate_section (struct bfd_link_info *info,
h = elfNN_loongarch_get_local_sym_hash (htab, input_bfd, rel,
false);
if (h == NULL)
- abort ();
-
- /* Set STT_GNU_IFUNC symbol value. */
- h->root.u.def.value = sym->st_value;
- h->root.u.def.section = sec;
+ {
+ /* Only a non-alloc section, which the relocation scan
+ skips, refers to the symbol. Relocate it as against
+ STT_FUNC, as for a global STT_GNU_IFUNC symbol
+ without a PLT entry. */
+ if ((input_section->flags & SEC_ALLOC) != 0)
+ abort ();
+ }
+ else
+ {
+ /* Set STT_GNU_IFUNC symbol value. */
+ h->root.u.def.value = sym->st_value;
+ h->root.u.def.section = sec;
+ }
}
defined_local = true;
resolved_local = true;
diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.d b/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.d
new file mode 100644
index 0000000000..8d5ddcdca9
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.d
@@ -0,0 +1,7 @@
+#name: local IFUNC symbol referenced only from a debugging section
+#ld: -Ttext=0x10000
+#objdump: -s -j .debug_info
+#...
+Contents of section .debug_info:
+ 0000 00000100 00000000 +.*
+#pass
diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.s b/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.s
new file mode 100644
index 0000000000..60a76198dd
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/ifunc-debug-nonalloc.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, %function
+resolver:
+ jr $ra
+ .type ifn, %gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ jr $ra
+ .section .debug_info,"",%progbits
+ .dword ifn
diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.d b/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.d
new file mode 100644
index 0000000000..4daa6d4105
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.d
@@ -0,0 +1,7 @@
+#name: local IFUNC symbol referenced only from a non-alloc note section
+#ld: -Ttext=0x10000
+#objdump: -s -j .note.probe
+#...
+Contents of section .note.probe:
+ 0000 00000100 00000000 +.*
+#pass
diff --git a/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.s b/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.s
new file mode 100644
index 0000000000..41f1c52622
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/ifunc-note-nonalloc.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, %function
+resolver:
+ jr $ra
+ .type ifn, %gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ jr $ra
+ .section .note.probe,"",%note
+ .dword ifn
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index b8e335bf77..9d56cbc1b3 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -28,6 +28,8 @@ if [istarget "loongarch64-*-*"] {
run_dump_test "syscall"
run_dump_test "disas-jirl"
run_dump_test "local-ifunc-reloc"
+ run_dump_test "ifunc-debug-nonalloc"
+ run_dump_test "ifunc-note-nonalloc"
run_dump_test "anno-sym"
run_dump_test "reloc-addend"
run_dump_test "pcala64"
--
2.55.0
More information about the Binutils
mailing list