binutils Newspaper
OCTOBER 6, 2026
risc-v — Proposed

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

A patch adds new RISC-V relocation types to support efficient global array access with non-constant indices.

Liqin Weng’s patch introduces new RISC-V relocation types (R_RISCV_BASE_IDX_*) to facilitate more efficient code generation for global array accesses where the array subscript is not a constant. The changes span BFD, gas, and ld, including new relocation definitions and support for internal relaxed relocation types. Jiawei reviewed the patch, approving it with minor requests for header declarations, TODO removal, and GNU comment formatting.

In the Thread 2 participants
  1. Liqin Weng <liqin.weng@spacemit.com> proposer

    Submits a patch introducing new RISC-V relocation types for efficient global array access with non-constant indices.

  2. Jiawei <jiawei@iscas.ac.cn> reviewer

    Approves the patch overall but requests the addition of a function declaration to elfxx-riscv.h and minor cleanup of TODOs and comment formatting.

Technical Tradeoffs

  • Enables more efficient code generation for a specific access pattern at the cost of introducing new relocation types and complexity in the toolchain.
  • Requires careful management of internal vs. emitted relocation types and adherence to ABI specifications.

In Details

This patch enhances the RISC-V backend in binutils by introducing new relocation types. These are designed to optimize how the compiler handles accesses to global arrays when the index is determined at runtime rather than compile time. This involves changes to how relocations are represented and processed, particularly concerning relaxation and the mapping of internal to emitted relocation types.

Filed Under: binutilsrisc-vrelocationscompiler