Commit graph zephyr/CMakeLists.txt
Author SHA1 Message Date
Alberto Escolar Piedras
a283f958e7 cmake: Explicitly disable stack protector without stack canaries
Some compilers (like the host gcc on Arch Linux) default to enabling
the stack protector.
This is not something we want in general, so let's disable it unless
we want it (due to the stack canaries)

Background:
When building with picolibc (our default C library),
enabling the stack protector, links the picolibc stackprotector code,
which uses a possible getentropy() if available.
By default Zephyr has CONFIG_POSIX_C_LIB_EXT=y
(due to CONFIG_POSIX_AEP_CHOICE_ZEPHYR), but this provided
getentropy() tries to always use an entropy source even if none
is available, which results in link errors.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-10-28 22:49:51 -04:00
Dimitrios Kafetzis
91ab709fe6 cmake: get APP_BUILD_VERSION from sysbuild for the main image
With sysbuild, -DAPP_BUILD_VERSION=... is stored in the sysbuild cache
and never reaches the application image, so app_version.h falls back
to git describe. Read the variable with zephyr_get(... SYSBUILD LOCAL),
as is already done for APP_VERSION_CUSTOMIZATION, so the main image
gets the value. Other images, such as MCUboot, keep their own default.

Tested on native_sim and frdm_mcxn947; not tested on nRF54 targets.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Dimitrios Kafetzis <dimitrioskafetzis@gmail.com>
2026-10-09 17:01:56 +02:00
Pisit Sawangvonganan
b064e7dec4 cmake: CMakeLists.txt: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in `CMakeLists.txt`.

Assisted-by: Claude:claude-sonnet-5-5 codespell
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-10-06 07:31:14 +02:00
Luca Burelli
b7127c3cab app_version: fix custom app version handling
According to the code comments, APP_BUILD_VERSION can be overridden
externally to set a custom version for the application. However, when
generating app_version.h, the Zephyr version (BUILD_VERSION) is passed
instead. This results in app_version.h always containing the Git hash
as a fallback, regardless of the user value.

Fix the issue by passing the correct APP_BUILD_VERSION to the
gen_version_h.cmake script when generating app_version.h.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2026-09-30 19:35:55 +02:00
Carles Cufi
65fbc3ed3f c standard: Remove support for deprecated C standard versions
Commit 27d7f2055c61506781952e958c65054e878154b5 deprecated support for C
standards older than C17. This patch removes that support since a
release including the deprecated support has been released (Zephyr
4.4.0).

For more information, see:
- Original deprecation PR: https://github.com/zephyrproject-rtos/zephyr/pull/97076
- Transition checklist: https://github.com/zephyrproject-rtos/zephyr/issues/97061
- Original RFC: https://github.com/zephyrproject-rtos/zephyr/issues/30105

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2026-09-24 17:14:21 +02:00
Tomáš Juřena
40fc4af0c6 cmake: Fix build type warning after optimization flag rename
The CMAKE_BUILD_TYPE check still matches CMAKE_C_FLAGS_<build_type>
against OPTIMIZATION_FLAG, renamed to COMPILER_OPTIMIZATION_FLAG by
commit a4b66f9214 ("cmake: assembler optimization options"). The
empty expansion makes the regex match nothing, so the warning fires
for every build type and reports an empty flag. Fix it by matching
against COMPILER_OPTIMIZATION_FLAG.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Tomáš Juřena <jurenatomas@gmail.com>
2026-09-17 12:13:19 +01:00
Jamie McCrae
6fc4bab4e8 kconfig: Deprecate CONFIG_DEPRECATION_TEST
This Kconfig is superfluous as it can be set using the existing
CONFIG_WARN_DEPRECATED Kconfig instead, therefore deprecate it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-08 13:48:44 +02:00
Yishai Jaffe
d096b6b12d cpp: add kconfig option STD_CPP26 for STD_CPP
support the use of C++26.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2026-09-02 19:18:33 +01:00
Benjamin Cabé
159ab1c09f cmake: flash: remove deprecated flash/debug/attach/rtt targets
The CMake build system targets `flash`, `debug`, `debugserver`, `attach`
and `rtt` were deprecated in Zephyr 4.3 and are removed here as part of
the 4.5 deprecation removal cycle. They were thin wrappers that shelled
out to the corresponding west command, so users must now call `west
flash`, `west debug`, `west debugserver`, `west attach` and `west rtt`
directly. Note that `west build -t <target>` and `ninja <target>` are the
same mechanism, so both spellings are affected.

The generator loop was the only consumer of the `WEST_DIR` lookup and of
cmake/flash/check_runner_dependencies.cmake, so both are removed as well.
The runners.yaml generation in cmake/flash/CMakeLists.txt is kept: it is
what the west commands read, and it is also included directly by the
Nordic UICR helper projects.

The `run`, `run_<emulator>` and emulation `debugserver` targets are
provided by cmake/emu and are not affected.

Documentation that told users to run `ninja flash`, `ninja debug` or
`ninja attach` is updated to the equivalent west command, and the
zephyr-app-commands directive now rejects the removed goals when the
cmake tool is selected, so the docs cannot regress.

The now-unused RUNNERS_DEPS variable and the
check_runner_dependencies.cmake helper, which only existed to serve those
targets, are removed as well.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-08-27 21:23:56 +01:00
Benjamin Cabé
c8c1675e09 cmake: request the CMake file-based API when building an SBOM
"west spdx" reads CMake's file-based API object model -- the codemodel
and toolchains replies -- to work out what went into a build. A file API
query has to exist in the build directory before CMake starts, so it
could not be created from the build system itself. Hence "west spdx
--init": a separate pass, run once per build directory before
configuring, easy to forget and recoverable only by reconfiguring.

CMake 3.27 added cmake_file_api(), which registers a query for the
current invocation and has the reply written at generation time. Zephyr
required CMake 3.20 until the floor was raised to 3.28, so the build can
now ask for its own object model and the pre-configure step goes away.

Tie it to CONFIG_BUILD_OUTPUT_META, which "west spdx" already requires:
it reads the zephyr.meta that option emits and bails without it. Builds
that are not producing an SBOM pay nothing.

This also covers sysbuild, where the query had to be created in each
domain's build directory -- one that does not exist until sysbuild has
configured it. Each domain is an ordinary Zephyr build, so each now
requests its own reply.

Cost, measured on hello_world and an LVGL sample for qemu_x86 with the
same tree and a warm ccache, varying only whether the query is present:
no measurable configure time (-0.02 s and +0.04 s median of 6 runs, both
inside run-to-run spread; CMake's generate phase does not move) and no
change to no-op rebuilds. The reply costs 1.1-1.4 MB of build-directory
disk. Without CONFIG_BUILD_OUTPUT_META no reply is written at all.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-25 08:59:27 +02:00
Jamie McCrae
b108bbbc44 soc: cmake: Remove usage of duplicate SOC_* variables
Instead uses the Kconfig values directly, which are the source of
truth

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-08-08 16:33:24 -04:00
Ederson de Souza
2cb53feca1 llext-edk: Properly get topdir when --sysbuild is used
When sysbuild is used with west (west build --sysbuild), west TOPDIR
variable is not saved to application build_info.yml, but to upper level
build_info.yml. Get topdir from there, otherwise during the EDK build
all paths relative to wesddt TOPDIR (such as modules) are handled as
absolute paths during EDK build.

Fixes: #110728

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2026-08-07 11:17:44 -04:00
Måns Ansgariusson
e93bca31a3 kernel: remove KERNEL define from CMake
The KERNEL define polluted namespace it was only really used for the ztest
unit test framework. This commit removes the define and updates the ztest
code to use the unittest define instead.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-08-04 16:39:10 +01:00
Reto Schneider
a8cca443c3 cmake: Mention modern git commands
There are more modern alternatives to git checkout, and it makes sense
to mention them too.

Signed-off-by: Reto Schneider <code@reto-schneider.ch>
2026-07-17 13:32:16 -05:00
Paul Würtz
58f319b766 debug: Add Kconfig option to enable GCC to export callgraph files
Adding CALLGRAPH_INFO to allow to export compilation unit level callgraph
files from GCC. Complementing the existing STACK_USAGE options to follow
the initial intention to use both options together for stack use analysis.

Signed-off-by: Paul Würtz <paulwuertz@posteo.de>
2026-06-23 21:15:59 -04:00
Nicolas Pitre
97fac4b782 kernel: mmu: remove LINKER_USE_PINNED_SECTION and __pinned_* tagging
CONFIG_LINKER_USE_PINNED_SECTION is the second half of the selective
kernel-pinning model removed in issue #108773. With the kernel image
now always resident at boot (previous commit), the __pinned_*
attribute family is a no-op: every page they would have segregated is
already pinned by z_mem_manage_init()'s whole-image loop, so the
tagging contract neither adds safety nor remains maintainable.

Drop it.

Mechanical removals:

* All ~219 in-tree uses of __pinned_text, __pinned_rodata,
  __pinned_data, __pinned_bss, __pinned_noinit, and __pinned_func
  across arch/x86, drivers/interrupt_controller, drivers/timer,
  arch/common, kernel, lib/libc, subsys/portability/posix, tests, and
  the syscall code generator (scripts/build/gen_syscalls.py).

* The assembly aliases PINNED_TEXT/RODATA/DATA/BSS/NOINIT used in
  arch/x86/core/ia32/*.S and drivers/interrupt_controller/
  intc_loapic_spurious.S become plain TEXT/RODATA/DATA/BSS/NOINIT.

* K_KERNEL_PINNED_STACK_DEFINE, K_KERNEL_PINNED_STACK_ARRAY_DEFINE,
  K_KERNEL_PINNED_STACK_ARRAY_DECLARE, K_THREAD_PINNED_STACK_DEFINE,
  and K_THREAD_PINNED_STACK_ARRAY_DEFINE are removed. The few
  in-tree callers (kernel/init.c, arch/arm/core/cortex_a_r/smp.c,
  arch/arm64/core/fatal.c, arch/rx/core/prep_c.c,
  arch/x86/core/prep_c.c, kernel/include/kernel_internal.h,
  tests/bluetooth/hci_uart_async) move to the corresponding
  non-pinned macros.

Machinery removals:

* Kconfig.zephyr drops CONFIG_LINKER_USE_PINNED_SECTION.
  qemu_x86_tiny and qemu_x86_atom_virt drop their =y overrides.

* include/zephyr/linker/section_tags.h drops the __pinned_* macro
  definitions (both arms). __isr collapses to an empty macro since
  its only purpose was to alias __pinned_func.

* include/zephyr/linker/sections.h drops PINNED_TEXT_SECTION_NAME,
  PINNED_BSS_SECTION_NAME, etc. and the bare PINNED_TEXT/RODATA/etc.
  forwarders, plus the _APP_SMEM_PINNED_SECTION_NAME constant.

* include/zephyr/linker/linker-defs.h drops the lnkr_pinned_*
  externs, the _app_smem_pinned_* externs, and the lnkr_is_pinned()
  / lnkr_is_region_pinned() inline helpers.

* include/zephyr/linker/utils.h drops the lnkr_pinned_rodata branch
  in linker_is_in_rodata().

* include/zephyr/linker/app_smem_pinned{,_aligned,_unaligned}.ld
  are deleted; cmake/linker/ld/target_configure.cmake stops
  configuring them.

* boards/qemu/x86/qemu_x86_tiny.ld and
  include/zephyr/arch/x86/ia32/linker.ld drop their pinned-section
  blocks and the now-redundant #ifndef CONFIG_LINKER_USE_PINNED_SECTION
  conditionals throughout the body. The
  LIB_KERNEL_IN_SECT / LIB_ARCH_X86_IN_SECT / LIB_ZEPHYR_IN_SECT /
  LIB_C_IN_SECT / LIB_DRIVERS_IN_SECT / LIB_SUBSYS_LOGGING_IN_SECT /
  LIB_ZEPHYR_OBJECT_FILE_IN_SECT / ZEPHYR_KERNEL_FUNCS_IN_SECT macros
  in qemu_x86_tiny.ld are deleted; they existed only to feed the
  pinned text/rodata/data/bss/noinit sections.

* kernel/mmu.c drops the mark_linker_section_pinned(lnkr_pinned_start,
  ...) call. The mark_linker_section_pinned() helper survives but is
  now gated only on CONFIG_LINKER_USE_BOOT_SECTION.

* arch/common/init.c and include/zephyr/arch/common/init.h drop
  arch_bss_zero_pinned(); arch/x86/core/ia32/crt0.S drops the call
  to it.

* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
  thread's privileged stack on user-mode entry. With the kernel
  image fully resident the stack is already mapped.

* arch/x86/gen_mmu.py drops map_region("lnkr_pinned") and the
  set_region_perms() calls for lnkr_pinned_text / lnkr_pinned_rodata.

* CMakeLists.txt drops the LINKER_USE_PINNED_SECTION block that
  generated APP_SMEM_PINNED_* variables and the
  pinned_partitions target property feeding gen_app_partitions.py.
  cmake/modules/extensions.cmake removes the PINNED_RODATA /
  PINNED_RAM_SECTIONS / PINNED_DATA_SECTIONS zephyr_linker_sources()
  location keywords and their snippet files.
  scripts/build/gen_app_partitions.py drops --pinoutput /
  --pinpartitions arguments and the pinned-output branch.
  subsys/testsuite/coverage/CMakeLists.txt drops its
  CONFIG_DEMAND_PAGING-conditional fork.

* scripts/build/gen_kobject_list.py drops the
  app_smem_pinned_start / _end fallback for kobject placement
  validation.

* tests/arch/x86/pagetables and tests/kernel/mem_protect/userspace
  drop their lnkr_pinned_text / lnkr_pinned_rodata branches.

* include/zephyr/arch/x86/ia32/arch.h folds IRQSTUBS_TEXT_SECTION
  to the unconditional ".text.irqstubs" form.

* tests/subsys/llext/src/syscalls_ext.c drops a stale comment about
  syscalls landing in .pinned_text.

Targeted retentions:

* arch/x86/core/bootargs.c keeps multiboot_cmdline and efi_bootargs
  in .noinit (was __pinned_noinit, which decayed to __noinit when
  LINKER_USE_PINNED_SECTION was unset). The multiboot and zefi loader
  paths write these buffers before Zephyr's BSS-zero step, so
  zeroing them at boot loses the cmdline.

* arch/x86/core/ia32/fatal.c keeps _df_esf and _df_stack in .noinit.
  They are scratch space written by the double-fault handler and have
  no zero-init requirement; keeping them in .noinit also preserves
  the historical post-noinit alignment that gen_mmu.py relies on
  (z_mapped_size is computed before CMake-injected iterable sections
  are appended to the linker script, so the post-noinit page padding
  is what keeps those sections within the mapped region).

* include/zephyr/arch/x86/ia32/syscall.h and
  include/zephyr/arch/x86/arch.h wrap the per-arch
  arch_syscall_invoke* / arch_is_user_context / arch_k_cycle_get_*
  implementations in @cond INTERNAL_HIDDEN. The public Doxygen
  contract lives on the prototypes in
  include/zephyr/arch/arch_interface.h; the per-arch implementations
  are internal. Without this, removing the __pinned_func attribute
  exposes the implementations to the doxygen-coverage delta check
  as 10 newly-undocumented APIs.

Documentation updates are deferred to a separate commit.

Issue: #108773

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-06-23 09:11:08 -04:00
Nicolas Pitre
86c6923e12 kernel: mmu: remove LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT
With qemu_x86_tiny moved off the =n side of this knob in the previous
commit, no in-tree configuration sets
CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT=n anymore. The mode it
selected is also unsafe by construction (issue #108773), so there is
nothing to deprecate -- drop the Kconfig symbol and every #ifdef on
it.

Consequences:

* z_mem_manage_init() pins the whole Zephyr image unconditionally and
  no longer calls arch_bss_zero() after demand-paging init. The
  pinning loop's TODO about "we will need linker regions for a subset
  of kernel code/data pages which are pinned in memory and may not be
  evicted" is replaced with a brief note that the kernel image is
  always resident now and that pageable kernel regions go through
  __ondemand_*.

* arch/x86/core/ia32/crt0.S always calls arch_bss_zero() once
  arch_bss_zero_boot and arch_bss_zero_pinned have run.

* kernel/kheap.c and kernel/userspace/userspace.c drop the
  pre-kernel/post-kernel "skip non-pinned" dance and zero/init each
  heap and app-shmem partition unconditionally at PRE_KERNEL_1.

* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
  thread's privileged stack before dropping to user mode -- with the
  full kernel image resident the stack is already mapped.

* arch/x86/gen_mmu.py always maps the Zephyr image with FLAG_P set
  (and lnkr_boot_* / lnkr_pinned_* regions just inherit that).

* CMakeLists.txt no longer force-pins z_libc_partition into
  pinned_partitions for app_smem.

* The EVICTION_LRU gate
  "depends on LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT" goes away;
  LRU is now safe by construction on any DEMAND_PAGING board and
  becomes the default whenever ARCH_SUPPORTS_EVICTION_TRACKING.

* DEMAND_PAGING_PAGE_FRAMES_RESERVE loses its conditional default of
  32 frames; the new model needs no reserve.

* boards/qemu/x86/qemu_x86_tiny.ld drops the FLASH MEMORY region and
  the flash_load_offset block that arranged the demand-paged
  generic-section layout. boards/qemu/x86/board.cmake drops the
  8 MB-RAM bump and the --map flash gen_mmu argument that paired with
  that mode.

* tests/arch/x86/pagetables and tests/kernel/fatal/exception drop the
  code paths that were guarded on =n.

* tests/kernel/mem_protect/demand_paging/mem_map.lru replaces its
  CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT=y override with an
  explicit CONFIG_EVICTION_LRU=y, since the symbol it relied on is
  gone.

The __pinned_* tagging convention still expands to its actual linker
sections under CONFIG_LINKER_USE_PINNED_SECTION; that symbol and the
~219 in-tree __pinned_* annotations are cleaned up in the following
commit.

Issue: #108773

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-06-23 09:11:08 -04:00
Perry Naseck
0953b38b84 flashing: Fix UF2 builds for mapped-partition
This commit enables HEX builds for UF2 to ensure images can be made when
using mapped-partitions. HEX builds are now preferred over BIN for UF2.

Signed-off-by: Perry Naseck <pnaseck@media.mit.edu>
2026-06-16 17:43:34 +02:00
Jamie McCrae
1c65d60a40 cmake: Add support for dts RAM configuration
Allows using the chosen SRAM node for RAM configuration without
using Kconfig values

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-05-11 08:45:38 +02:00
Luca Burelli
a97b5f221b llext-edk: capture full build properties for EDK export
The current implementation of the LLEXT EDK exports only a partial set
of compiler settings to the EDK build system, specifically only the ones
defined by the Zephyr core (the 'zephyr_interface' target). Extending
this to include application and module-specific settings (from the 'app'
target and its dependencies) is tricky, because:
- while evaluating the main CMakeLists.txt, the 'app' target is not
  fully configured yet, and
- using generator expressions is not possible due to CMake not allowing
  expansion of $<COMPILE_LANGUAGE:...> outside of a proper compile
  context.

To work around this, this change introduces a new CMake subdirectory
(misc/llext_edk) that creates a dummy target which imports the build
configuration from 'app', but overrides the C compile rules to simply
output the resulting properties (defines, include directories, flags)
to text files. The EDK generation script then reads those text files
to get the full set of build properties, and includes them in the EDK
tarball.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2026-05-04 14:53:03 +02:00
Luca Burelli
b367b34bb9 llext-edk: (refact) filter flags in post-processing step
This changes the LLEXT EDK flag filtering to be done after the main
Zephyr build is completed. Instead of filtering the flags via genexes,
the full set is passed to the script along with the set of filters to be
applied, and the filter is applied later.

No functional change is intended.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2026-05-04 14:53:03 +02:00
Henrik Brix Andersen
4a6a00bb90 toolchain: warn on unsupported output format
Print a warning when an output format not supported by the toolchain is
enabled instead of silently ignoring it.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2026-04-28 15:24:47 +02:00
Anas Nashif
9b1c89a601 kernel: move gen_offset.h to arch
gen_offset.h is an architecture-specific header, not a kernel one.
Move it under the arch tree where it belongs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-24 15:39:20 -04:00
Henrik Brix Andersen
092485f407 toolchain: add support for verilog memory hex dump output
Add support for producing a zephyr.mem binary in Verilog memory hex dump
output format. This requires binutils v2.40 or newer.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2026-03-21 00:49:20 +00:00
Nicolas Pitre
dee349919b lib: heap: compute heap sizing constants from actual struct layouts
Z_HEAP_MIN_SIZE and Z_HEAP_MIN_SIZE_FOR were defined in kernel.h as
hardcoded magic numbers gated by a growing tower of #ifdefs — one
per Kconfig option that happened to affect the heap struct layout.
Every internal change required manually recomputing the constants,
duplicating layout knowledge across files, and praying nobody forgot
to update the #ifdef matrix.  This is fragile and unscalable: adding
a single new heap feature (e.g. a chunk canary trailer) would add yet
another dimension to the combinatorial explosion.

Replace this with build-time computation from the actual C structures.
A new lib/heap/heap_constants.c uses GEN_ABSOLUTE_SYM to emit the
correct values into a generated heap_constants.h header via the
zephyr_constants_library() infrastructure.  Z_HEAP_MIN_SIZE is
derived through an iterative fixed-point expansion (3 rounds, always
convergent) that mirrors the runtime logic in sys_heap_init().

Big vs small heap determination uses CONFIG_SYS_HEAP_SMALL_ONLY,
CONFIG_SYS_HEAP_BIG_ONLY, and sizeof(void *), mirroring the
big_heap_chunks() logic in heap.h.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-03-11 20:52:01 -04:00
Nicolas Pitre
1db0458480 cmake: add zephyr_constants_library() for build-time constants
Introduce a reusable CMake function that creates an OBJECT library
from a C source file containing GEN_ABSOLUTE_SYM() declarations and
generates a header file from the resulting symbols.  This encapsulates
the boilerplate needed for the offsets-style pattern: OBJECT library
creation, LTO prohibition, gen_offset_header.py invocation, and
dependency registration.

Convert the existing offsets.h generation to use this new function.

The zephyr_generated_headers target is moved earlier in CMakeLists.txt
so that subsystem CMakeLists.txt files can register generated headers
via zephyr_constants_library().

Also update gen_offset_header.py to derive the include guard from the
output filename instead of hardcoding __GEN_OFFSETS_H__, and remove the
unused input_name parameter.  This allows multiple generated headers to
coexist with distinct include guards.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-03-11 20:52:01 -04:00
Jamie McCrae
fa6c04b411 Revert "lib: heap: compute Z_HEAP_MIN_SIZE from actual struct layouts"
This reverts commit 518d8420c9.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-03 17:55:22 +01:00
Jamie McCrae
976ae48ce9 Revert "cmake: prohibit LTO for heap_constants.c offsets source"
This reverts commit 2d747e55a3.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-03 17:55:22 +01:00
Nicolas Pitre
2d747e55a3 cmake: prohibit LTO for heap_constants.c offsets source
Commit 518d8420c9 ("lib: heap: compute Z_HEAP_MIN_SIZE from actual
struct layouts") added heap_constants.c to the offsets library, but
did not add the prohibit_lto compile option that offsets.c has.
When LTO is enabled, the compiler optimizes away the absolute symbols
emitted by GEN_ABSOLUTE_SYM, causing them to be missing from the
generated offsets.h.  This breaks builds that use Z_HEAP_MIN_SIZE
(via kernel/mempool.c) with LTO-enabled configurations.

Fix by adding heap_constants.c to the same set_source_files_properties
call that disables LTO for offsets.c.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-28 10:10:18 +01:00
Nicolas Pitre
518d8420c9 lib: heap: compute Z_HEAP_MIN_SIZE from actual struct layouts
Z_HEAP_MIN_SIZE and Z_HEAP_MIN_SIZE_FOR were defined in kernel.h as
hardcoded magic numbers gated by a growing tower of #ifdefs — one
per Kconfig option that happened to affect the heap struct layout.
Every internal change required manually recomputing the constants,
duplicating layout knowledge across files, and praying nobody forgot
to update the #ifdef matrix.  This is fragile and unscalable: adding
a single new heap feature (e.g. a chunk canary trailer) would add yet
another dimension to the combinatorial explosion.

Replace this with build-time computation from the actual C structures.
A new lib/heap/heap_constants.c is compiled as part of the offsets
library and uses GEN_ABSOLUTE_SYM to emit the correct values into the
generated offsets.h.  Z_HEAP_MIN_SIZE is derived through an iterative
fixed-point expansion (3 rounds, always convergent) that mirrors the
runtime logic in sys_heap_init().  Z_HEAP_MIN_SIZE_FOR overhead and
bucket sizes are also generated, keeping all internal heap layout
knowledge in one place.

Big vs small heap determination uses CONFIG_SYS_HEAP_SMALL_ONLY,
CONFIG_SYS_HEAP_BIG_ONLY, and sizeof(void *), mirroring the
big_heap_chunks() logic in heap.h.

kernel.h picks up the generated values via
__has_include(<zephyr/offsets.h>) so there is no circular dependency
with the offsets compilation itself.  The old _Z_HEAP_SIZE manual
sizeof and BUILD_ASSERT scaffolding in heap.c are removed.

gen_offset_header.py is updated to accept multiple input object files
so that the heap constants object can coexist with the per-arch offsets
object in the same offsets library.  COMMAND_EXPAND_LISTS is added to
the offsets generation custom command so that CMake correctly expands
the $<TARGET_OBJECTS:> generator expression into separate arguments
when the offsets library contains more than one object file.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-27 21:02:45 +00:00
Lauren Murphy
ebf1f9d019 tests: llext: fixes for arcmwdt, gcc
Adds fixes for build and runtime issues using MWDT:

* Rename sections for llext_memblk.c buffers as MWDT cannot initialize
  sys_mem_blocks struct with buffer address when the section name of
  sys_mem_blocks struct (its variable name) is identical to the
  buffer's section name
* Adds --no-check-sections flag for MWDT on final stages of
  linking. Unlike other toolchains, MWDT's default behavior is to
  strictly check and fail on section overlap. Using SLIDs requires
  overlap; see llext-sections.ld
* Modifies inspect test case's ifdef around rodata sections, as
  not all Harvard platforms using MWDT have .rodata_in_data sections -
  their creation is triggered by passing the -Hccm flag to CCAC.
  As an example, nsim/nsim_em doesn't have them and nsim/nsim_vpx5 does
* Removes -Hccm flag when building with CONFIG_LLEXT_RODATA_NO_RELOC
  as it causes CCAC to mark the custom section llext.rodata.noreloc
  writable (SHF_WRITE) though it has only read-only data, making it
  impossible for for LLEXT to recognize it and put it in the
  appropriate region; see llext_load.c's llext_map_sections
* Adds name to unnamed first argument of threads_objects_test_setup,
  removing warning about omitting parameter names being a
  C2x extension

Also fixes a build warning for GCC about pointer arithmetic in
the INSTR_FETCHABLE macro.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-02-20 07:07:52 +01:00
Torsten Rasmussen
f04c9c0093 cmake: improve linker and assembly optimization inheritance
Switch manual linker and assembly inheritance settings from custom
handling of checking and setting linker/assembly optimization settings
based on compiler properties to instead use CMake's property inheritance
mechanism.

This reduces code to maintain as well as allow toolchain infrastructure
to clear optimization property flags when no flag is required or
supported, for example by the linker.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2026-01-30 16:58:13 -06:00
Daniel Leung
8776407309 cmake: compiler: add flags for VLIW generations
This adds to compiler flags template on instructing the compiler
on whether to generate VLIW instructions.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-29 16:09:13 -06:00
Mathieu Choplain
edbdfcad8c llext: add discarded symbol groups inspector
When the LLEXT subsystem detects that a symbol is marked for export from
the main image, but the symbol group in which the export belongs is not
enabled, add a marker in a special section in addition to not placing the
symbol in the final export table.

Add a post-build script which consumes the special section as post-build to
dump information about all discarded symbols in a build artifact, and also
check for common errors (missing Kconfig symbol / improperly named groups).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-29 13:42:56 +01:00
Torsten Rasmussen
a99311ebc6 cmake: align board qualifiers in CMake with Kconfig
Follow-up to PR# 102385.

Some occurrences of ${BOARD}${BOARD_QUALIFIERS} was missed in the
original alignment PR.

This commit adjusts the remaining occurrences to know include `/`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2026-01-27 08:41:15 -05:00
Tim Lin
2edece9d58 kernel: Add Kconfig option to disable LTO for kernel sources
Some SoCs require kernel code to be placed in RAM, which makes
link-time optimization (LTO) unsuitable for these files.
Disabling LTO allows the affected code to be linked as separate
objects and placed in specific memory regions.

Running kernel code from RAM can improve execution performance,
especially for timing-critical routines or context switch paths.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2026-01-21 17:04:50 +01:00
Mark Inderhees
234aa30a8f build: Dependency handling for syscall gen for changed API
Fix issue where changing an existing syscall API does not result in
regeneration of syscalls. This causes a build break on incremental
builds. The issue comes from an incorrect assumption that file
modifications result in updates to folder timestamps on Linux. The fix
is to use the same mechanism Windows is using to track file changes,
making explicit deps on header files that have syscalls.

Signed-off-by: Mark Inderhees <markind@meta.com>
2026-01-15 16:40:11 +00:00
Wilfried Chauveau
05dde46c4d build: cmake: print the board's qualifiers in the elf postbuild phase
When building for several cores of the same system it can be hard to
identify which build is currently running.
This addition helps disambiguate the logs.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2026-01-14 09:19:39 -06:00
Jamie McCrae
1bbbb286b3 cmake: Remove old deprecated code
Removes code that was deprecated in Zephyr 4.0

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-08 09:50:19 +01:00
Alberto Escolar Piedras
d74ccc1bdb cmake: Do not warn on deprecated symbols w CONFIG_WARN_DEPRECATED=n
CONFIG_WARN_DEPRECATED is 'y' by default.
When a user actively disables CONFIG_WARN_DEPRECATED, one would expect
that they would stop getting all deprecation warnings, not just the
ones from kconfig.
Otherwise users continue getting tons of these warnings when building
deprecated functionality.

So let's indeed disable them also for symbols and macros.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-19 07:52:31 -06:00
Carles Cufi
d0547b67cd toolchain: gcc: Add a new LTO_SINGLE_THREADED option for LTO
As described in this issue:
https://github.com/zephyrproject-rtos/sdk-ng/issues/1038
`-flto=auto` fails on some (slower) Windows machines due to an issue with
the Zephyr SDK's GCC toolchain for Windows.
In order to allow users to work around this issue, introduce a new
CONFIG_LTO_SINGLE_THREADED option that switches to `-flto=1`, which
enforces a single thread when processing LTO.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-11-28 09:50:04 +00:00
Jamie McCrae
2a09063289 cmake: Allow specifying custom VERSION file dependency
Allows applications and projects to specify their own requirements
for the application VERSION file to be re-generated, this fixes an
issue whereby the application git repository is updated with a new
commit but the old commit is still used by a build, users would
need to add a dependency in their application to the git index file

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-10-31 22:41:26 +02:00
Anas Nashif
303af992e5 style: fix 'if (' usage in cmake files
Replace with 'if(' and 'else(' per the cmake style guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-29 11:44:13 +02:00
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
Ederson de Souza
08ec5e89fc cmake: New list for post build commands that should run early
New cmake list, `post_build_patch_elf_commands`, will be prepended to
`post_build_commands` one, effectively making these commands to run just
after the ELF is created. It's particularly useful for operations that
patch the ELF generated, before other representations of it (such as
.bin) are created.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-09-02 07:56:48 +02:00
Dmitrii Sharshakov
8433c491b2 build: uf2: set offset when building RAM images
Follow ROMABLE_REGION from include/.../arm/cortex_m/scripts/linker.ld

This enables UF2 images to be created for RAM-only apps on RP2350.

Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
2025-09-01 16:40:54 +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
Keith Packard
d29cbf6563 cmake: Pass optimization flag to linker too
The linker may want to know the desired optimization level as when
the multilib configuration includes -Os as a selector.

Adopt the same pattern as the assembler optimization flags by allowing
toolchains to specify linker optimization flags which default to the
compiler optimization flags and the apply those using add_link_options.

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