Relocate IFUNC references from non-alloc sections as STT_FUNC
Fixes riscv linker to correctly relocate IFUNC symbols from non-alloc sections.
The riscv linker can now correctly relocate IFUNC (indirect function) symbol references originating from non-allocatable sections, such as .debug_info. Previously, the linker skipped these sections, causing relocation errors and toolchain aborts when only such sections referred to an IFUNC symbol. This change ensures these references are treated as STT_FUNC, allowing the linker to resolve them to the IFUNC’s resolver function.
In Details
This patch addresses a bug in the RISC-V ELF linker where STT_GNU_IFUNC symbols, particularly local ones without hash entries, were not being relocated correctly when referenced from non-SEC_ALLOC sections (like .debug_info). The existing relocation logic skipped these sections, leading to errors. The fix modifies riscv_elf_relocate_section to treat such references as STT_FUNC, ensuring they are resolved to the IFUNC resolver address, rather than being missed or causing aborts. This harmonizes behavior across different section types and symbol scopes for IFUNC relocation.
- 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.