binutils Newspaper
JULY 29, 2026
risc-v/gas Ready to Land

RISC-V/gas: .attribute vs .insn

Align RISC-V assembler's .attribute directive handling with .insn instructions.

This patch refactors the RISC-V GNU Assembler (gas) to ensure that directives like .attribute are processed correctly before instructions generated by .insn. A new helper function start_assembly is introduced to manage this initialization logic, ensuring consistency between attribute settings and instruction encoding.

In the Thread 2 participants
  1. Jan Beulich <jbeulich@suse.com> proposer

    Introduces a helper function to ensure .attribute is processed before .insn-generated instructions.

    “"... before any instruction", as the diagnostic from s_riscv_attribute() says, presumably ought to include also insns resulting from .insn. Make a small helper function.”
  2. Jiawei <jiawei@iscas.ac.cn> reviewer

    Provided an RFC comment, questioning the necessity of the `start_assemble` constraint and suggesting it could potentially be relaxed or removed.

Technical Tradeoffs

  • Centralizes initialization logic, improving code clarity and maintainability.
  • Maintains stricter checks for attribute settings, potentially impacting flexibility as noted in the RFC comment.

In Details

This patch addresses the RISC-V assembler's handling of mandatory RISC-V ELF attributes (like architecture and privilege specification) which must be set before any instructions are emitted. It consolidates this setup logic into a start_assembly() helper function, ensuring it's called correctly for both direct assembly and instructions generated via the .insn directive, thus maintaining ABI compliance and correct instruction decoding.

For Context
RISC-V
An open-source instruction set architecture (ISA) that is gaining popularity for its modularity and extensibility.
gas
The GNU Assembler, part of the GNU Binutils package.
.attribute
An assembler directive used to specify object file attributes, such as target architecture or features.
.insn
An assembler directive that allows insertion of raw machine instructions.
ABI
Application Binary Interface. Defines how low-level properties of the "call interface" between two compiled modules or languages are specified.
Filed Under: binutilsrisc-vgasattributeinstruction