x86: relocate IFUNC references from non-alloc sections as STT_FUNC
Fixes binutils to correctly relocate IFUNC references from non-alloc sections on x86.
This patch addresses an issue in binutils for x86 architectures (i386 and x86_64) where IFUNC references from non-allocatable sections are not correctly relocated. The relocation scan skips these sections, causing the linker to abort or misinterpret references, especially from debug sections. The fix treats these references as STT_FUNC, resolving the problem reported in PR ld/34988 and demonstrated with a GCC example.
- proposer
Proposes relocating IFUNC references from non-alloc sections as STT_FUNC to fix a bug where relocation scans skip these sections.
“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.”
In Details
This patch series applies to the x86 (both 32-bit i386 and 64-bit x86_64) architectures in Binutils. It resolves a bug (PR ld/34988) where STT_GNU_IFUNC symbols referenced from non-allocatable sections (like .debug_info) are not properly relocated by elf_i386_relocate_section and elf_x86_64_relocate_section. The linker skips these sections, leading to relocation failures. The fix ensures these references are handled as STT_FUNC, pointing to the IFUNC resolver.
- STT_GNU_IFUNC
- A symbol type in the ELF format used for Indirect Functions, allowing dynamic selection of function implementations at runtime.
- non-alloc section
- A section in an ELF object file that is not loaded into memory when the program is executed. Examples include debugging information sections.
- relocation
- The process by which a linker or dynamic loader resolves symbolic references and updates addresses in an object file or executable to their final locations in memory.
- STT_FUNC
- A symbol type in the ELF format representing a function.
- PR ld/34988
- A bug report filed against the GNU linker (ld) concerning the handling of IFUNC references in non-alloc sections.