RISC-V: Error handling for subset parsing
When parsing RISC-V architecture subsets, keep the previous ISA state upon parsing failures, instead of partially updating the subset list.
This patch improves error handling when parsing RISC-V architecture subsets (-march and .option arch). If parsing fails, the previous ISA state is kept, preventing partially updated subset lists. The change ensures that conflicting extensions are not unexpectedly enabled due to parsing errors.
- proposer
Agrees with the temporary-subset approach in ``riscv_update_subset()``, noting that keeping the previous ISA state is safer for ``.option arch`` and ``.attribute`` parsing failures.
“The temporary-subset approach in riscv_update_subset() looks right to me. For .option arch and .attribute parsing failures, keeping the previous ISA state is safer than leaving the current subset list partially updated.”
In Details
The RISC-V backend parses architecture strings (e.g. from -march) to determine enabled extensions. This patch ensures that errors during parsing of these strings do not lead to a corrupted state, where partially parsed extensions are enabled. Specifically, it modifies riscv_update_subset in bfd/elfxx-riscv.c to use a temporary subset during parsing, reverting to the original state on error.
For Context
When compiling code for RISC-V, the compiler needs to know which extensions the target processor supports (e.g., compressed instructions, floating-point, etc.). This is specified via the architecture string (the -march option). This patch ensures that if the compiler fails to understand the architecture string, it doesn't end up in a broken state where it incorrectly assumes certain extensions are available.