binutils Newspaper
OCTOBER 6, 2026
risc-v — Proposed

RISC-V: Add new relocation types for global array accesses with non-constant indices

Introduces new RISC-V relocation types (R_RISCV_BASE_IDX_*) for efficient global array access with non-constant indices.

This patch introduces support for new RISC-V relocation types, specifically R_RISCV_BASE_IDX_LO12, R_RISCV_BASE_IDX_LO12_S, and R_RISCV_BASE_IDX_ADD. These are designed to enable more efficient code generation for accessing global arrays when the array subscripts are not constant, aligning with the RISC-V PSABI specification.

In Details

This patch adds new relocation types to binutils for the RISC-V architecture, aimed at optimizing accesses to global arrays where the index is not a compile-time constant. This involves modifications to BFD (Binary File Descriptor) and GAS (GNU Assembler) to recognize and generate these new relocation types, referred to as R_RISCV_BASE_IDX_*. The goal is to improve performance by allowing the compiler to generate more specialized instructions for such memory accesses.

For Context
RISC-V
An open-standard instruction set architecture based on RISC principles.
relocation types
Information embedded in an object file that tells the linker how to adjust addresses in the code or data when combining different pieces of code or when creating position-independent code.
R_RISCV_BASE_IDX_*
New relocation types specific to RISC-V, designed to handle base-relative indexed accesses to global arrays, particularly when the index is dynamic.
PSABI
Processor Specific Application Binary Interface; defines calling conventions, data layout, and object file formats for a specific architecture and operating system.
BFD
Binary File Descriptor library, a backend for GNU binutils that provides a common interface to various object file formats.
GAS
GNU Assembler, the assembler used by the GNU toolchain.
Filed Under: binutilsrisc-vrelocationcompiler