riscv: handle a local IFUNC referenced only from a non-alloc section
Fixes RISC-V linker to correctly handle local IFUNC symbols referenced from non-allocatable sections.
This patch addresses an issue in the RISC-V linker where local STT_GNU_IFUNC symbols referenced only from non-allocatable sections were causing link failures. The relocation scan skips these sections, and riscv_elf_relocate_section would not find an entry and abort. The fix utilizes _bfd_elf_ifunc_nonalloc_reloc for these cases, similar to how global symbols are handled, and reports a defined STT_GNU_IFUNC symbol in an unsupported non-alloc section. New test cases are provided.
In Details
This patch tackles a linking problem on RISC-V concerning local STT_GNU_IFUNC symbols that are only referenced within non-allocatable sections (like .debug_info). The linker's relocation process, which typically skips SEC_ALLOC-free sections, means riscv_elf_relocate_section won't find the necessary information and will abort. This fix applies the generic _bfd_elf_ifunc_nonalloc_reloc handler to these symbols, ensuring they are processed correctly even without a PLT entry. It also aligns the error reporting with that for global symbols in similar unsupported sections. New linker tes…
- RISC-V
- An open-standard instruction set architecture (ISA) based on RISC principles.
- 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
- The process of updating symbolic references in an object file to absolute addresses when linking. Relocations contain information about which parts of the code need to be modified and how.
- _bfd_elf_ifunc_nonalloc_reloc
- A generic BFD helper function for handling relocations of IFUNC symbols located in non-allocatable sections.
- SEC_ALLOC
- A flag in BFD that indicates whether a section should be allocated memory when the program is loaded.