binutils Newspaper
NOVEMBER 30, 2026
risc-v — Proposed

RISC-V: Use the 2-byte worst case for alignment in norvc code

Adjust RISC-V assembler alignment to account for potential 2-byte shifts from RVC relaxation.

This patch addresses an alignment issue in RISC-V code where the relaxed RVC (RISC-V Compressed) instructions can shift code by up to 2 bytes. This shift can cause incorrect alignment padding, potentially leading to alignment of 4 bytes with no R_RISCV_ALIGN relocation. The change ensures that the assembler considers the 2-byte worst-case scenario when RVC code is present, thereby correcting the alignment padding.

In the Thread 1 participant
  1. Kito Cheng <kito.cheng@sifive.com> proposer

    Proposes to use the 2-byte worst-case alignment for RISC-V norvc code when RVC code is present, to correct for potential shifts caused by RVC relaxation.

In Details

This patch series addresses alignment issues in the RISC-V assembler (gas) related to instruction relaxation. Specifically, it tackles problems arising when RVC (RISC-V Compressed) instructions are relaxed to their non-compressed equivalents, which can shift code by up to two bytes. This shift affects subsequent alignment directives (.balign) in norvc (non-compressed) regions, potentially causing the assembler to reserve too few no-operation (nop) instructions for R_RISCV_ALIGN relocations, or to miss them entirely when a 4-byte alignment is requested. The fix adjusts the alignment ca…

For Context
RVC
RISC-V Compressed. A standard extension to the RISC-V ISA that provides 16-bit compressed instruction encodings for common operations, improving code density.
norvc
Indicates that the assembler should not emit RVC (compressed) instructions for the following code, even if the architecture supports it.
R_RISCV_ALIGN
A relocation type in RISC-V used by the assembler and linker to enforce alignment. It typically pads with no-operation (nop) instructions to meet a specified alignment boundary.
Relaxation
A process during assembly and linking where the assembler or linker can adjust instruction encodings or code addresses to optimize for space or performance. This can change the exact byte offsets of code.
Filed Under: risc-vassembleralignmentrelaxationrvc