[PATCH v2 1/6] x86: relocate IFUNC references from non-alloc sections as STT_FUNC
Jan Beulich
jbeulich@suse.com
Fri Nov 20 13:32:22 GMT 2026
On 14.11.2026 10:38, Harshit Kumar wrote:
> 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, elf_i386_relocate_section and
> elf_x86_64_relocate_section find no entry and abort. "gcc -g -O2"
> produces this: once call () below loses its unused argument, only the
> call-site DWARF still refers to f, and ld 2.47 aborts:
>
> static int impl(void){return 1;}
> static int (*resolve(void))(void){return impl;}
> static int f(void) __attribute__((ifunc("resolve")));
> __attribute__((noinline))
> static int call(int (*p)(void), int x){ return x; }
> int g(int x){ return call(f, x); }
>
> A non-alloc section is not loaded and ld.so never processes it, so
> relocate a reference from any non-alloc section, debugging and note
> sections included, as against STT_FUNC: it gets the address of the
> resolver. This replaces the separate SHT_NOTE (PR ld/22929) and
> SEC_DEBUGGING (PR ld/18808) cases for a global symbol, which left a
> debugging section's field unrelocated (0, or the bare addend, in
> .debug_info) and rejected or aborted on other non-alloc sections.
>
> bfd/
> PR ld/34988
> * elf32-i386.c (elf_i386_relocate_section): Relocate a reference
> from a non-alloc section to an STT_GNU_IFUNC symbol, local without a
> hash entry or defined, as against STT_FUNC.
> * elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
> ld/
> PR ld/34988
> * testsuite/ld-i386/ifunc-debug-nonalloc.d: New test.
> * testsuite/ld-i386/ifunc-debug-nonalloc.s: New file.
> * testsuite/ld-i386/ifunc-global-debug-nonalloc.d: New test.
> * testsuite/ld-i386/ifunc-global-debug-nonalloc.s: New file.
> * testsuite/ld-i386/ifunc-global-plain-nonalloc.d: New test.
> * testsuite/ld-i386/ifunc-global-plain-nonalloc.s: New file.
> * testsuite/ld-i386/ifunc-note-nonalloc.d: New test.
> * testsuite/ld-i386/ifunc-note-nonalloc.s: New file.
> * testsuite/ld-i386/ifunc-plain-nonalloc.d: New test.
> * testsuite/ld-i386/ifunc-plain-nonalloc.s: New file.
> * testsuite/ld-i386/i386.exp: Run them.
> * testsuite/ld-x86-64/ifunc-debug-nonalloc.d: New test.
> * testsuite/ld-x86-64/ifunc-debug-nonalloc.s: New file.
> * testsuite/ld-x86-64/ifunc-global-debug-nonalloc.d: New test.
> * testsuite/ld-x86-64/ifunc-global-debug-nonalloc.s: New file.
> * testsuite/ld-x86-64/ifunc-global-plain-nonalloc.d: New test.
> * testsuite/ld-x86-64/ifunc-global-plain-nonalloc.s: New file.
> * testsuite/ld-x86-64/ifunc-note-nonalloc.d: New test.
> * testsuite/ld-x86-64/ifunc-note-nonalloc.s: New file.
> * testsuite/ld-x86-64/ifunc-plain-nonalloc.d: New test.
> * testsuite/ld-x86-64/ifunc-plain-nonalloc.s: New file.
> * testsuite/ld-x86-64/x86-64.exp: Run them.
>
> Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
Okay.
Jan
More information about the Binutils
mailing list