Supported GCC Versions
The following GCC versions are available, selectable viamenuconfig:
| Version | Config Symbol | Notes |
|---|---|---|
| GCC 12.x | GCC_USE_VERSION_12 | Older stable branch |
| GCC 13.x | GCC_USE_VERSION_13 | Previous stable branch |
| GCC 14.x | GCC_USE_VERSION_14 | Default |
| GCC 15.x | GCC_USE_VERSION_15 | Latest branch |
14.3.0). To change the GCC version:
GCC Configuration Options
These options are available under Toolchain Options inmenuconfig (requires TOOLCHAINOPTS or DEVEL mode):
| Option | Config Symbol | Description |
|---|---|---|
| PIE by default | GCC_DEFAULT_PIE | Builds executables with Position Independent Execution enabled (-fPIE -pie) |
| SSP by default | GCC_DEFAULT_SSP | Enables Stack-Smashing Protection by default (-fstack-protector-strong) |
| Graphite | GCC_USE_GRAPHITE | Enables the Graphite loop optimization framework |
| SJLJ exceptions | SJLJ_EXCEPTIONS | Use setjmp/longjmp for C++ exception handling (increases code size) |
| Fortran compiler | INSTALL_GFORTRAN | Build and install gfortran in the toolchain |
| Go compiler | INSTALL_GCCGO | Build and install gccgo (glibc only) |
| Extra config options | EXTRA_GCC_CONFIG_OPTIONS | Arbitrary additional ./configure flags |
Optimization Flags
Target optimization flags are configured per-target intarget/linux/<target>/Makefile via the TARGET_OPTIMIZATION variable, which defaults to DEFAULT_TARGET_OPTIMIZATION from the toolchain config.
Typical embedded target flags:
LTO (Link Time Optimization)
LTO allows GCC to optimize across translation unit boundaries, often reducing binary size and improving performance. Global LTO can be enabled via:PKG_BUILD_FLAGS:
include/package.mk):
Hardening Flags
Security hardening flags are applied frominclude/hardening.mk. These are automatically included for all package builds.
Common hardening options controlled via menuconfig:
| Config Symbol | Flag Applied | Effect |
|---|---|---|
CONFIG_PKG_CC_STACKPROTECTOR_REGULAR | -fstack-protector | Basic stack canary protection |
CONFIG_PKG_CC_STACKPROTECTOR_STRONG | -fstack-protector-strong | Stronger stack protection |
CONFIG_PKG_RELRO_FULL | -Wl,-z,now -Wl,-z,relro | Full RELRO (read-only after relocation) |
CONFIG_PKG_RELRO_PARTIAL | -Wl,-z,relro | Partial RELRO |
CONFIG_PKG_ASLR_PIE_ALL | -fPIE -pie | PIE for all packages |
Wrapper Scripts
OpenWrt wraps the cross-compilers in shell scripts located intoolchain/wrapper/. These wrappers automatically inject the required flags (-fhonour-copts, sysroot paths, etc.) so that package build systems do not need to know all of the OpenWrt-specific flags.
The wrapper is responsible for:
- Enforcing
GCC_HONOUR_COPTSto detect packages that incorrectly override compiler flags - Adding the correct
--sysrootpath - Injecting target-specific flags from the build environment
GCC Build Stages
GCC is built in three stages to bootstrap the toolchain:| Stage | Directory | Purpose |
|---|---|---|
| Minimal | toolchain/gcc/minimal/ | Bare-minimum compiler to build the C library |
| Initial | toolchain/gcc/initial/ | Compiler using the newly built C library headers |
| Final | toolchain/gcc/final/ | Full compiler with complete C library support |