Commit graph

316 commits

Author SHA1 Message Date
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
Lauren Murphy
f0eb7ebc83 llext: arc: enforce bitness match
Enforces bitness match of ARC compilers and linkers invoked
building LLEXT apps by inheriting -mcpu flag from Zephyr.
The ARC toolchain becomes confused without the -mcpu flag.
On qemu_hs5x we see GCC select elf32-littlearc64 for
linking an object previously compiled as elf64-littlearc64.

Fixes #80949

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-02-05 21:01:01 +01:00
Filip Kokosinski
ee07eba569 arch/riscv: add Zaamo and Zlrsc extension subsets
The Zaamo and Zalrsc Extension (Version v1.0.0, 2024-04-25; Ratified) split
the standard A extension into two subextensions. As of date, the `_zaamo`
and `_zlrsc` extension specifications are accepted by the upstream
in-development GCC through the `march` argument. This means that those
subextensions are not yet supported by GCC shipped with Zephyr SDK.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2025-02-05 17:49:13 +01:00
Joel Holdsworth
46e37b00e7 compiler: gcc: Support versions predating include-fixed/limits.h
GCC versions starting from 4.3.0 until 12.4.0 stored the limits.h header in
a directory named include-fixed/ . Before 4.3.0 and after 12.4.0 i.e. from
13.1.0 onward, the header is stored in a directory named include/ .

Previously, target.cmake would only detect if the GCC version was 13.1.0 or
newer. This patch adds a check to also check if it is older than 4.3.0.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Joel Holdsworth
8b59dcfd11 cmake: compiler: Check -fno-printf-return-value before using
GCC versions before 7.1.0 do not have the -fno-printf-return-value flag and
give an error if it is used. This patch improves compatibility with older
compilers by making CMake check for the flag's availability before using.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Joel Holdsworth
c7bc47c60d cmake: compiler: Check -fdiagnostics-color=always before using
The -fdiagnostics-color flag is only on GCC versions 4.9.0 and newer.
Previously, CMake only checked that the compiler was not the XCC compiler
before using the flag.

However, given that the flag us unavailable on compilers other than XCC,
e.g. old versions of GCC, this patch replaces the previous logic with a
flag-check using the check_set_compiler_property() CMake function.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Luca Burelli
5b66af8adb llext: build with debug info, strip at packaging time
This patch changes the way extensions are built to allow for debugging
information to be collected. Debug flags are now used when compiling and
linking the extension source code, generating a debuggable ELF file.
The final .llext file is then stripped of unneeded symbols, including
all debugging information, at packaging time.

The debugging flag is still removed from the EDK-exported flags.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-27 08:54:44 +01:00
Benjamin Cabé
4b55a13c6c Revert "cmake clang/compiler_flags.cmake: Re-enable -Wgnu"
This reverts commit 8133f470dd.
Causes issues in pow2.c test

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-20 20:54:58 +01:00
Tom Hughes
8133f470dd cmake clang/compiler_flags.cmake: Re-enable -Wgnu
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-20 16:27:10 +01:00
Tom Hughes
c021c6d5f0 cmake clang/compiler_flags.cmake: Re-enable Wmissing-braces warning
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-17 10:42:00 +01:00
Tom Hughes
9ba1f2e170 cmake clang/compiler_flags.cmake: Re-enable -Winvalid-format-specifier
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-16 02:39:44 +01:00
Tom Hughes
b9d7b1bdae cmake clang/compiler_flags.cmake: Re-enable -Wunknown-warning-option
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-16 02:39:31 +01:00
Tom Hughes
2ae4ad2097 cmake clang/compiler_flags.cmake: Re-enable -Wtautological-compare
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-16 02:39:21 +01:00
Tom Hughes
0a71e95c5a cmake clang/compiler_flags.cmake: Re-enable -Wshift-overflow
This warning can be re-enabled without any changes (no warnings are
emitted).

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-01-15 19:05:34 +01:00
Benjamin Cabé
eacd5527aa Revert "cmake: remove enforcement of DWARF v4"
This reverts commit 9d849d92bf that seems to
be causing dozens of basic kernel test failures across various platforms.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-12-20 16:05:23 +01:00
Flavio Ceolin
3e75c03cb2 security: Add default stack protection level
STACK_CANARIES was enabling canaries in all functions using the compiler
flag -fstack-protector-all. This became confuse with the addition of the
options STRONG and EXPLICIT.

This commit adds the missing option (default level) and disambiguous the
options mapping them close to the compiler flags.

Now we have the following options:

STACK_CANARIES            -> fstack-protector
STACK_CANARIES_STRONG     -> fstack-protector-strong
STACK_CANARIES_ALL        -> fstack-protector-all
STACK_CANARIES_EXPLICIT   -> fstack-protector-explicit

Note that from now on STACK_CANARIES_ALL is the symbol that adds canaries
for all functions.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2024-12-20 12:37:20 +01:00
Flavio Ceolin
0236f7c9aa security: Add option for explicit stack canaries
Add option to enable stack canaries only when explicitely
declared. It adds a new function attribute, __stack_protect, that
can be used to enable stack protection in a function.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2024-12-20 12:37:20 +01:00
Flavio Ceolin
82ace41da4 security: Additional option for stack canaries
Previously, when stack canaries were enabled, Zephyr applied this
protection to all functions. This commit introduces a new option that
allows stack canary protection to be applied selectively to specific
functions based on certain criteria.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2024-12-20 12:37:20 +01:00
Benedikt Schmidt
9d849d92bf cmake: remove enforcement of DWARF v4
Remove the enforcement of DWARF v4 as pyelftools is able
to parse DWARF v5.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-12-20 12:36:46 +01:00
Robin Kastberg
742679a928 soc: nordic: make -include a compiler property
CMakeLists.txt uses the C compiler parameter -include,
This is causing issues for other toolchains and needs to generalized.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2024-12-16 20:51:17 +01:00
Guennadi Liakhovetski
827909b7b9 LLEXT: Xtensa: don't generate FLIX commands
The LLEXT linker for Xtensa cannot relocate FLIX commands, disable
them in extensions only until we have a solution. Note, that this
only affects extensions, the main Zephyr binary is still built with
FLIX commands.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2024-11-20 10:17:06 +00:00
Guennadi Liakhovetski
e2d8daae16 LLEXT: Xtensa: add a Kconfig option to enable -fPIC
Currently when building LLEXT for Xtensa we use the -fPIC compiler
option, but this cannot be used when using detached sections in
extensions. Add a Kconfig option to switch between the two
compilation modes and switch -fPIC off when building relocatable
(partially linked) ELF binaries.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2024-11-16 15:28:00 -05:00