binutils Newspaper
NOVEMBER 30, 2026
risc-v — Proposed

RISC-V: Add no-op relax pass 0 to update section VMAs before shortening [PR34979]

Introduces a no-op relaxation pass at the beginning of the RISC-V linker's relaxation process to ensure section VMAs are consistently updated before code short…

This patch addresses a relocation overflow issue on RISC-V (PR ld/34979) caused by inconsistent Virtual Memory Address (VMA) updates during the linker’s relaxation process. When segment headers grow, output section VMAs are updated. If a later section’s VMA is still stale when an earlier section needs to calculate relative offsets, it can lead to incorrect shortening of instructions (e.g., auipc+jalr to jal), causing relocation overflows. The fix adds a no-op ‘layout’ pass as the first relaxation pass (pass 0) to ensure all section VMAs are recalculated consistently before the ‘shorten’ pass, resolving the problem without affecting other targets.

In Details

This patch resolves a specific issue in the RISC-V linker's relaxation mechanism. Relaxation is a multi-pass process where the linker adjusts instruction offsets and lengths to fit within available space, particularly for PC-relative branches and loads. The problem arises in the context of program header manipulation: when elf_program_header_size increases, the linker re-evaluates section VMAs. If this VMA update happens *after* an earlier section has already been processed by the relaxation 'shorten' pass but *before* a later section is processed, the earlier section's VMA might be ahead o…

For Context
RISC-V
An open-standard instruction set architecture (ISA) based on RISC principles.
Relaxation
A linker optimization process where instructions are adjusted (e.g., shortened or lengthened) to fit within specific encoding constraints, often related to PC-relative addressing. This typically involves multiple passes.
VMA
Virtual Memory Address. The address of a location in memory as seen by a program.
Section
A part of an object file or executable that contains code, data, or other information. Examples include .text (code), .data (initialized data), and .bss (uninitialized data).
PC-relative offset
An offset calculated relative to the current value of the Program Counter (PC). This is common for position-independent code.
auipc+jalr
A common instruction pair in RISC-V used to load an immediate value into a register and then perform an indirect jump. This pair can sometimes be shortened to a single jal instruction if the target is within range.
R_RISCV_JAL
A RISC-V relocation type used for jump and link (JAL) instructions, typically for PC-relative jumps.
Program Header
A structure in an ELF file that describes segments, which are mappings of sections into memory during execution.
Filed Under: risc-vlinkerrelocationsVMArelaxation