LoongArch: handle a local IFUNC referenced only from a non-alloc section
Fixes LoongArch linker to correctly handle local IFUNC symbols referenced from non-allocatable sections.
This patch resolves an issue in the LoongArch linker where local STT_GNU_IFUNC symbols referenced solely from non-allocatable sections were causing link failures. Because the relocation scan bypasses these sections, loongarch_elf_relocate_section would not find an entry and abort. The fix aligns the behavior with global IFUNCs, relocating the symbol against itself (as STT_FUNC) when no hash entry is found, thereby preventing the abort. New test cases are included.
In Details
This patch addresses a specific problem in the LoongArch linker's handling of STT_GNU_IFUNC symbols, particularly when they are local to an object file and only referenced from non-allocatable sections (e.g., .debug_info). The linker's standard relocation scan skips non-SEC_ALLOC sections. If an IFUNC symbol's only reference comes from such a section, the linker's loongarch_elf_relocate_section function fails to find a corresponding entry in its internal structures and aborts. This patch modifies the function to handle this scenario gracefully by treating the IFUNC as a regular fu…
- LoongArch
- A RISC-ISA architecture developed in China.
- STT_GNU_IFUNC
- A symbol type in the ELF format that represents an Indirect Function. IFUNCs allow for dynamic selection of function implementations at runtime, typically based on processor capabilities.
- Non-alloc section
- A section in an object file that is not loaded into memory when the program runs (e.g., debugging information sections). Marked by
SEC_ALLOCflag being unset. - Relocation scan
- The process by which the linker identifies and processes relocation entries in an object file to resolve symbolic addresses.
- STT_FUNC
- A symbol type in ELF representing a function.
- SEC_ALLOC
- A flag in BFD that indicates whether a section should be allocated memory when the program is loaded.