bfd: local IFUNC symbols referenced only from non-alloc sections
Fixes binutils linker to correctly handle local IFUNC symbols referenced only from non-alloc sections across multiple architectures.
This patch series addresses a bug in the binutils linker (PR ld/34988) where local STT_GNU_IFUNC symbols fail to link when their only references come from non-allocatable sections. The linker’s relocation scan intentionally skips these sections, preventing the necessary hash entry creation. The series introduces a common BFD helper function for handling these cases and then applies this logic to x86, AArch64, RISC-V, and SPARC. This ensures consistent behavior, mirroring how global IFUNC symbols are handled, and provides appropriate error messages when resolution is not possible.
- proposer
Proposes a series of patches to fix the binutils linker's handling of local IFUNC symbols referenced only from non-alloc sections, by introducing a common helper function and applying it to multiple architectures.
“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 thi…”
In Details
This series tackles a linker bug (PR ld/34988) where local IFUNC symbols are not linked correctly if their sole references reside in non-allocatable sections (e.g., debug info). The linker's standard relocation scan omits these sections, causing a lack of necessary symbol information. The solution involves creating a unified BFD helper (_bfd_elf_ifunc_nonalloc_reloc) to manage these IFUNCs, then applying this logic to specific architectures like x86 and AArch64. This brings their behavior in line with global IFUNCs, ensuring either successful linking, a skipped relocation, or a diagnostic e…
- STT_GNU_IFUNC
- A symbol type in the ELF format that represents an indirect function. The linker and dynamic loader resolve this symbol to a specific function pointer at runtime, allowing for architecture-specific or version-specific function implementations.
- non-alloc section
- An ELF section that is not loaded into memory when the program is executed. These sections are often used for debugging information, notes, or other metadata.
- relocation scan
- The process by which the linker identifies and resolves references between different parts of an executable or library. This involves examining relocation entries in object files.
- hash entry
- A data structure within an ELF file that helps speed up symbol lookups, particularly for dynamic linking. For IFUNC symbols, a hash entry is important for runtime resolution.
- IFUNC
- Indirect Function. Similar to STT_GNU_IFUNC, it's a mechanism to select a function implementation at runtime based on certain criteria.
- DWARF
- A debugging data format used by many compilers and debuggers. It stores information about variables, types, and source code locations.