Commit graph

337 commits

Author SHA1 Message Date
Kevin Townsend
03fcfcd0f2 cmake: compiler: Add func_instrumentation flag
Adds a new compiler flag to enable function instrumentation injection
at compile time for compilers that support it.

Adds support for this flag to GCC when `CONFIG_INSTRUMENTATION` is
enabled, setting the `-finstrument-functions` flag during compilation.

Signed-off-by: Kevin Townsend <kevin.townsend@linaro.org>
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Signed-off-by: Maciej Sobkowski <msobkowski@antmicro.com>
2025-10-05 06:18:25 -04:00
Pierrick Guillaume
b7eec0fe24 cmake: linker: separate toolchain_ld_options() calls for grouped flags
Fixes #91045

Adding NO_SPLIT in the TOOLCHAIN_LD_FLAGS list caused every flags in the
list to be checked together by the linker. This caused issues where
incompatible flags was passed together, and the result was that none was
propagated to the linker.

By using separate variables, we can achieve the initial goal of NO_SPLIT to
only group a sub-set of flags.

Signed-off-by: Pierrick Guillaume <pguillaume@fymyte.com>
2025-09-30 19:36:37 +02:00
Robin Kastberg
d1e5c34ccc iar: toolchain: Cortex-M85 support
Add support in IAR build system for Cortex-M85.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-09-26 13:22:38 +02:00
Benjamin Cabé
59bf4e7895 cmake: clang: set no_track_macro_expansion properly
Compiler property no_track_macro_expansion is controlled by
CONFIG_COMPILER_TRACK_MACRO_EXPANSION.
When that Kconfig is set to Y, clang fails with the following error
message:

   unknown argument: '-ftrack-macro-expansion=0'

This commit modifies clang/compiler_flags.cmake so that there is a
proper clang compiler option for this flag.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-22 11:17:34 +02:00
Jaagup Averin
ac0387448e llvm: Remove "-Wno-volatile" from clang compiler args.
-Wno-volatile is set by gcc/compiler_flags.cmake,
but is not supported by clang and generated warnings.

Signed-off-by: Jaagup Averin <jaagup.averin@gmail.com>
2025-09-13 18:14:04 -04:00
Jaagup Averin
a2c55e01a8 llvm: Reorganize clang/compiler_flags.cmake
Since this overrides values from gcc/compiler_flags.cmake,
they should ideally have the same structure and order.

Signed-off-by: Jaagup Averin <jaagup.averin@gmail.com>
2025-09-13 18:14:04 -04:00
Ilya Tagunov
09a034e8ce toolchain: arcmwdt: override unsuitable default implementations
Provide toolchain-specific implementations for the new functions
added in d77b58a, because the default ones end up with build failures.

As the MWDT toolchain doesn't support different combinations of
compilers and linkers, there's no need to pass any linker properties
from the compiler, at least for the time being. Moreover, the default
implementation of compiler_set_linker_properties() uses the compiler
flag (--print-libgcc-file-name) that doesn't make any sense for MWDT.
Therefore, provide an empty implementation of the function.

The default implementation of toolchain_linker_add_compiler_options()
doesn't cause any issues for now, but it's still better to replace
it with the passthrough implementation borrowed from ld/lld.

Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
2025-09-01 14:01:46 +02:00
Mikhail Siomin
60a12bd336 cmake: fix build using clang when default and target arch do not match
Use CMAKE_C_COMPILER_TARGET to allow clang to correctly determine
the runtime library for the target architecture.
Otherwise, the default runtime library will be selected.

Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
2025-09-01 08:33:00 +02:00
Keith Packard
d77b58aacb cmake: Delay computation of linker paths until needed
With inclusion of the optimization flag into the multilib selection
process, we cannot compute the compiler library path when the compiler's
target.cmake is processed as LINKER_OPTIMIZATION_FLAG is not computed until
much later.

Instead, add a function (compiler_file_path) which can be used to locate
the appropriate crtbegin.o and crtend.o files.

Delay computation of lib_include_dir and rt_library until after all
compiler flags have been computed by adding compiler_set_linker_properties
and calling that just before toolchain_linker_finalize is invoked.

Place default implementations of both of these functions in a new file,
cmake/compiler/target_template.cmake, where we assume the compiler works
like gcc or clang and handlers the --print-file-name and
--print-libgcc-file-name options. Compilers needing alternate
implementations can override these functions in their target.cmake files.

These implementations require that no generator expressions are necessary
for the compiler to compute the right library paths.

This mechanism is also used to take any additional compiler options by
adding a new (optional) linker function,
toolchain_linker_add_compiler_options, which maps compiler options to
equivalent linker options, discarding any that aren't applicable.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-08-13 22:13:24 -04:00
Daniel Flodin
a4b66f9214 cmake: assembler optimization options
Commit f499ea0 made it so that the compiler optimization flags are also
passed to the assembler. However, this breaks for the IAR toolchain
since it uses the GNU assembler which does not have the same
optimization flags as the IAR compiler.

This commit separates the compiler and assembler optimizations to make
it possible to specify appropriate flags in a toolchains corresponding
`compiler_flags.cmake`

Signed-off-by: Daniel Flodin <daniel.flodin@iar.com>
2025-08-11 12:49:21 +03:00
Lauren Murphy
92db7bcf11 llext: compile llext with arc mwdt on nsim vpx5
Allow users to compile LLEXTs with the MetaWare Design Toolchain.
Provides utility to dramatically shrink bloated extensions by removing
unused section names left behind by MWDT strip. Test extensions will
not fit in NSIM VPX5 memory otherwise; each is reduced from ~16k to ~1k.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-08-01 19:36:59 +01:00
Adrian Bieri
5d42408efa cpp: add kconfig option STD_CPP23 for STD_CPP
to be able to choose c++23 dialect
deprecates c++2b, but we should keep the option c++2b for legacy

Signed-off-by: Adrian Bieri <adrian.bieri@loepfe.com>
2025-07-30 07:27:53 -04:00
Stephanos Ioannidis
dc3c9f3560 arch: riscv: Introduce code model options
This commit introduces a new Kconfig choice for configuring the code model
used for compilation.

All three code models specified by the RISC-V ELF psABI specification are
supported: medlow, medany and large.

For RV32, the `medlow` code model is always selected.
For RV64, the `large` code model is selected if the SRAM or kernel VM base
address is greater than or equal to 4 GiB; otherwise, the `medany` code
model is selected.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-07-19 15:43:09 -04:00
Stephanos Ioannidis
f5000936a8 arch: riscv: Add Zicntr extension support
This commit introduces the support for the standard Zicntr extension, which
provides hardware counters.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-07-19 15:42:57 -04:00
Stephanos Ioannidis
58a6a696a0 arch: riscv: Add Zc* compressed instruction extension support
This commit adds the support for the following new Zc* series compressed
instruction extensions:

  Zca  - Subset of the C extension without FP loads and stores
  Zcb  - "Simple" instructions
  Zcd  - Double-precision floating-point instructions
  Zcf  - Single-precision floating-point instructions
  Zcmp - "Complex" instructions for embedded CPUs
  Zcmt - Table jump instructions for embedded CPUs

With the introduction of the Zc* extensions, the C extension now implies
the following Zc* extensions:

  * Zca, always
  * Zcf if F is specified (RV32 only)
  * Zcd if D is specified

The Zc* extensions that are implied by the C extension are not specified in
the GCC `-march` flag because they are redundant and can interfere with the
resolution of the correct multi-lib for the selected architecture unless
the the alternate mappings for the redundant forms are manually specified.

All the implementation details in this commit are based on the Zc* v1.0.0
specification, which is the ratified version.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-07-19 15:32:35 -04:00
Lars-Ove Karlsson
2a9be50c29 toolchain: compiler: IAR does not allow vla with C++
Fixed a problem where the command line option --vla was used
with C++ causing a command line error in the IAR ICCARM compiler.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-07-11 08:14:12 -10:00
Stephanos Ioannidis
d0bded3c8c arch: riscv: Fix incorrect Zalrsc extension name
`Zlrsc` is not a thing and the correct name for it is `Zalrsc`.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-07-01 10:18:19 -05:00
Stephanos Ioannidis
1b3534d627 cmake: gcc: Fix code formatting of target_riscv.cmake
This commit fixes the incorrect code formatting used by target_riscv.cmake
by changing the 4-space indent to 2-space and removing the space between if
keyword and parenthesis.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-07-01 10:18:19 -05:00
Carles Cufi
4ea89d0ada cmake: clang: Enable -Waddress-of-packed-member
Several years ago we started enabling the -Waddress-of-packed-member
warning in commit cf111962e0 for GCC.

Do the same for Clang, since there is no reason not to and the warning
is very useful, especially in protocol stacks.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-06-27 18:28:09 -05:00
Keith Packard
0463827f92 compiler/gcc: Add rx compiler flags to linker too
Many of these affect the library search path.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-26 14:07:03 +02:00
Carles Cufi
892ac07a4a cmake: Add a new no_deprecation_warning compiler flag
Commit be40d854c2ccacf14ca3fcfb01bffdc9b075c6c9 introduced the ability
of building Zephyr with deprecation warnings enabled, by making
COMPILER_WARNINGS_AS_ERRORS depend on the newly added DEPRECATION_TEST
Kconfig option. This has the downside of disabling **all** warnings, not
only the deprecation ones.

This patch instead makes DEPRECATION_TEST disable only the deprecation
warning, but leaves COMPILER_WARNINGS_AS_ERRORS enabled.
This has the advantage of being able to see other unrelated warnings
(and fail if they appear) but has the disadvantage of not printing out
the deprecation warnings themselves (since they are disabled).

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-06-23 12:38:07 -07:00
Marcin Szymczyk
ab750eab5f cmake: compiler: gcc: riscv: remove spurious Zmmul
Zmmul is a subset of M extension.
No need to enable Zmmul redundantly if M is already present.

Reference:
449cd0c79a/src/m.tex (L173)
https://github.com/riscv/riscv-isa-manual/issues/869

Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
2025-06-13 10:13:37 -07:00
Daniel Leung
146e22fca4 cmake: xcc/xt-clang: fix for proper system include paths
Although xt-clang is based on clang, for some reason, it still
lists xcc system include path as the first search path (e.g.
for stddef.h), and the clang system include path as last. This
creates a big issue when the code starts to use any standards
past C89 (since xcc is based on GCC 4.2). We can use compiler
property nostdin_include to add -isystem to compiler options.
However, some modules (e.g. picolibcs) somehow ignore this.
So we also need to forcibly do add_compile_options() to make
sure the clang system include path is placed before the xcc
system include path.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-06-11 16:10:53 -07:00
Daniel Leung
f7b314347e cmake: compiler/gcc: skip nostdinc property for xt-clang
Xtensa toolchain xt-clang needs similar treatment to xcc in
terms of nostdinc and nostdinc_include, so add it to the if
block to exclude these by default.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-06-11 16:10:53 -07:00
Tom Hughes
b6766aeb6b cmake: compiler: Remove -fshort-enums
"-fshort-enums" changes the ABI. It's not enabled for gcc, so it's not
clear why it's enabled for clang (only ARM) and armclang, other than it
looks like some users of these toolchains may be linking against code
that is compiled with "-fshort-enums".

As an example, when compiling with clang, CONFIG_LTO, and a toolchain
built without "-fshort-enums", the linker warns:

ld.lld: error: linking module flags 'min_enum_size': IDs have
conflicting values in
'/usr/armv7m-cros-eabi/usr/lib/libc++_static.a(string.cpp.o at 784090)'
and 'ld-temp.o'

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-06-06 11:52:22 +02:00
Yuval Peress
d17956a074 build: Support SYSROOT_DIR in native_sim and clang
When running naive sim builds using clang, respect user passed
SYSROOT_DIR values. Additionally, allow overriding the archive tool
when calling Make for the native simulator.

Add the sysroot (if available) to the native_simulator target and
TOOLCHAIN_C_FLAGS and TOOLCHAIN_LD_FLAGS. Additionally pass CMAKE_AR
to NSI_AR.

Signed-off-by: Yuval Peress <peress@google.com>
2025-06-06 10:11:49 +02:00
Björn Bergman
bb797ab421 cmake: Fix compilation options for kobject_hash*.c
Rework how the compilation-options for the gperf generated
kobject_hash*.c files are put together to fix problems with SHELL:
and cmake-list separators handling.

zephyr_get_compile_options_for_lang_as_string() returns the set of
options as a cmake generator expression string which is cumbersome to
edit. This caused the command line for the IAR toolchain to have broken
SHELL: entries, and other some command line entries being postfixed by
"gnu".

This also adds CMake compiler properties for no_function_sections and
no_data_sections options

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-05-31 07:02:36 -04:00
Anas Nashif
b8f3263df0 toolchain: clang: compiler opt: -Ofast -> -O3 -ffast-math
clang 20 does not like -Ofast.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-23 17:41:40 -04:00
Duy Nguyen
f77e258cb9 cmake: Set RX build use 64bit doubles as default
The RX floating-point hardware only works on 32-bit values
so default gcc will build doubles as 32-bit, this make many
test fail on RX build test.
This commit force the build for RX arch to use 64-bit doubles
FPU will be supported later on this arch

Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
2025-05-22 23:57:26 +02:00
Lauren Murphy
7bbe425fe4 llext: basic x86 support
Adds basic x86 support for LLEXT.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-05-21 19:57:20 +02:00
3468830744 arch: riscv: add support for the zmmul integer multiply extension
The QingKe V2C has an integer multiplier but no divide. Add support
for the corresponding Zmmul extension and, as the extension was added
in GCC 13.0, add a test for the compiler version.

Signed-off-by: Michael Hope <michaelh@juju.nz>
2025-05-09 01:40:22 +02:00
Duy Nguyen
65ad2b0883 cmake: Add Renesas RX support
This commit add toolchain command line option for the RX
architecture support

Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
2025-05-02 09:18:16 +02:00
Keith Packard
2d64237f44 cmake: Enable undefined behavior sanitizer on all targets
GCC and Clang support the undefined behavior sanitizer in any
configuration, the only restriction is that if you want to get nice
messages printed, then you need the ubsan library routines which are only
present for posix architecture or when using picolibc.

This patch adds three new compiler properties:

 * sanitizer_undefined. Enables the undefined behavior sanitizer.
 * sanitizer_undefined_library. Calls ubsan library routines on fault.
 * sanitizer_undefined_trap. Invokes __builtin_trap() on fault.

Overhead for using the trapping sanitizer is fairly low and should be
considered for use in CI once all of the undefined behavior faults in
Zephyr are fixed.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-05-02 01:16:18 +02:00
Tom Hughes
78b1ad9a73 cmake clang/compiler_flags.cmake: Re-enable -Wunused-variable for clang
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-04-25 14:03:25 +02:00
Robin Kastberg
f9ec5f86fa iar: toolchain: arm: Fix FPU settings for CM55 and CM85
Currently the FPU settings for CM55 and CM85 are not complete.
This will complete them.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-04-14 13:06:41 +02:00
Tom Hughes
1415796bb2 cmake clang/compiler_flags.cmake: Re-enable Wunused-function for clang
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-04-08 10:50:08 +02:00
Julien Racki
6d1cb00627 arch: arm: Add Cortex-A7 support
Pass the correct -mfpu and -mcpu flags to the compiler when building
for the Cortex-A7.

Signed-off-by: Julien Racki <julien.racki@st.com>
2025-04-04 09:35:03 +02:00
Jamie McCrae
cc453dfed8 cmake: Remove previously deprecated look-ups
Removes functions that would handle deprecated variables and
functionality from CMake within Zephyr that were deprecated in
Zephyr 3.1 onwards but before 3.7

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-03-24 07:53:31 +01:00
Tom Hughes
53f17c1d78 cmake clang/compiler_flags.cmake: Re-enable -Wsometimes-uninitialized
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-23 13:19:27 +01:00
Lars-Ove Karlsson
bd278514e7 cmake: Fix warning levels for IAR
Rewrote the warning levels for toolchain IAR as IAR tools just turn
off warnings, not on. Also did some minor cleanup for coding
guidelines.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-19 10:57:41 +01:00
Daniel Leung
4b5ceb9dd0 cmake: compiler/xt-clang: add -Wno-unknown-warning-option
xt-clang is usually based on older version of clang, and
Zephyr main targets more recent versions. Because of this,
some newer compiler flags may cause warnings where twister
would mark as test being failed. To workaround that,
add -Wno-unknown-warning-option to suppress those warnings.

Fixes #84138

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-03-14 01:01:22 +01:00
Torsten Rasmussen
41ac85a2c5 cmake: introduce GCC_COMPILER_VERSION variable
Introduce GCC_COMPILER_VERSION to be used in Zephyr CMake when knowledge
of the current GCC Compiler version is needed and
CMAKE_C_COMPILER_VERSION has not been defined yet.

CMAKE_C_COMPILER_VERSION is not defined until project() is called.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2025-03-13 16:53:26 +00:00
Lars-Ove Karlsson
a43bca0a8c cmake: compiler: Added property flag for optimization fast
CMSIS modules dsp and nn sets the optimization flag -Ofast for their
libraries. I've now made a new compiler property optimization_fast to
avoid using ifdefs in the cmsis CMakeLists.txt files.

I've update GCC and arcmwdt (not sure if arcmwdt supports -Ofast)

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-07 20:01:18 +01:00
Robin Kastberg
da384651ec hal: infineon: handle gcc flag
Move -Wno-array-bounds from being hardcoded to a compiler
property

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-03-07 19:56:10 +01:00
Robin Kastberg
6d5dd34860 iar: toolchain: enable VLA for IAR
Currently some subsystems outside the zephyr kernel
use VLA:s such as bluetooth. We will enable it for now
in the same kind of situations as gcc.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-24 15:37:07 +00:00
Eric Ackermann
45b85bd220 llext: Disable small data sections on RISC-V
On RISC-V, GCC and possibly other compilers include small globals in
special "small data" sections like .sbss and .sdata.
This allows accessing these globals using the global pointer register
and an offset, which is faster than ordinary relocations.
Currently, llext_load does not support multiple NOBIT sections.
Thus, llext's that use both .bss and .sbss sections cannot be relocated.
Also, the global pointer cannot be used in llext's, as it does not
change when calling into or returning from an llext, making the
optimization pointless for llext.
This commit disables the use of small data sections by adding the
appropriate compiler flag when compiling llext's.
In addition to solving the aforementioned issue, this fixes llext's
test_inspect on RISC-V.

Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
2025-02-21 11:40:44 +00:00
Björn Bergman
36a599f158 cmake: mwdt assembler option for imacros
Add the -imacros property for assembler language to compensate
for changes introduced in PR #84800.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-02-19 14:50:17 +00:00
Lars-Ove Karlsson
4b40295e01 cmake: Always use Dwarf 4 for IAR
The IAR linker does not handle Dwarf 5 and since it uses the GCC
assembler for assembler files, we need to make sure the assembler
output uses Dwarf 4.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-02-18 18:38:41 +01:00
Robin Kastberg
9ab06ec667 toolchain: iar: Add experimental IAR support
This adds experimental support for the IAR toolchain.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Robin Kastberg
e9a0d146cf toolchain: move some hardcoded flags to properties
Some basic flags that were hardcoded needed
to be moved to properties to be able to implement
alternative toolchains.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00