RISC-V: Describe relax passes with a pass table
Refactors RISC-V relax passes into a table for better extensibility and maintainability.
This patch refactors the RISC-V relax pass mechanism in binutils to use a pass table instead of hard-coded branches. This change aims to improve extensibility, allowing for easier addition of new relax passes, such as vendor-specific ones or those for Zcmt table jumps. The new structure defines each pass with a reloc selector, optional hooks, and a flag for optimization disabling, while maintaining the existing functionality.
In Details
This patch restructures the RISC-V relaxation passes in binutils' BFD and linker. Previously, _bfd_riscv_relax_section used a chain of branches based on info->relax_pass, and the linker hard-coded the number of passes. This RFC introduces a riscv_relax_pass struct and a pass table managed by bfd_elfNN_riscv_init_relax_passes. Each entry in the table describes a pass (reloc selector, hooks, optimization flag), enabling easier addition of new passes like vendor-specific ones or Zcmt table jumps without modifying the core relax logic.
- Relaxation passes
- In linkers, these are passes that adjust relocation entries after initial linking to optimize code, for example, by shortening branch instructions or handling position-dependent code.
- RISC-V
- An open-standard instruction set architecture based on RISC principles.
- reloc selector
- A function or mechanism that determines which relocation entries are applicable to a particular relaxation pass.
- hooks
- Callback functions that can be invoked at specific points during a process, such as at the end of a pass or after processing a section.
- Zcmt
- Likely refers to a specific extension or feature within the RISC-V architecture, possibly related to control-transfer instructions or memory management.
- BFD
- Binary File Descriptor library, a backend for the GNU toolchain that provides a generic interface to various object file formats.