[PATCH 0/7] bfd: local IFUNC symbols referenced only from non-alloc sections
Harshit Kumar
harshit7kr@gmail.com
Wed Nov 11 11:03:43 GMT 2026
A local STT_GNU_IFUNC symbol gets its hash entry (on s390, its PLT slot)
from the relocation scan, which skips non-SEC_ALLOC sections. When only
such a section refers to the symbol, relocate_section aborts on i386,
x86-64, AArch64, RISC-V, SPARC and LoongArch, and s390 fails the link
with no diagnostic or uses an unallocated PLT slot. A global symbol in
the same place links. "gcc -g -O2" hits this through call-site DWARF;
patch 2 has a five-line reproducer. This is PR ld/34988:
https://sourceware.org/bugzilla/show_bug.cgi?id=34988
The scan skips these sections on purpose since c4b126b87a (PR ld/26080),
so creating the entry or scanning them again is not the fix. For a
global symbol, x86 treats the symbol as STT_FUNC in a non-alloc SHT_NOTE
section (347a87745e, PR ld/22929) and leaves the relocation unapplied in
a debugging section, which ld.so never processes (97dc35c88d and
0eace2105d, PR ld/18808); AArch64, RISC-V and SPARC do the same. The
series applies that rule to the local symbol:
1 _bfd_elf_ifunc_nonalloc_reloc: the rule, in one place. The
global-symbol copies are left as they are, to keep this a fix.
2-5 x86, AArch64, RISC-V and SPARC use it. In other non-alloc
sections they report their existing errors (x86: the one GOT,
PLT and TLS relocations get there since 471130b39c,
PR ld/34444). x86 and RISC-V also aborted there for a global
symbol; 2 and 4 give it the same error. SPARC's error printed
"(null)" for a local symbol; 5 fixes that.
6-7 LoongArch and s390 relocate a global IFUNC symbol without a PLT
entry as STT_FUNC in any non-alloc section, so they do the same
for the local one and do not need the helper.
The abort () stays for SEC_ALLOC sections, which always go through the
scan.
Each backend patch adds .debug_info and SHT_NOTE tests; 2-5 also test a
plain non-alloc section, and 2 and 4 the global symbol there. make
check-ld on base 49465fb034a8, with and without the series:
x86_64-pc-linux-gnu native (3331 -> 3339 expected passes) and aarch64,
riscv64, sparc64 and loongarch64 linux-gnu crosses, plus s390x-linux-gnu
on master. Only the new tests change, all passing. The series applies
unchanged to master 2de4446d9090. Each patch builds with
--enable-targets=all on top of the earlier ones; 6 and 7 also build
alone.
Patches 2-5 need patch 1; the rest are independent. The series is also
independent of a separate series on GOT and TLS relocations in sections
the scan skips; the two apply in either order.
The other IFUNC backends need no change: arm, PowerPC, alpha, arc, csky
and hppa link the local case like the global one; nds32, tic6x and
mn10300, which have no IFUNC support, link it too; the MIPS and KVX
assemblers reject the symbol type.
Harshit Kumar (7):
bfd: add _bfd_elf_ifunc_nonalloc_reloc
x86: handle a local IFUNC referenced only from a non-alloc section
aarch64: handle a local IFUNC referenced only from a non-alloc section
riscv: handle a local IFUNC referenced only from a non-alloc section
sparc: handle a local IFUNC referenced only from a non-alloc section
LoongArch: handle a local IFUNC referenced only from a non-alloc
section
s390: handle a local IFUNC referenced only from a non-alloc section
bfd/elf-bfd.h | 11 ++++++
bfd/elf32-i386.c | 27 +++++++++++---
bfd/elf32-s390.c | 20 +++++++++-
bfd/elf64-s390.c | 20 +++++++++-
bfd/elf64-x86-64.c | 27 +++++++++++---
bfd/elflink.c | 20 ++++++++++
bfd/elfnn-aarch64.c | 33 ++++++++++++++---
bfd/elfnn-loongarch.c | 18 ++++++---
bfd/elfnn-riscv.c | 34 ++++++++++++++---
bfd/elfxx-sparc.c | 37 ++++++++++++++++---
ld/testsuite/ld-aarch64/aarch64-elf.exp | 3 ++
ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d | 7 ++++
ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s | 11 ++++++
.../ld-aarch64/ifunc-plain-nonalloc.d | 3 ++
.../ld-aarch64/ifunc-plain-nonalloc.s | 11 ++++++
ld/testsuite/ld-aarch64/ifunc-skip-nonalloc.d | 7 ++++
ld/testsuite/ld-aarch64/ifunc-skip-nonalloc.s | 11 ++++++
ld/testsuite/ld-i386/i386.exp | 4 ++
.../ld-i386/ifunc-global-plain-nonalloc.d | 4 ++
.../ld-i386/ifunc-global-plain-nonalloc.s | 12 ++++++
ld/testsuite/ld-i386/ifunc-note-nonalloc.d | 8 ++++
ld/testsuite/ld-i386/ifunc-note-nonalloc.s | 11 ++++++
ld/testsuite/ld-i386/ifunc-plain-nonalloc.d | 4 ++
ld/testsuite/ld-i386/ifunc-plain-nonalloc.s | 11 ++++++
ld/testsuite/ld-i386/ifunc-skip-nonalloc.d | 8 ++++
ld/testsuite/ld-i386/ifunc-skip-nonalloc.s | 11 ++++++
.../ld-loongarch-elf/ifunc-note-nonalloc.d | 7 ++++
.../ld-loongarch-elf/ifunc-note-nonalloc.s | 11 ++++++
.../ld-loongarch-elf/ifunc-skip-nonalloc.d | 7 ++++
.../ld-loongarch-elf/ifunc-skip-nonalloc.s | 11 ++++++
.../ld-loongarch-elf/ld-loongarch-elf.exp | 2 +
.../ifunc-global-plain-nonalloc.d | 3 ++
.../ifunc-global-plain-nonalloc.s | 12 ++++++
.../ld-riscv-elf/ifunc-note-nonalloc.d | 7 ++++
.../ld-riscv-elf/ifunc-note-nonalloc.s | 11 ++++++
.../ld-riscv-elf/ifunc-plain-nonalloc.d | 3 ++
.../ld-riscv-elf/ifunc-plain-nonalloc.s | 11 ++++++
.../ld-riscv-elf/ifunc-skip-nonalloc.d | 7 ++++
.../ld-riscv-elf/ifunc-skip-nonalloc.s | 11 ++++++
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 4 ++
ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d | 8 ++++
ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s | 11 ++++++
ld/testsuite/ld-s390/ifunc-note-nonalloc.d | 8 ++++
ld/testsuite/ld-s390/ifunc-note-nonalloc.s | 11 ++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d | 8 ++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s | 11 ++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc.d | 8 ++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc.s | 11 ++++++
ld/testsuite/ld-s390/s390.exp | 4 ++
ld/testsuite/ld-sparc/ifunc-note-nonalloc.d | 9 +++++
ld/testsuite/ld-sparc/ifunc-note-nonalloc.s | 13 +++++++
.../ld-sparc/ifunc-plain-nonalloc-data.d | 5 +++
.../ld-sparc/ifunc-plain-nonalloc-data.s | 15 ++++++++
ld/testsuite/ld-sparc/ifunc-plain-nonalloc.d | 5 +++
ld/testsuite/ld-sparc/ifunc-plain-nonalloc.s | 13 +++++++
ld/testsuite/ld-sparc/ifunc-skip-nonalloc.d | 9 +++++
ld/testsuite/ld-sparc/ifunc-skip-nonalloc.s | 13 +++++++
ld/testsuite/ld-sparc/sparc.exp | 7 ++++
.../ld-x86-64/ifunc-global-plain-nonalloc.d | 4 ++
.../ld-x86-64/ifunc-global-plain-nonalloc.s | 12 ++++++
ld/testsuite/ld-x86-64/ifunc-note-nonalloc.d | 8 ++++
ld/testsuite/ld-x86-64/ifunc-note-nonalloc.s | 11 ++++++
ld/testsuite/ld-x86-64/ifunc-plain-nonalloc.d | 4 ++
ld/testsuite/ld-x86-64/ifunc-plain-nonalloc.s | 11 ++++++
ld/testsuite/ld-x86-64/ifunc-skip-nonalloc.d | 8 ++++
ld/testsuite/ld-x86-64/ifunc-skip-nonalloc.s | 11 ++++++
ld/testsuite/ld-x86-64/x86-64.exp | 4 ++
67 files changed, 686 insertions(+), 36 deletions(-)
create mode 100644 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-aarch64/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-aarch64/ifunc-skip-nonalloc.s
create mode 100644 ld/testsuite/ld-i386/ifunc-global-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-i386/ifunc-global-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-i386/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-i386/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-i386/ifunc-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-i386/ifunc-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-i386/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-i386/ifunc-skip-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
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-skip-nonalloc.s
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-global-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-global-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-skip-nonalloc.s
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc.s
create mode 100644 ld/testsuite/ld-sparc/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-sparc/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-sparc/ifunc-plain-nonalloc-data.d
create mode 100644 ld/testsuite/ld-sparc/ifunc-plain-nonalloc-data.s
create mode 100644 ld/testsuite/ld-sparc/ifunc-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-sparc/ifunc-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-sparc/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-sparc/ifunc-skip-nonalloc.s
create mode 100644 ld/testsuite/ld-x86-64/ifunc-global-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-x86-64/ifunc-global-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-x86-64/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-x86-64/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-x86-64/ifunc-plain-nonalloc.d
create mode 100644 ld/testsuite/ld-x86-64/ifunc-plain-nonalloc.s
create mode 100644 ld/testsuite/ld-x86-64/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-x86-64/ifunc-skip-nonalloc.s
base-commit: 2de4446d9090b5773c863ab7bbdd95a5d4f81367
--
2.55.0
More information about the Binutils
mailing list