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

RISC-V: Specifies cmodel in option default specs.

The RISC-V GCC port now explicitly specifies the default code model in `OPTION_DEFAULT_SPECS` for improved multilib support.

The RISC-V GCC port now specifies the default code model (cmodel) directly within OPTION_DEFAULT_SPECS. While TARGET_DEFAULT_CMODEL generally sets the default, this explicit specification is necessary to correctly handle multilib configurations. This ensures that the compiler accurately detects and applies the appropriate code model for different multilib targets, improving the reliability of RISC-V binaries built with GCC.

In Details

In GCC, a 'code model' (cmodel) dictates how code and data are accessed, influencing the generated assembly and linker expectations. For RISC-V, this determines addressability ranges and instruction sequences. While TARGET_DEFAULT_CMODEL provides a general default, it is insufficient for multilib environments where a single GCC installation can target multiple ABI variants. OPTION_DEFAULT_SPECS in config/riscv/riscv.h is a mechanism to embed default compiler options that are applied during the compilation process, resolving ambiguities in multilib scenarios where TARGET_DEFAULT_CMODEL

For Context

When a compiler turns your C/C++ code into machine instructions, it needs to know how the program will access memory and variables. This is determined by something called a 'code model.' For the RISC-V processor, there are different code models depending on how large your program is and how far away its data might be in memory. GCC, the compiler, usually has a default way of picking this. However, if you're building programs for multiple different RISC-V configurations at once (called 'multilib'), the old default mechanism could get confused. This update explicitly tells the compiler which code model to use by default in a way that works correctly even for these complex multilib setups. This ensures that the generated programs for RISC-V always use the correct memory access strategies.

Filed Under: risc-vmultilibcompiler-options