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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Clean up the comment around the zephyr_generated_headers CMake library
to make it more accurate, now that the library is an interface library
rather than a custom target.
This is a follow-up to non-blocking feedback from
https://github.com/zephyrproject-rtos/zephyr/pull/92927.
Signed-off-by: Kesavan Yogeswaran <hikes@google.com>
Define `zephyr_generated_headers` as an interface library rather than a
custom target. This allows CMake libraries to depend on this target
AND propagate the dependency if needed using target_link_libraries.
Example:
If some user header includes offsets.h, even transitively, then
offsets.h must be generated before any source file that includes that
header is compiled. This can be captured by defining a library `foo` for
the header with a public link dependency on zephyr_generated_headers
using `target_link_libraries(foo zephyr_generated_headers)`. The
ordering dependency on the generated offsets.h header will then
propagate to `foo` and any libraries that link against `foo`, even
transitively. This was not possible before this CL because one cannot
use custom targets as public link dependencies with
target_link_libraries.
Signed-off-by: Kesavan Yogeswaran <hikes@google.com>
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>
This mode of building has been removed, so we do not need to support it
in the top level cmake file either.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Commit 65471a6095 separated
compiler flags into ASM, C and CXX as those flags may not be
universal to both assembler and compiler. Though, with that
separation, the assembler no longer gets the optimization
flags (e.g. speed/size optimizations). So adds this back so
the assembler can optimize the code if it chooses to. For
example, some instructions can be fused together to result
in small code.
Fixes#92439
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Some architectures use pseudo instructions in assembly.
Introduce an option that allows forcing raw instruction mnemonics.
Currently implemented for GNU binutils.
Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
Ignore gapfill for RX target as some RX toolchains generate wrong
output image when running gapfill for binary format.
Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
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>
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>
Discard the eh_frame section when C++ exceptions are disabled.
In principle the eh_frame may be used for other purposes such as
backtracing when linking C programs, then Zephyr compiles each source
file with '-fno-asynchronous-unwind-tables', thus keeping the eh_frame
in the elf output just takes up space.
When using gcc/ld, then the eh_frame is generally generally discarded
per default, however for clang/lld it will be included but give a
warning that the section is auto-placed.
Some platforms already discards the eh_frame, so unify this for all
targets.
As eh_frame is now discarded in linker scripts then post processing step
of removing the section during hex or bin conversion can also be
removed.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The Renesas RX support flashing .mot file for binary image
This commit target to add the .mot file output for build and
flash script
Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
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>
A typo in the top-level CMakeLists.txt prevented C++ targets from
receiving -fstack-protector-explicit when CONFIG_STACK_CANARIES_EXPLICIT=y.
Signed-off-by: Mirai SHINJO <oss@mshinjo.com>
All in all this makes cmake linker generator able to work for at least
most of the kernel tests and samples, on cortex m4.
Make the cmake linker generator have a file-structure more similar to
the ld-skeletons.
Add or edit groups, sections and logic to make the generator reflect
what the ld-skeletons do, esp. for kobjects and APP_SMEM, nonint and
some other details are also effected.
Use the new zephyr_linker_include_generated() and
zephyr_linker_include_var() functions to to handle
${DEVICE_API_LINKER_SECTIONS_CMAKE}, the kobject-prebuilt-*.h files and
APP_SMEM partition. Essentially the output from gen_app_partitions.py,
gen_kobject_placeholders.py.
Add ALIGN_WITH_INPUT on sections being put into DATA_REGION. This makes
the init layout work for ld.
This leverages the updates in gen_app_partitions.py to generate its
output as cmake linker generator sections too, and puts them into a
group defined in linker.cmake
Setup generator variables for alignment of APP_SMEM. Note that this does
not yet handle MPU_ALIGN which depends on the size of the section...
Fix broken k_object_assignment iterable section
Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
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>
Currently the compiler and assembler shares many
properties. This can be problematic for non-GNU
toolchains that takes different parameters to the
assembler and compiler.
Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
This patch adds support for Zstd and Zip formats to the EDK generation
process. The user can now choose between XZ, Zstd, and Zip compression
and output formats for the EDK file.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Add a new Kconfig option to make the generation of an Extension
Development Kit (EDK) for the LLEXT subsystem optional. This
allows to cleanly separate EDK-related configuration and build
steps from the rest of the Zeprhyr build system.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Currently, the llext-edk.cmake script requires a number of variables to
be passed in from the main CMakeLists.txt file as arguments to be able
to customize the generated files.
To improve this rigid approach, the script is modified to read in the
following files in the build directory:
* 'zephyr/.config', for the final set of Kconfig options used;
* 'build_info.yml', for the cmake-related variables.
This is more flexible and also easier to maintain, as it doesn't require
manual changes to the main CMakelists.txt file when new variables need
to be referenced.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Allows having CMake variables inside of this Kconfig to e.g. use a
value that can specify a board directory or path relative to a
CMake file location variable
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
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>