binutils Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
risc-v

RISC-V: Add no-op relax pass to update section VMAs before shortening

Introduces a no-op relax pass at the beginning of RISC-V relaxation to ensure section VMAs are consistent before code shortening.

This change adds a no-operation relax pass at the start of the RISC-V linker relaxation process. This ensures that all output section Virtual Memory Addresses (VMAs) are consistently updated before the shortening pass runs. Previously, increases in SIZEOF_HEADERS could cause discrepancies in VMAs between output sections, leading to incorrect PC-relative offset calculations and potential relocation truncated to fit errors for R_RISCV_JAL relocations.

In Details

A discrepancy in Virtual Memory Addresses (VMAs) between output sections in the RISC-V linker, caused by ldelf_map_segments invoking lang_relax_sections after bfd_elf_map_sections_to_segments increases elf_program_header_size, leads to issues in PC-relative relocation shortening. Specifically, _bfd_riscv_relax_call can underestimate offsets and irreversibly shorten auipc+jalr into jal, causing R_RISCV_JAL overflows. By prepending a no-op layout pass (pass 0) in bfd_elfNN_riscv_init_relax_passes, this commit ensures all output section VMAs are recalculated uniformly before th…

For Context
RISC-V
An open-standard instruction set architecture (ISA) based on RISC principles.
VMA
Virtual Memory Address. The address of a memory location as seen by a program, distinct from the physical address in RAM.
Relaxation
A linker optimization process where initially-generated code with fixed-size relocations is analyzed and potentially rewritten to use shorter or different relocation types, especially when code addresses are finalized.
PC-relative offset
An offset calculated relative to the current value of the Program Counter (PC).
R_RISCV_JAL
A RISC-V relocation type used for Jump and Link instructions.
SIZEOF_HEADERS
A linker-internal constant representing the size of the ELF header and program headers.
Filed Under: risc-vlinkerrelocationbugfix