The autoconf.h macros were not passed to the CMake custom command for
linker script generation.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
With CMake 3.20 relative path inside DEPFILEs are treated relative to
CMAKE_CURRENT_BINARY_DIR and are transformed by CMake in its internal
dep file.
Therefore Zephyr build system must no longer add `base_name` to the
`-MT` argument for the preprocessor.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Zeroing the BSS and copying data to RAM with regular memset/memcpy may
cause problems when those functions are assuming a fully initialized
system for their optimizations to work e.g. some instructions require
an active MMU, but turning the MMU on needs the .bss section to be
cleared first, etc.
Commit c5b898743a ("aarch64: Fix alignment fault on z_bss_zero()")
provides a detailed explanation of such a case.
Replacing z_bss_zero() with an architecture specific one is problematic
as the former may see new sections added to it that would be missed by
the later. The same reasoning goes for z_data_copy().
Let's make maintenance much easier by providing weak versions of
memset/memcpy that can be overridden by architecture-specific safe
versions when needed.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Since CMake 3.20 DEPFILE has been supported by Makefile generators.
Simplify the CMake code by using DEPFILE for both Ninja and Makefile
generators.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
With CMake 3.20 relative path inside DEPFILEs are treated relative to
CMAKE_CURRENT_BINARY_DIR and are transformed by CMake in its internal
dep file.
Therefore Zephyr build system must no longer add `base_name` to the
`-MT` argument for the preprocessor.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes: #41435
Remove build host specific escaping of start symbol command argument.
The start symbol for armlink is: Image$$device$$Base
and were escaped as: Image\\$$\\$$device\\$$\\$$Base
However, the $ must only be escaped in Linux and MacOS, not on windows
hosts.
Instead of escaping the start symbol in the CMake code then it is better
to use the VERBATIM flag on `add_custom_command()` which ensures correct
escaping for the build host.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes: #41435
The use of %<symbol>% works well in Linux and MacOS but when passed
to the linker script generator in Windows the %<symbol>% is processed
by the windows shell causing the value to disappear and thus an empty
value inside the generated ld linker script or scatter file.
This is fixed by using the @ character instead of the % character.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The PR #40174 changed `configure_linker_script()` macro from handling a
single string to handle a list of strings for the
linker_pass_define argument.
This changed the armlink/target.cmake from STREQUAL to IN_LIST, however
as `configure_linker_script()` is a macro, then arguments are not
variables in the CMake sense but string replacements, and therefore
IN_LIST doesn't work directly on the argument.
Fix this by creating a true CMake list from the content of the argument
and use this list for IN_LIST checking.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The armlink/target.cmake should not source ld/target_base.cmake file
as it provides its own (empty) implementation of the
`toolchain_ld_base` macro.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
To prepare for linker script creation with flexible number of linker
passes depending on system configuration then the Zephyr CMake linker
script generator has been updated to use pass names instead of pass
numbers.
This allows greater flexibility as a section can now be active based on
the settings on the pass and not the linking pass index number.
As part of this, the `PASS` processing in `linker_script_common.cmake`
has been adjusted so that it properly handles when a linking pass is
handling multiple settings, such as both `LINKER_APP_SMEM_UNALIGNED`
and `DEVICE_HANDLES_PASS1` in same linking pass.
As the number of linking passes are more flexible, then the PASS
argument in `zephyr_linker_section()` and
`zephyr_linker_section_configure()` has been updated to also support
a `NOT <name>` argument, for example: `PASS NOT LINKER_ZEPHYR_FINAL`.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Currently all calls to `configure_linker_script()` specifies `-D<name>`
when calling `configure_linker_script()`.
This works well for the gcc pre-processed ld linker script templates,
but Zephyr also supports a CMake linker script generator which can be
used for ld scripts and armlink scatter files.
In this case, a `-D` must be stripped.
This commit changes this so that Zephyr CMake build system calls
`configure_linker_script()` without `-D`.
Thus the `LINKER_SCRIPT` choice can decide how this information should
be passed to underlying linker script functionality, that is `-D` for
linker script template and CMake variable for the CMake linker script
generator.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This option was deprecated for the v2.6 release, and has therefore met
the 2 release deprecation cycle requirements.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Update -fno-pie to only be added when relevant. This fixes native_posix
builds on Debian hosts.
* Debian and other Linux distributions have ld with --warn-textrel as
default.
* The option generates a warning when linking on x86.
* The warning make scripts/twister fail because we treat all warnings
as error.
* The warning is issued when no PIE objects are linked against PIE
library.
* PIE (Position Independent Executable) or not can be seen with the
following command.
* When you want to generate non PIE, link with `-no-pie.`
Non PIE
$ readelf -l build/zephyr/zephyr.elf | grep 'Elf file type is'
Elf file type is EXEC (Executable file)
PIE
$ readelf -l /lib/x86_64-linux-gnu/libc.so.6 | \
grep 'Elf file type is'
Elf file type is DYN (Shared object file)
Issue #35244
Signed-off-by: Yuval Peress <peress@google.com>
The root cause of #38591 was region symbols being placed before the
section description for data region.
Some region start symbols are placed before section description, other
region start symbols are placed inside the first section in the region
and thus identical to the sections own first symbol.
To support both schemes with the linker generator, a new
`SYMBOL SECTION` argument has been added to the zephyr_linker_group()
function.
The ld_script.cmake linker script generator has been updated to support
the new argument so that generated ld linker script has identical
behavior to the templated ld linker scripts.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
__cxa_atexit implementation provided by MWDT startup code calls
malloc which isn't supported right now. As we don't support
calling static destructors in Zephyr let's provide our own
__cxa_atexit stub and get rid of MWDT startup libs
entirely.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
This commit introduces armlink steering file.
A steering file in armlink allows Zephyr to keep using existing linker
symbols defined in ld scripts and used throughout the code tree.
The steering file is generated at build time in order to resolve Zephyr
linker symbols to their corresponding armlink symbols.
As example, Zephyr defines __ramfunc_start which corresponds to the
armlink auto defined Image$$ramfunc$$Base symbol.
Or __init_PRE_KERNEL_1_start which corresponds to Image$$init_0$$Base.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The default armlink signature uses `--list=<TARGET_BASE>.map`, but in
Zephyr we uses a different name for the map file, therefore we need to
specify a custom link executable signature.
This is done in the linker specific flags file:
cmake/linker/armlink/linker_flags.cmake
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This is the initial support for the armclang compiler together with the
armlink linker.
Introduced in this commit:
- armclang compiler support
- armlink linker support
- armlink scatter file generator for scatter loading
- dual pass linker script generation
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
A "Linker script" choice group has been added to the linker options
menu.
The existing HAVE_CUSTOM_LINKER_SCRIPT config has been relocated inside
the linker script menu.
Two new entries has been created:
- LD template, for using the old ld template files together with the C
pre-processor to create the final linker script.
- CMake linker generator, used for ARMClang / armlink toolchain.
The CMake linker generator is also supported for LD linker scripts
for the ARM architecture.
In CMake, the file cmake/linker/ld/target.cmake has been updated to
support the CMake LD linker generator.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Adding intial version of ld_script.cmake.
This script can generate ld linker script from the Zephyr CMake linker
functions.
This script is called by the build system and all linker settings, such
as memory regions, groups, output sections, linker symbols defined with
Zephyr CMake linker functions are passed to this script in order to
generate an ld linker script.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Adding intial version of linker_script_common.cmake.
This script parses memory regions, groups, sections, settings, and
symbols defined in the Zephyr CMake build system.
The linker script creates objects for each type above and groups
sections, symbols, and groups together based on their configuration.
This creates a hierarchy which the `<linker>_script.cmake`
implementations can then use during linker script generation.
linker_script_common.cmake also provides stubs for <type>_to_string()
functions which are used when generating the output script.
Each specific `<linker>_script.cmake` must implement those to_string()
functions to create the final linker script.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The current gen_handles.py script uses linker defined symbols.
As preparation for support of more linkers the gen_tables.py now takes
the device start symbol as argument.
For example, armlink and ld uses different symbols.
With ld those can be named explicitly, but for armlink the linker
decides the names.
For ld, Zephyr defines: __device_start
For armlink, the symbol is defined as: Image$$<section name>$$Base
Therefore knowledge of the linker symbol to be used must be passed to
gen_handles.py so that the correct symbol can be used for locating
devices.
To support this change, the creation of the asm, compiler, compiler-cpp,
linker targets has been moved from target_toolchain_flags.cmake to
target_toolchain.cmake.
All linkers has been updated to support the use of the
device_start_symbol on the linker target.
List of linkers updated:
- ld
- lld
- arcmwdt
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This allows memory partitions to be put into the pinned
section so they are available during boot. For example,
the stack guard (in libc partition) is needed during boot
but before the paging mechanism is initialized. Without
pinning it in physical memory, it would fault in early
boot process.
A new cmake property app_smem,pinned_partitions is
introduced so that additional partitions can be pinned
if needed.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The MWDT toolchain provides two C++ libraries. Let's use
LLVM C++ library.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
We don't need MWDT libc if we are using minimal one provided by
Zephyr. So let's avoid linking mwdt libc if CONFIG_MINIMAL_LIBC
is enabled.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
MetaWare hostlink is a library of system calls for debugging.
We don't use in case of Zephyr, however we provide real system
calls implementations. Let's pass -Hhostlib= to MWDT linker to
eliminate the MetaWare hostlink library from linkage.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
The constructors of static objects are stored in ".ctors"
section. In case of MWDT toolchain we have incompatible
".ctors" section format with GNU toolchain. So let's use
initialization code provided by MWDT instead of Zephyr one
in case of MWDT toolchain usage.
As it is done for GNU toolchain We call constructors of
static objects but we don't call destructors for them.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Add auto-generated kconfig header to linker script pre-processing
via -imacros flag. This permits link scripts supplied via
zephyr_linker_sources() to use CONFIG_* variables.
Signed-off-by: David Palchak <palchak@google.com>
-Hcl option instructs linker to use MetaWare C Compactlib.
According to MWDT documentation "Compactlib is not thread-safe"
So, let's use MetaWare C library instead which is thread-safe.
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
When the host toolchain is used, `-nostdlib` option is not specified
and therefore all default libraries, including the libgcc and its
components, are automatically linked -- so it is not necessary to
manually link them here.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Fixes part of: #32448
This commit updates the CMake CMAKE_CXX_LINK_EXECUTABLE to include
crtbegin.o and crtend.o at the right locations when linking with gcc.
It also updates linker scripts to ensure proper location of the
exception header frame sections.
This ensure proper handling of exceptions for those architectures
- x86
- xtensa
- riscv32
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes: #32237
When building for native_posix, then host tools are used.
This means that gcc will link using `/usr/bin/ld` per default.
If ld points to lld, then linking will fail.
This commit will first look for ld.bfd, and if found then use
-fuse-ld=bfd for linking. If ld.bfd is not found, then ld is used as
fallback as that will be assumed to be the best working candidate.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
-P is an option that was inherited from the old MetaWare compiler.
[ccac foo.c -P] is actually a shortcut for: [ccac -E foo.c -o foo.i].
In new version of mwdt, -P option can't redirect the output. we need
to use -E option, which works in all versions.
-P: Preprocess the file and write it to <src>.i (C) or
<src>.ii(C++). No compilation is performed.
-E: Run preprocessor only.
Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
We don't use xcheck (we disable it by passing '-Hnoxcheck' to
linker) so let's avoid xcheck object linkage as well by
passing '-Hnoxcheck_obj' option.
'-Hnoxcheck_obj' option implies the '-Hnoxcheck' option.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Fixes: #28847
This commit fixes two places that was causing gen_relocate_app to fail
in windows.
gen_relocate_app.py now splits only on first `:` in
`<MEM_REGION>:<file>`.
Windows contains `:` in path, thus only first `:` is valid for splitting
mem region and file path.
Second part of the issue is fixed in CMake where `'` was used for
quoting of command arguments.
This causes a file not found on Windows because the final `'` would be
treated as part of the filename. Similar the first `'` would be treated
as path of the mem region name.
This is fixed by using `"` for quoting, which works correctly on all
platforms.
gen_relocate_app.py:403: UserWarning: File: .../kernel/sem.c' Not found
Note the stray `'` ^^^
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
-Hnocopyr option suppress copyright message in case of LDAC linker
but in case of LLDAC linker somehow it leads to partial linking
and generation output file with relocations. Looks like we
are converting MWDT option to LLVM option incorrectly in this
case. Among the partial linking itself it may cause build errors
when 'elf.get_dwarf_info' from 'gen_kobject_list.py' meets the
arch-specific relocation which isn't supported by 'elftools'
It requires future investigation, let's disable -Hnocopyr for now
to have elf image linked correctly.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
The current zephyr_get_compile_<type> flags returns compile / include
flags based on generator expressions.
But they also included a space.
This have the unintended side-effect that when the properties are
fetched into another variable and later appended to lists in order to
finally be used in a CMake target function / custom command, then CMake
in some cases will quote the string, creating a quoted argument like:
"arg0 arg1 arg2: instead of individual arguments like: "arg0" "arg1"
"arg2".
By using $<SEMICOLON>, then arguments are seperated correctly.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes#28456
This commit extends `target_ld_options()` with a NO_SPLIT flag.
Specifying `NO_SPLIT` will ensure that all linker flags will be applied
together when testing the compiler and linker.
This allows a caller to ensure that flags are tested together.
This fixes the RISC-V case where the flags `-mabi` and `-march` were
omitted because they were tested individually.
Note, the update of `target_ld_options()` will allow the same flag on
`zephyr_ld_options()`
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit fixes an issue where the list returned by
zephyr_get_include_directories_for_lang() would be a space separated
list, cause the arguments to be quoted during linking.
This is fixed by requesting `$<SEMICOLON>` to be used as separated which
which again ensures a correct expansion of the list.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
* add metaware toolchain support in build system:
* compiler
* linker
* binutils
* gcc objcopy is used because it can't be replaced
with mwdt's binutils currently
* To use ARC metaware toolchain, you'd better:
* in Linux/Unix environment
* install arc gcc/zephyr toolchain to use gnu's objcopy
tool
* set ZEPHYR_TOOLCHAIN_VARIANT=arcmwdt
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
This commit updates the get Zephyr settings functions to be able to
handle settings if those settings are expressed using a generator
expression.
As example, zephyr_get_include_directories_for_lang(...) would prefix
each include property of zephyr_interface with `-I`, like this:
Property: include;include/generated;lib/libc/minimal/include
becomes: `-Iinclude -Iinclude/generated -Ilib/libc/minimal/include`
But if the property contains a generator expression:
Property: include;$<TARGET_PROPERTY:compiler,some_include>
becomes: -Iinclude -I$<TARGET_PROPERTY:compiler,some_include>
and in case that property is a list, this results in:
`-Iinclude -Iinclude/list_item1;include/list_item2;include/list_itemN`
and thus breaking the build.
This is fixed by using `$<JOIN:<list>>` expression instead, which
ensures all list item, regardless of provided as simple list or through
the usage another generator expression, will always expand correctly.
Functions updated in the commit:
- zephyr_get_include_directories_for_lang
- zephyr_get_system_include_directories_for_lang
- zephyr_get_compile_definitions_for_lang
- zephyr_get_compile_options_for_lang
The sample `application_development/external_lib` has been updated
according to those changes.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
As part of toolchain abstraction three template files to facilitate
additional toolchain support development has been introduced.
Those covers:
- bintools
- compiler flags
- linker flags
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.
This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The undefined symbol option "-u" applies to linker so prefix
it with the linker prefix (usually "-Wl"). This fixes warnings
from LLVM/Clang about unknown arguments.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>