RISC-V: Add Zcmt table-jump relocation definitions
Adds definitions for RISC-V Zcmt table-jump relocations to binutils.
Jiawei proposes adding linker-internal definitions for RISC-V Zcmt table-jump relocations to binutils. This change introduces new relocation numbers, symbol names, and section names to support this feature. The RFC is intended to move forward with the implementation, with one reviewer noting they have pushed subsequent patches to make progress.
- proposer
Submits RFC v4 to add linker-internal table-jump marker and instruction encoding definitions for RISC-V Zcmt, noting the marker has no public ELF relocation or howto entry.
“Add the linker-internal table-jump marker and instruction encoding definitions. The marker has no public ELF relocation or howto entry.”
- contributor
Provides an update on the patch series, describing the process of recording, planning, and rewriting passes for shortening and alignment, and selecting target groups after complete recording.
“Register recording, planning and rewriting passes between ordinary shortening and alignment. Select profitable residual target groups after complete recording, then size the table before rewriting. Keep optional JVT-base references symbolic until final linking; preserve normal alignment accounting. Consume table-jump markers in the dedicated relocation handler. Use the NONE howto for common disc…”
- reviewer
Notes that subsequent patches in the series have been pushed to facilitate progress on the Zcmt table-jump relocation definitions.
“I pushed this and https://patchwork.sourceware.org/project/binutils/patch/20260924155402.420585-5-jiawei@iscas.ac.cn/ ahead to make some progress here :)”
Technical Tradeoffs
- Adds new symbols and sections, potentially increasing binary size slightly.
- Introduces new relocation types, requiring careful handling by the linker and assembler.
- The complexity of jump table management needs to be balanced against performance gains.
In Details
This RFC introduces support for the RISC-V Zcmt extension's table-jump (JT) mechanism within binutils. It defines new ELF relocation types and internal linker structures (.riscv.jvt section, R_RISCV_TABLE_JUMP reloc) to handle indirect jumps via a jump table. The changes are necessary for optimizing control flow in performance-sensitive code on RISC-V platforms supporting Zcmt.
- RISC-V
- An open standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles.
- Zcmt
- A RISC-V extension that provides instructions for efficient table-based indirect jumps, improving performance for switch statements and virtual method calls.
- Relocation
- Information in an object file that describes how to modify certain byte values (e.g., addresses) when the code or data is combined with other files or loaded into memory.
- ELF
- Executable and Linkable Format, a common file format for object files, executables, and shared libraries on Unix-like systems.
- Linker
- A program that combines object files and libraries into an executable program or another object file. Binutils provides the GNU linker,
ld. - Table-jump
- A control flow technique where a program jumps to a target address stored in a table, often used to implement efficient switch statements or virtual function calls.