RISC-V linker: Structure relax passes for extensibility
RISC-V linker's relax passes are now described by a data structure, improving maintainability and enabling new pass types.
The RISC-V linker previously used a chain of conditional branches to select relax functions and hard-coded the number of passes. This refactoring introduces a riscv_relax_pass structure to describe each pass, including its reloc selector and optional hooks. This change lays the groundwork for adding new relax passes, such as vendor-specific ones or those for Zcmt table jumps, without requiring extensive code modifications.
In Details
The _bfd_riscv_relax_section function previously selected relax passes via a series of if (info->relax_pass == N) branches. The total number of passes was hardcoded in ld/emultempl/riscvelf.em. This commit replaces that imperative control flow with a declarative data structure, riscv_relax_pass, which holds a reloc selector, per-section and end-of-pass hooks, and a flag for disabling target-specific optimizations. bfd_elfNN_riscv_init_relax_passes now builds an array of these structures. This facilitates adding new passes, like those for compressed instructions (Zcmt), without modif…
- relax passes
- Optimization passes in the linker that adjust instruction sequences to use shorter or more efficient forms, often by modifying branch targets or instruction encodings after initial code generation.
- reloc selector
- A function or condition used to determine which specific relocation types or instruction patterns a particular linker pass should operate on.
- hook
- A callback function that can be registered to be executed at a specific point in a process, allowing for customization or extension of behavior. In this context, hooks are used for per-section or end-of-pass actions during relaxation.
- Zcmt
- A specific extension for the RISC-V architecture, likely related to compressed instruction handling or table jumps, which may require dedicated relaxation passes.
- link_info
- A data structure within the linker that holds global information about the linking process, such as the symbols table, output format, and optimization flags.
- bfd_elfNN_riscv_init_relax_passes
- A function responsible for initializing the list of relax passes for RISC-V ELF targets within the BFD library.