RISC-V: Implement table-jump relaxation via Zcmt extension
RISC-V linker gains Zcmt support for optimizing jumps and calls using jump tables.
The RISC-V linker now supports the Zcmt extension, enabling table-jump relaxation for eligible jumps and calls. This optimization, when enabled, analyzes target groups and constructs profitable jump tables to rewrite selected sites before final alignment. It is opt-in, intended for non-PIC executables with compatible ISA attributes, and considers factors like page alignment and table slot capacity. This change introduces new data structures and logic within BFD and the linker to manage jump table targets and rankings.
In Details
This patch introduces the core implementation for RISC-V table-jump relaxation using the Zcmt extension. It adds data structures (riscv_jvt_key_t, riscv_jvt_slot_t, etc.) and logic to bfd/elfnn-riscv.c to record, rank, and manage jump table targets. A new hash table (riscv_jvt_htab_t) is introduced to store candidate jump table entries, keyed by symbol, addend, and PLT selection. The linker's internal hash table (riscv_elf_link_hash_table) is augmented to track JVT state per link. The relaxation is opt-in, primarily for non-PIC executables, and involves planning profitable tables an…
- RISC-V
- An open-source instruction set architecture (ISA) based on RISC principles. It is designed to be simple, modular, and extensible.
- Zcmt
- A RISC-V extension that supports table-jump relaxation, an optimization technique for indirect branches.
- Table-jump relaxation
- An optimization technique in linkers where indirect jumps or calls are analyzed. If a set of targets can be grouped and efficiently handled by a jump table, the linker rewrites the code to use the table, potentially reducing code size or improving performance.
- PIC
- Position Independent Code. Code that can be executed regardless of where it is loaded into memory. Often used in shared libraries.
- PLT
- Procedure Linkage Table. A table used in dynamically linked executables to resolve symbols at runtime.
- BFD
- Binary File Descriptor library. A library used by GNU Binutils to abstract the details of different object file formats.