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

Improve error handling for subset parsing

RISC-V ISA extension parsing now uses a transactional approach for error handling, preserving prior state on failure.

The RISC-V ISA extension parsing in Binutils now employs improved error handling, ensuring that if parsing fails, the previous configuration remains intact. This is critical for scenarios like .option arch, ..., where an invalid option should not corrupt the current architectural settings. For -march=, a failed parse now correctly reverts to default extensions. The change introduces a copy-on-write mechanism for architectural state during parsing, preventing partial updates and ensuring consistency.

In Details

Parsing of RISC-V ISA extensions, whether from compiler flags like -march= or assembler directives like .option arch, ..., was previously susceptible to leaving the architectural state in an inconsistent or partially updated condition if an error occurred during parsing. This commit refines the error handling within the riscv_update_subset() function in bfd/elfxx-riscv.c and gas/config/tc-riscv.c. It now uses a transactional approach: a new riscv_parse_subset_t structure is created, and if the parsing using riscv_update_subset1() fails, the changes are discarded, preserving the…

For Context

When you write code for a RISC-V processor, you sometimes specify precisely which features (called 'ISA extensions') your code uses, either through compiler settings (-march=) or special instructions in the assembly file (.option arch, ...). Before this change, if there was a mistake in how you specified these features, the tools (Binutils) might end up in a confused state, potentially using an incorrect set of features or even crashing. This commit improves error handling by making the parsing process 'all or nothing.' If there's an error, the tools effectively roll back to the last known good configuration, like an 'undo' button. This makes the tools more robust; if you make a mistake, they'll simply tell you about it without getting corrupted or using the wrong RISC-V features for the rest of your program. It also makes a small internal adjustment to how certain related features are checked for consistency.

Filed Under: risc-verror-handlingparserrobustness