Relocate IFUNC references from non-alloc sections as STT_FUNC
Fixes x86 linker to correctly relocate IFUNC symbols from non-alloc sections.
The x86 linker now correctly handles IFUNC (indirect function) symbol references found in non-allocatable sections, such as debugging information. Previously, these references could cause the linker to abort, especially when only such sections referred to an IFUNC symbol. This change ensures that these references are processed as STT_FUNC, allowing the linker to resolve them to the IFUNC’s resolver function and preventing build failures.
In Details
This patch resolves an issue in the x86 ELF linker (elf_i386_relocate_section and elf_x86_64_relocate_section) where references to local STT_GNU_IFUNC symbols, especially those without a hash entry, were not being relocated when found in non-SEC_ALLOC sections. The relocation scan skipped these sections, causing the linker to abort. The fix ensures that such references are treated as STT_FUNC, enabling them to be resolved to the IFUNC resolver address. This addresses PR ld/34988 and corrects behavior for symbols referenced from debugging or NOTE sections, aligning with previous fixes for…
- IFUNC
- Indirect Function. A mechanism in ELF that allows a symbol to resolve to different function implementations at runtime, typically based on architecture or system features. The dynamic linker determines which implementation to use.
- STT_GNU_IFUNC
- The ELF symbol type that denotes an indirect function. This type allows the dynamic linker to perform symbol resolution for IFUNC symbols.
- STT_FUNC
- The ELF symbol type that denotes a function. In this context, it's used as a workaround to ensure that IFUNC references from non-alloc sections are processed by the linker.
- non-alloc section
- An ELF section that is not loaded into memory when the program is executed. Examples include debugging sections (.debug_*) or NOTE sections. The dynamic linker typically ignores these sections.
- relocation
- The process of updating symbol references in object files or executables to their final memory addresses. This is typically performed by the linker or the dynamic loader.