binutils Newspaper
JUNE 15, 2026
risc-v Ready to Land

RISC-V: riscv_set_arch() can fail

Avoid passing NULL pointers to functions when ``riscv_set_arch()`` fails to set architecture string.

This patch fixes a potential crash in riscv_set_arch() when the architecture string is empty. In such cases, the code now avoids passing NULL pointers to subsequent functions by using a default architecture string (DEFAULT_RISCV_ARCH_WITH_EXT). This prevents crashes when the frontend fails to provide a valid architecture string.

In the Thread 1 participant
  1. Jiawei <jiawei@iscas.ac.cn> proposer

    States that the patch prevents NULL pointers from being passed to functions when the architecture string is empty, and also catches cases where the frontend fails to provide the architecture string.

    “So this should still catch cases like a frontend failing to provide the archstring, while avoiding a follow-up crash.”

In Details

The riscv_set_arch() function, located in gas/config/tc-riscv.c, parses the RISC-V architecture string. This patch addresses a scenario where the architecture string is empty, which could lead to NULL pointers being passed to other functions. To avoid this, the code now uses a default architecture string when the input is empty.

For Context

When the assembler processes RISC-V code, it needs to know the target architecture. The riscv_set_arch() function is responsible for setting the architecture based on the input string. This patch fixes a bug where if the architecture string is empty, the assembler could crash. Now, if the string is empty, a default architecture is used.

Filed Under: risc-verror handlingnull pointer