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

RISC-V assembler emits alignment relocations after relaxable code when not relaxing

RISC-V assembler now emits R_RISCV_ALIGN relocations even when relaxation is disabled, if relaxable code precedes the alignment directive.

The RISC-V assembler now correctly emits R_RISCV_ALIGN relocations for code sections where relaxation is disabled but preceded by relaxable code. Previously, when relaxation was off, the assembler used fixed NOPs for padding. However, if relaxable instructions altered the code’s layout, the linker might still adjust alignment points. This change ensures that alignment directives are respected by emitting the necessary relocation information, preventing potential alignment issues.

In Details

This patch modifies the RISC-V assembler's behavior for alignment directives (.balign) when relaxation (riscv_opts.relax) is explicitly disabled. In such cases, the assembler typically pads with fixed NOPs. However, if relaxable instructions (like those that can be compressed by RVC) were used earlier in the section, the linker might still shift the section's content. This commit introduces logic to detect if the last instruction was relaxable (last_relax = true) and, if so, emits an R_RISCV_ALIGN relocation even when riscv_opts.relax is false. This ensures the linker is aware of po…

For Context
R_RISCV_ALIGN
A relocation type specific to RISC-V that indicates an alignment requirement for a particular code location. The linker uses this information to ensure the target address meets the specified alignment.
relaxation
In RISC-V, a compiler/assembler optimization where 32-bit instructions can be replaced by equivalent 16-bit compressed instructions (RVC) to reduce code size. This process can alter code addresses, requiring the linker to adjust offsets.
NOP
No Operation. A CPU instruction that does nothing. Used here as padding to meet alignment requirements when relaxation is disabled.
Filed Under: risc-vassembleralignmentrelaxation