[PATCH v2 0/6] bfd: local IFUNC symbols referenced only from non-alloc sections

Harshit Kumar harshit7kr@gmail.com
Sat Nov 14 09:38:23 GMT 2026


v1: https://inbox.sourceware.org/binutils/20261111110350.3761956-1-harshit7kr@gmail.com/

Changes since v1:
- As Alan suggested on v1 0/7, an IFUNC reference from any non-alloc
  section is now relocated as against STT_FUNC, for local and global
  symbols, on x86, AArch64, RISC-V and SPARC, the way LoongArch and
  s390 already handle it.  There is no separate SHT_NOTE or debugging
  case and no error for other non-alloc sections.  For global symbols
  this changes what was there before: debugging sections were left
  unrelocated (0, or the bare addend, in .debug_info), and other
  non-alloc sections were rejected or aborted.
- The helper of v1 1/7 is gone: with that rule it has nothing to
  decide.  Jan asked for the existing global-symbol copies to be
  converted to it; they are replaced by the same one-line rule instead.
- s390: elf_s390_local_ifunc_plt_p takes a const bfd (Jan's point on
  1/7).  A local symbol that also has a PLT slot now gets its own
  address in a non-alloc section, as the global one does, instead of
  the slot's (new ifunc-plt-nonalloc tests).
- SPARC: v1 also fixed "(null)" in the "unresolvable ... relocation"
  error for a local symbol.  Now that non-alloc sections are relocated,
  I found no input that still reaches it, so that change is dropped.
- Tests: ifunc-skip-nonalloc is renamed ifunc-debug-nonalloc and
  checks the resolver's address; the plain non-alloc tests now check
  the address instead of an error; new ifunc-global-debug-nonalloc
  tests; -e _start dropped (Jan).
- Test fixes for configurations v1 failed on: the SPARC tests only run
  on GNU OSABI targets (since ff31f2e09d gas rejects IFUNC on
  sparc64-*-solaris*); the AArch64 tests use run_dump_test_lp64
  (ILP32), and the AArch64 and RISC-V dumps accept either byte order
  (aarch64_be, riscv64be).
- Rebased onto master 45054c45d2.

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.  "gcc -g -O2" hits
this through call-site DWARF; patch 1 has a short 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.  A
non-alloc section is not loaded and ld.so never processes it, so the
reference is relocated as against STT_FUNC and gets the resolver's
address, as the global symbol already did in a non-alloc SHT_NOTE
section (347a87745e, PR ld/22929):

  1-4  x86, AArch64, RISC-V and SPARC, for local and global symbols.
  5-6  LoongArch and s390 already 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.  s390 does so for the global
       symbol's R_390_8 to R_390_64 even when it has a PLT slot, and 6
       does the same for the local one.

When the symbol has a PLT entry, LoongArch relocates a non-alloc
reference against the PLT entry, for local and global symbols alike,
where 1-4 and s390 now use the resolver.  Neither is wrong for a
section that is never loaded; I have left LoongArch as it is for its
maintainers to decide.

The abort () stays for SEC_ALLOC sections, which always go through the
scan.  The SEC_DEBUGGING tests in the x86 GOT, PLT and TLS cases that
Alan pointed out are left to the x86 maintainers, as he suggested; no
other target gets them.

Each patch needs its target maintainer's ack: 1 x86, 2 AArch64,
3 RISC-V, 4 SPARC, 5 LoongArch, 6 s390.

One consequence to be aware of: such a relocation is now processed as
for any other symbol, so the diagnostics that apply to any symbol now
apply to an IFUNC symbol too, where a debugging section used to skip
them silently.  Two cases: a field too small for the address now gives
"relocation truncated to fit", and a GOT relocation with no GOT entry
stops with an internal error (x86-64) or with an assertion failure
followed by a segmentation fault (AArch64).  Both already happen on
master for an ordinary function symbol, and both need an unusual or
hand-made object.  A series I am still working on, for GOT and TLS
relocations in sections the scan skips, turns the second into a proper
error for all symbols.  On s390x the local case of such a GOT
relocation is worse on master: it dereferences a NULL .got, or, when
.got exists, uses the -1 offset and writes 8 bytes starting one byte
before the GOT contents.  With 6 it reaches one of the existing
abort () calls instead.

make check-ld on master 5a1c88b169, with and without the series (rerun
with the series on 45054c45d2 for these seven: identical results):
  x86_64-pc-linux-gnu native   3331 -> 3341 expected passes
  aarch64-linux-gnu            1276 -> 1280
  riscv64-linux-gnu            1034 -> 1039
  sparc64-linux-gnu             846 -> 851
  loongarch64-linux-gnu         941 -> 943
  s390x-linux-gnu               875 -> 881
  x86_64-elf                   1354 -> 1364
plus x86-64.exp and i386.exp on x86_64-linux-gnux32 (880 -> 890) and
i686-linux-gnu, aarch64-elf.exp on aarch64_be-linux-gnu, aarch64_be-elf
and aarch64-linux-gnu_ilp32, ld-riscv-elf.exp on riscv64be-elf, and
sparc.exp on sparc64-sun-solaris2.11.  Only the new tests change, all
passing; no existing result changes, including the PR ld/18808 run
test in ld-ifunc.

Each patch builds with --enable-targets=all on top of the earlier
ones, and the patches are independent of each other.

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 (6):
  x86: relocate IFUNC references from non-alloc sections as STT_FUNC
  aarch64: relocate IFUNC references from non-alloc sections as STT_FUNC
  riscv: relocate IFUNC references from non-alloc sections as STT_FUNC
  sparc: relocate IFUNC references from non-alloc sections as STT_FUNC
  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/elf32-i386.c                              | 33 +++++++------
 bfd/elf32-s390.c                              | 34 +++++++++++++-
 bfd/elf64-s390.c                              | 35 +++++++++++++-
 bfd/elf64-x86-64.c                            | 33 +++++++------
 bfd/elfnn-aarch64.c                           | 47 +++++++------------
 bfd/elfnn-loongarch.c                         | 19 ++++++--
 bfd/elfnn-riscv.c                             | 33 +++++++------
 bfd/elfxx-sparc.c                             | 32 +++++++------
 ld/testsuite/ld-aarch64/aarch64-elf.exp       |  4 ++
 .../ld-aarch64/ifunc-debug-nonalloc.d         |  7 +++
 .../ld-aarch64/ifunc-debug-nonalloc.s         | 11 +++++
 .../ld-aarch64/ifunc-global-debug-nonalloc.d  |  7 +++
 .../ld-aarch64/ifunc-global-debug-nonalloc.s  | 13 +++++
 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d |  7 +++
 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s | 11 +++++
 .../ld-aarch64/ifunc-plain-nonalloc.d         |  7 +++
 .../ld-aarch64/ifunc-plain-nonalloc.s         | 11 +++++
 ld/testsuite/ld-i386/i386.exp                 |  5 ++
 ld/testsuite/ld-i386/ifunc-debug-nonalloc.d   |  8 ++++
 ld/testsuite/ld-i386/ifunc-debug-nonalloc.s   | 11 +++++
 .../ld-i386/ifunc-global-debug-nonalloc.d     |  8 ++++
 .../ld-i386/ifunc-global-debug-nonalloc.s     | 13 +++++
 .../ld-i386/ifunc-global-plain-nonalloc.d     |  8 ++++
 .../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   |  8 ++++
 ld/testsuite/ld-i386/ifunc-plain-nonalloc.s   | 11 +++++
 .../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 +
 .../ld-riscv-elf/ifunc-debug-nonalloc.d       |  7 +++
 .../ld-riscv-elf/ifunc-debug-nonalloc.s       | 11 +++++
 .../ifunc-global-debug-nonalloc.d             |  7 +++
 .../ifunc-global-debug-nonalloc.s             | 13 +++++
 .../ifunc-global-plain-nonalloc.d             |  7 +++
 .../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       |  7 +++
 .../ld-riscv-elf/ifunc-plain-nonalloc.s       | 11 +++++
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp    |  5 ++
 .../ld-s390/ifunc-debug-nonalloc-31.d         |  8 ++++
 .../ld-s390/ifunc-debug-nonalloc-31.s         | 11 +++++
 ld/testsuite/ld-s390/ifunc-debug-nonalloc.d   |  8 ++++
 ld/testsuite/ld-s390/ifunc-debug-nonalloc.s   | 11 +++++
 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-plt-nonalloc-31.d  |  8 ++++
 ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s  | 13 +++++
 ld/testsuite/ld-s390/ifunc-plt-nonalloc.d     |  8 ++++
 ld/testsuite/ld-s390/ifunc-plt-nonalloc.s     | 13 +++++
 ld/testsuite/ld-s390/s390.exp                 |  6 +++
 ld/testsuite/ld-sparc/ifunc-debug-nonalloc.d  |  9 ++++
 ld/testsuite/ld-sparc/ifunc-debug-nonalloc.s  | 13 +++++
 .../ld-sparc/ifunc-global-debug-nonalloc.d    |  9 ++++
 .../ld-sparc/ifunc-global-debug-nonalloc.s    | 16 +++++++
 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      |  9 ++++
 .../ld-sparc/ifunc-plain-nonalloc-data.s      | 15 ++++++
 ld/testsuite/ld-sparc/ifunc-plain-nonalloc.d  |  9 ++++
 ld/testsuite/ld-sparc/ifunc-plain-nonalloc.s  | 13 +++++
 ld/testsuite/ld-sparc/sparc.exp               |  9 ++++
 ld/testsuite/ld-x86-64/ifunc-debug-nonalloc.d |  8 ++++
 ld/testsuite/ld-x86-64/ifunc-debug-nonalloc.s | 11 +++++
 .../ld-x86-64/ifunc-global-debug-nonalloc.d   |  8 ++++
 .../ld-x86-64/ifunc-global-debug-nonalloc.s   | 13 +++++
 .../ld-x86-64/ifunc-global-plain-nonalloc.d   |  8 ++++
 .../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 |  8 ++++
 ld/testsuite/ld-x86-64/ifunc-plain-nonalloc.s | 11 +++++
 ld/testsuite/ld-x86-64/x86-64.exp             |  5 ++
 79 files changed, 831 insertions(+), 103 deletions(-)
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s
 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-i386/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-i386/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-i386/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-i386/ifunc-global-debug-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-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
 create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-riscv-elf/ifunc-global-debug-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-s390/ifunc-debug-nonalloc-31.d
 create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.s
 create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-s390/ifunc-debug-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-plt-nonalloc-31.d
 create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s
 create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc.d
 create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc.s
 create mode 100644 ld/testsuite/ld-sparc/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-sparc/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-sparc/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-sparc/ifunc-global-debug-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-x86-64/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-x86-64/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-x86-64/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-x86-64/ifunc-global-debug-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


base-commit: 45054c45d2201cbd49b3fe9a8f21851b8479b480
-- 
2.55.0




More information about the Binutils mailing list