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

Treat RISC-V R_RISCV_ALIGN as relaxable

Binutils now treats R_RISCV_ALIGN relocations as relaxable for RISC-V, improving linker behavior.

This commit updates the RISC-V assembler in Binutils to treat R_RISCV_ALIGN relocations as relaxable. This change ensures that the linker can correctly handle alignment changes, even in non-relaxable code sections, by allowing the R_RISCV_ALIGN to influence section size adjustments. Previously, the assembler might not have marked these as relaxable, potentially leading to alignment issues when the linker needed to modify section sizes after instructions that were not themselves relaxable.

In Details

This commit modifies the RISC-V backend in Binutils (gas) to mark R_RISCV_ALIGN relocations as relaxable. In gas/config/tc-riscv.c, the riscv_frag_align_code function now sets info->last_relax = true; after emitting an R_RISCV_ALIGN relocation. This is crucial because an R_RISCV_ALIGN can alter the size of a section. Even in contexts where preceding instructions are not relaxable, the linker might need to adjust section boundaries. By marking the alignment as relaxable, the linker is informed that subsequent relaxations might depend on this alignment, ensuring correct behavior f…

For Context
R_RISCV_ALIGN
A relocation type specific to RISC-V that indicates a required alignment for a section or symbol. The linker uses this information to adjust code placement.
relaxable
In the context of linkers and assemblers, 'relaxable' refers to instructions or relocations whose size or position can be adjusted by the linker after initial assembly. This allows for optimizations like instruction compression or better code positioning.
relocation
Information in an object file that tells the linker how to modify addresses in the code or data sections to correctly reference symbols defined elsewhere. Relocation entries specify the type of fix-up needed and the location to apply it.
Filed Under: risc-vbinutilslinkerassembler