RISC-V: reject unclosed ULEB128 relocation pairs
Enforces RISC-V psABI by rejecting linker inputs with unclosed R_RISCV_SET_ULEB128 relocations.
This patch enforces the RISC-V psABI requirement that R_RISCV_SET_ULEB128 relocations must be paired with R_RISCV_SUB_ULEB128 relocations at the same offset. Previously, unclosed SET relocations at the end of a section were silently ignored. The change adds a check after the relocation loop to detect and report an error if a SET relocation remains open, ensuring ABI compliance.
- proposer
Adds a check to detect and reject trailing, unclosed R_RISCV_SET_ULEB128 relocations in RISC-V object files to comply with the psABI.
“The RISC-V psABI requires each R_RISCV_SET_ULEB128 relocation to pair with an R_RISCV_SUB_ULEB128 relocation at the same offset. Previously, the linker silently ignored an unclosed SET relocation at section end. Check whether a SET relocation remains open after the relocation loop completes. If uleb128_set_rel is non-NULL, report an error to enforce psABI pairing rules.”
In Details
This patch enforces a specific pairing rule from the RISC-V psABI concerning ULEB128 encoded relocations. It modifies riscv_elf_relocate_section to detect and error out on R_RISCV_SET_ULEB128 relocations that do not have a corresponding R_RISCV_SUB_ULEB128 at the same location, preventing silent failures where the linker would previously ignore such unmatched relocations.
- psABI
- The Application Binary Interface for the specific architecture and operating system. For RISC-V, it defines conventions for how software is compiled and linked.
- R_RISCV_SET_ULEB128
- A RISC-V relocation type used in conjunction with R_RISCV_SUB_ULEB128 to encode variable-length unsigned integers.
- R_RISCV_SUB_ULEB128
- A RISC-V relocation type used in conjunction with R_RISCV_SET_ULEB128 to encode variable-length unsigned integers.
- ULEB128
- Unsigned LEB128 (Little-Endian Base 128) is a variable-length encoding format for integers, commonly used in DWARF debugging information and some ABIs.