Commit Graph

127 Commits

Author SHA1 Message Date
Daniel DeGrasse 0ea212918f cmake: extensions: use INTERFACE_SOURCES as property for code relocation
In order to enable code relocation, we use a custom target
(code_data_relocation_target), and add files we wish to relocate, as
well as which sections should be relocated to the COMPILE_DEFINITIONS
property for the target.

This approach has been fragile, because COMPILE_DEFINITIONS can also be
added to for all targets using `add_definitions`. This means if another
part of the project uses `add_definitions` and
CONFIG_CODE_DATA_RELOCATION is on, a warning will appear about the
"file" not being found. The "file" of course, is just the definition
added by `add_definitions`.

To work around this, switch to overloading the INTERFACE_SOURCES
property. This property should be a bit more robust, because nobody else
will add sources to the code_data_relocation_target.

However, this approach has the downside that the CMake documentation
pstates targets created with `add_custom_target()` (which the
code_data_relocation_target is) do not have an INTERFACE scope for
their sources- so while this approach works, it is not officially
supported by CMake

Fixes #60220

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-11-16 13:35:36 -05:00
Vinayak Kariappa Chettimada 7a7cfd0d64 cmake: gcc/ld: Fix LTO warnings
Fix the following warnings:
[255/261] Linking C executable zephyr/zephyr_pre0.elf
lto-wrapper: warning: using serial compilation of 8 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more
information
[260/261] Linking C executable zephyr/zephyr.elf
lto-wrapper: warning: using serial compilation of 8 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more
information

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-10-25 18:49:07 +01:00
Daniel Leung ac98d0e350 cmake: xcc: remove TOOLCHAIN_LIBS
Following the footstep of GCC/Clang cmake code to remove
TOOLCHAIN_LIBS, xcc also has it removed and utilizes
something similar to c_library to link the HAL library.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-10-15 19:08:47 -04:00
Torsten Rasmussen 29e82d2f23 cmake: add linker_libraries.cmake for Cadence Xtensa linker
Follow-up: #78320

Create linker_libraries.cmake for the Cadence Xtensa xt-ld linker to
ensure correct linking of runtime and C libraries as well as correct
link order.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-07 20:15:08 -04:00
Torsten Rasmussen 9d835fe464 cmake: move specs compiler and linker flags to toolchain properties
Moving specs argument to compiler and linker properties so that the
compiler and linker in use can decide how the flags are mapped / handled
for the compiler and linker in use.

This avoids specifying `--specs=spec.picolibc` for clang which prints a
warning about an unused argument.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Torsten Rasmussen 2e3873adde cmake: improve Zephyr link phase
Zephyr is a bare metal build where standard libs are disabled.

This means that c and runtime libraries must manually be linked in.

This has generally been handled by using CMake's link libraries handling
but the issue with that is both de-duplication but also library link
order.

Standard libraries must be linked at last location to ensure symbols
are always available, however this is not optimal with
target_link_libraries() because this would ultimately require every
library to know the c library to link with, which is not desired.

Therefore, setup standard C and runtime library linking in linker
CMake files for toolchains where this is required.

This commit expands the principle introduced with toolchain abstraction,
see PR#24851.

This means that a toolchain implementation may specify standard C,
runtime, C++, etc libraries, as well as their link order.
Because a property approach is used, then Zephyr modules, such as the
Picolibc module can adjust such properties.

An optional `zephyr_linker_finalize()` macro is called at the end of
Zephyr's CMakeList process and can be used by the toolchain
implementation to define the final linker invocation.

This aligns the linker handling flow to the principle introduced in
PR#24851 and improves the flexibility and robustness of Zephyr build
system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Jonathon Penix 9fe6c5e3fb cmake: linker: Use the same linker for cmake checks and final build
Currently, the linker that is used when performing various cmake checks
(check_c_compiler_flag, for example) may be different than the linker that
will be used during the actual build. This happens as we currently specify
'-fuse-ld' to force the appropriate linker a) after many such checks have
already happened and b) in a way which is not automatically propagated to
check_c_compiler_flag (and friends). As a result, the toolchain's default
linker will generally be used for such checks regardless of which linker
was selected in Zephyr.

This can lead to a number of surprises when building Zephyr, particularly
when building with clang. For example:

- If the linker is misconfigured, where the build will fail can vary
  depending on whether the linker is the toolchain's default. When the
  configured linker happens to be the toolchain's default, the build
  (helpfully) fails quickly on the checks for a basic working toochain.
  When the configured linker isn't the default, the build won't fail until
  the final link steps.
- The build can fail due to issues with a linker other than the one
  configured by the user in Zephyr. For example, LLVM toolchains without
  lld will generally fail to build Zephyr (the checks for a basic
  working toochain will fail) for targets where lld is the default in LLVM
  even if GNU ld is configured in Zephyr and would otherwise be used in the
  final build.
- Flags which are only added if check_c_compiler_flag (or similar) succeeds
  may be unexpectedly omitted during the final build if the flag is
  supported in the configured linker but is unsupported in the toolchain's
  default linker (as check_c_compiler_flag will test using the default
  one).

Note that this isn't limited to clang--even when we are building with
Zephyr's SDK and force ld.bfd, we seem to use the 'ld' variant during the
cmake checks (though this generally seems fairly harmless compared to
mixing ld/lld or other proprietary linkers).

To fix this, ensure the appropriate 'fuse-ld' is set early enough and in
such a way that the same linker will be used throughout the entire build.

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Evgeniy Paltsev 71e862e79c MWDT: linker: fix regresion
Fixes commit 5badbfe2a2 ("cmake: move
toolchain_ld_baremetal to linker properties.") which broke build for
ARC MWDT toolchain.

Fixes failure:
```
lldac: error: cannot open ,--orphan-handling=warn: No such file or
  directory
ninja: build stopped: subcommand failed.
```

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2024-09-10 11:43:01 +02:00
Marc Herbert c1cc11891c cmake: remove spurious parenthese just added to xt-ld/linker_flags
Fixes commit 9a9e252d16 ("cmake: linker: move toolchain_ld_<base|cpp>
to linker flag property")

Fixes failure:

```
CMake Error at zephyr/cmake/linker/xt-ld/linker_flags.cmake:32:
  Parse error.  Expected a command name, got right paren with text ")".

Call Stack (most recent call first):
  zephyr/cmake/target_toolchain_flags.cmake:42 (include)
  zephyr/cmake/modules/kernel.cmake:148 (include)
  zephyr/cmake/modules/zephyr_default.cmake:142 (include)
  zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
  zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boi
```

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2024-09-05 09:49:27 +02:00
Torsten Rasmussen 5db1f1ae8f cmake: deprecate toolchain_ld_<base|baremetal|cpp> macros
Remove the toolchain_ld_<base|baremetal|cpp> macro as all the macro
handling is now done through the use of linker properties.

Keep support for calling the old macros for out of tree toolchains
which have not been updated to the new property approach.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen 5badbfe2a2 cmake: move toolchain_ld_baremetal to linker properties.
Move linker flag setting from toolchain_ld_baremetal() to linker flag
properties as to follow the principle used in previos commits and from
PR#24851.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen 9a9e252d16 cmake: linker: move toolchain_ld_<base|cpp> to linker flag property
Transition the linker flag for the toolchain_ld_base and
toolchain_ld_cpp macros to linker flag properties.
This work follows the toolchain abstraction started in PR#24851.

toolchain_ld_base() was intended for base linker flags, but has slowly
become a 'set-any-linker-flag-here' and thus having several
`if(<check>)` or `<func>_ifdef(<check> ...)`.

Move the check to the top-level Zephyr CMakeLists.txt file, so that it
becomes cleaner which part is responsible for setting a value, and then
move the actual value (the linker flag) definition to the linker flag
property location.

It also helps adding support for new linkers, as it becomes clearer
which linker flags Zephyr always expects, for example `base` and
`cpp_base`, as well as those settings which are targeting for a given
purpose, such as linker sort alignment.

It also makes it clearer when those are used, for example in top-level
CMakeLists.txt with CONFIG_LINKER_SORT_BY_ALIGNMENT compared to this
information being buried in a linker support macro.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen 22c45c9234 cmake: remove llvm runtime library selection from target_base.cmake
The selection of the runtime library when using LLVM has already been
done in llvm/target.cmake and passed to the toolchain_ld_base() function
through the global TOOLCHAIN_LD_FLAGS setting.

The only reason this haven't been noticed is because of CMake's built-in
symbol de-duplication feature.

Remove the redundant runtime library handling.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen 9bb0140522 cmake: remove the use of PROPERTY_LINKER_SCRIPT_DEFINES
The support of PROPERTY_LINKER_SCRIPT_DEFINES has been broken since
the transition to CMake in 12f8f76165.

The intention was probably to allow users / projects to adjust
PROPERTY_LINKER_SCRIPT_DEFINES by setting a CMake cache variable.

The implementation tests for the CMake variable (local scope or cache)
PROPERTY_LINKER_SCRIPT_DEFINES, but it never uses such CMake variable.

Instead it uses a CMake global property named
PROPERTY_LINKER_SCRIPT_DEFINES. CMake variables and CMake global
properties are two very different things, and therefore the current
implementation has never worked. The fact that no one has never noticed
this flaw, means that the feature has never been used as intended.

Simplify the code by removing the use of the global CMake property and
instead set the value of the property on the linker script
pre-processing invocation.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Guennadi Liakhovetski 024bd41efb llext: xtensa: add support for the xt-clang toolchain
To build LLEXT images using the xt-clang toolchain from Cadence
linker flags have to be set similar to other toolchains. Add the
missing cmake files.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2024-05-29 10:49:40 -07:00
Jonathon Penix 4d7fe771f1 linker: lld: riscv: Enable gp relaxation for lld
Unlike GNU ld, lld's gp relaxation is disabled by default and must be
explicitly enabled via `--relax-gp`. Pass this flag to enable gp relaxation
for lld when both linker relaxations and gp usage for RISC-V are enabled.

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
2024-04-29 15:56:22 +02:00
Ederson de Souza 321e395a8f linker: Include libkernel.a in the whole-archive when llext is enabled
Differently from other libraries, which are included whole in the final
Zephyr ELF, libkernel.a itself isn't. Assuming this is intended to
enable optimisations (if it isn't, this patch will break things) - linker
can remove parts of the kernel that are not used by the application.

However, when considering Linkable Loadable Extensions (llext), this
optimisations can be counterproductive: for instance, syscalls that are
not used by the application won't be available for extensions. It won't
matter if someone "EXPORT_SYMBOL" for them, or even try to keep them
using LINKER_KEEP, they'll be gone.

To avoid that, this patches includes, when CONFIG_LLEXT=y, libkernel.a
inside the linker "whole-archive" block. This ends up making it consider
libkernel.a as a library whose all symbols should be kept. Note this
doesn't mean that all symbols will be there - things compiled out via
Kconfig will naturally still be out.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-03-26 19:31:56 -04:00
Jonathon Penix 9fc9eb5ddb cmake: Set memusage property for lld
lld gained support for the --print-memory-usage flag somewhat recently
(May 2023). Associate this flag with the memusage property when building
with lld, similar to what is done for GNU ld.

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
2024-03-04 22:12:15 +01:00
Radoslaw Koppel 26c8776c70 buildsystem: Add an option to enable LTO
This commit adds option to enable Link Time Optimization.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2024-02-02 19:49:36 +01:00
Grzegorz Swiderski 0b7fb57d09 cmake: code_relocation: Re-run when relocation_dict.txt changes
Fix an issue where updating a `zephyr_code_relocate()` call in CMake
didn't trigger regeneration of `code_relocation.c` and linker scripts.
The generation command was missing a dependency on the aforementioned
input text file, where the outcome of each call is cached.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-01-15 13:20:17 +01:00
Torsten Rasmussen 0b0f2f1912 cmake: safeguard path of SOC_LINKER_SCRIPT
Issue reported on Discord.

Safeguard cmake_path() for SOC_LINKER_SCRIPT so that the path is only
processed when SOC_LINKER_SCRIPT is defined.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-11-03 14:47:34 +00:00
Torsten Rasmussen 26b649ea53 cmake: update board and soc linker script handling
This commit updates the handling of board and SoC linker scripts.

Several SoCs creates a linker.ld file which sole purpose is to include
another arch common linker script, often with content like this:

    #include <arch>/linker.ld

instead of 100+ SoC specific linker.ld files containing just a single
include line of above structure, then this commit introduces two now
CMake variables, BOARD_LINKER_SCRIPT and SOC_LINKER_SCRIPT.

This allows the board and SoC CMake code to point directly to a common
linker script instead of creating a dummy linker.ld file doing this.

This removes the need for several dummy linker.ld file.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-11-03 11:01:23 +01:00
Patryk Duda ce438da14f llvm: Add support for LLVM libc++ C++ Standard Library
LLVM toolchain provides its own C++ standard library called libc++.
This patch adds new LLVM_LIBCXX config which should be used to indicate
that libc++ is used.

Information about library can be found at https://libcxx.llvm.org

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-10-20 14:59:31 +02:00
Al Semjonovs 955d85aa67 libc: picolibc: Fix picolibc to allow third party CPP
Picolibc dependencies limit ability to use third party minimal
implementations of CPP when enablng PICOLIBC_USE_MODULE.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2023-10-09 15:05:39 +03:00
Torsten Rasmussen 026dbdf539 cmake: LLVM LLD minimum version 14.0.0
Fixes: #35671

Add minimal version required for LLVM LLD linker.
Linking fails with older LLVM LLD, such as v10.0.0.

LLVM v14.0.0 was released in 2022, and latest LLVM is v17.0.1.
Zephyr currently doesn't have a strict minimum version of LLVM
specified, but based on LLVM development and known issues on older
releases, then a minimum version of v14.0.0 has been chosen in this
commit.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-10-03 11:40:19 +02:00
Torsten Rasmussen 73605f1ee8 cmake: armlink: update CMake library to arch__arm__core__cortex_m
Fixes: #62589
Follow-up: #60031

The PR #60031 moved CMake code to new folder location causing generated
library names to change.
This change impacted the use of those libraries in the Zephyr armlink
CMake code, causing CMake failures at configure time.

This PR fixes this failure by updating the armlink CMake code to use
the new library names.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-09-13 14:37:08 +01:00
Alberto Escolar Piedras fd27bed45e cmake/toolchain: Support LLVM source profiling/coverage for native boards
Add a a new source coverage for native builds
and new kconfig choice of COVERAGE mode to select which:
* COVERAGE_NATIVE_GCOV: what we had until now with native builds
* COVERAGE_NATIVE_SOURCE: a new LLVM source coverage mode
* COVERAGE_GCOV: the old COVERAGE_GCOV (embedded gcov data generation).

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-08-28 10:35:21 +02:00
Patryk Duda 4b94fc3da2 llvm: Add support for selecting runtime library
This patch adds Kconfig options to select either GNU libgcc or LLVM
compiler-rt. The 'rtlib' flag is provided in a config file, so this
patch introduces 'clang_libgcc.cfg' and 'clang_compiler_rt.cfg' which
enable appropriate library. The file is selected by concatenating
the 'clang_' prefix with library name.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-08-03 19:35:11 +02:00
Carles Cufi 623fb0ee81 build: relocation: Fix long command-line invocations
For applications relocating big parts of the code with many sections,
builds were failing on Windows due to hitting the max command-line
length on that platform.
Fix this by using a file to store the dictionary passed to the python
script.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/60994.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-08-01 09:47:57 -07:00
Patryk Duda fad8ae4052 linker: Introduce linker-tool-lld.h
Until now, linker-tool-gcc.h was used when LLD linker was chosen.
This causes linking issues because for GNU LD we use ALIGN_WITH_INPUT
attribute which is not available in LLVM LLD.

When using GNU LD we have to use ALIGN_WITH_INPUT to make sure that the
difference between VMA and LMA remains the same between output sections
that have different memory regions for VMA and LMA (RAM and FLASH).
With ALIGN_WITH_INPUT it's safe to do the memcpy of sections
that needs to be copied from flash to RAM in one function call:

(from z_data_copy() in kernel/xip.c)
```
z_early_memcpy(&__data_region_start, &__data_region_load_start,
               __data_region_end - __data_region_start);
```

By default, LLVM LLD aligns both VMA and LMA to the same value, but
when --omagic (-N) option is provided then only the first output section
of given region has aligned LMA and the difference between VMA addresses
(0 is this is the first section) is added.

As a result the difference between LMA and VMA is constant for every
section, so this emulates ALIGN_WITH_INPUT option present in GNU LD
(required by XIP systems).

The --omagic flag is defined in cmake/linker/lld/target_baremetal.cmake

Example:
```
MEMORY {
  ROM : ORIGIN = 0x1000, LENGTH = 1K
  RAM : ORIGIN = 0x11000, LENGTH = 1K
}
SECTIONS {
  .text 0x1000 : {
  	*(.text*)
  } >ROM

  .data.rel.ro : {
  	*(.data.rel.ro)
  } >RAM AT>ROM

  .data : {
  	*(.data*)
  } >RAM AT>ROM
}
```

```
echo '.globl _start; _start: nop; .byte 1;'\
     '.data.rel.ro; .balign 16; .byte 0;'\
     '.data; .balign 32; .byte 0;' | \
     llvm-mc -filetype=obj -triple=arm - -o test.o

armv7m-cros-eabi-ld.lld --sort-section=alignment -N -T script.ld \
     test.o -o lld_out
```

```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000094  2**2
  1 .data.rel.ro  00000001  00011000  00001010  000000a0  2**4
  2 .data         00000001  00011020  00001030  000000c0  2**5
```

In this example the first section has lower alignment than the following
section, but with -N option the difference between VMA and LMA is the
same for .data.rel.ro and .data sections.

For comparison, using BFD linker with --omagic option results in the
following:
```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000094  2**2
  1 .data.rel.ro  00000001  00011000  00001005  000000a0  2**4
  2 .data         00000001  00011020  00001006  000000c0  2**5

```

with ALIGN_WITH_INPUT added, GNU LD adds the difference between VMA to
LMA, but doesn't align LMA of .data.rel.ro section:
```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000074  2**2
  1 .data.rel.ro  00000001  00011000  00001005  00000080  2**4
  2 .data         00000001  00011020  00001025  000000a0  2**5
```

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-07-05 12:33:42 +00:00
Alberto Escolar Piedras e9af821e22 cmake: Add partial linking abstraction
Add a property to abstract the partial linking/rellocatable
linking for gcc ld and llvm's lld.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-23 09:05:14 +02:00
Gerard Marull-Paretas d0e58ad0a6 device: use iterable sections
Use iterable sections to handle devices list. This simplifies devices
implementation by using standard APIs.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-12 12:01:10 +02:00
Daniel Leung c9d70bb986 linker: ld: include crt{begin,end}.o if LIBGCC_DIR is defined
Only include crtbegin.o and crtend.o when LIBGCC_DIR is defined.
Since LIBGCC_DIR is not defined when compiling for posix
architecture, crt{begin,end}.o cannot be referred to via
LIBGCC_DIR.

Also note that, when using llvm/clang, crt{begin,end}S.o are
automatically for native_posix which collide with symbols in
crt{begin,end}.o. So there is no point in making LIBGCC_DIR
available for native_posix under llvm/clang.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 5d9079ba6d linker: ld: lld: do not do RELRO when using llvm/clang
GNU ld and LLVM lld both complain under C++:
  error: section: init_array is not contiguous with other relro sections

So do not create RELRO program header.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 81c3b3152c cmake: linker: make passing -no-pie configurable
This adds a new linker property specifically for passing
"-no-pie" to linker. Older binutils' LD (<= 2.36) do not
support this flag and will behave erratically if set. It
would parse "-no-pie" separately as "-n" and "-o-pie",
which would result in the output file being "-pie"
instead of "zephyr*.elf". Moreover, LLVM lld does not
support -no-pie but --no-pie (note the extra hyphen).
By having no-pie as a linker property, we can pass
correct no-pie flag to these linkers (or none at all).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 04fd862f68 linker: ld: GNULD_LINKER_IS_BFD to indicate if ld.bfd is used
This adds a new output variable to FindGnuLd.cmake to indicate
if ld.bfd is found. Since we now ask the compilers for their
preferred ld.bfd linker, it may not match using the existing
string equal test to ${CROSS_COMPILE}ld.bfd. So set the new
variable GNULD_LINKER_IS_BFD to true if ld.bfd, and use it to
pass an extra argument to compiler to make it use ld.bfd.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 41f015b39b linker: use find_package() to find LLVM lld
This introduces a new cmake module FindLlvmLld.cmake to do
the work to discover LLVM lld linker.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 29a67d1f2e linker: use find_package() to find GNU ld
This introduces a new cmake module FindGnuLd.cmake to do
the work to discover GNU ld (of binutils).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 7864caba1b linker: llvm: provide a default config file for clang
Some distros may provide config files for clang to change its
default behavior. We need to override that, or else developers
may be using different defaults and we will have confusing
bug reports in the future.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-29 19:48:47 -04:00
Daniel Leung 4683c8d4d5 linker: introduce profile xt-ld
Xtensa toolchain has its own linker, xt-ld, which is based on
binutils' ld. There are, of course, Xtensa specific options.
But mostly it is based on old version of ld. It would be
better to detach it from the ld profile to avoid any
incompatible changes there.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-02-22 08:35:46 -05:00
Nikolay Agishev 0dec4cf927 toolchain: Move extra warning options to toolchain abstraction
Move extra warning option from generic twister script into
compiler-dependent config files.
ARCMWDT compiler doesn't support extra warning options ex.
"-Wl,--fatal-warnings". To avoid build fails flag
"disable_warnings_as_errors" should be passed to twister.
This allows all warning messages and make atomatic test useles.

Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
2023-02-19 20:34:13 -05:00
Torsten Rasmussen 60196ca112 cmake: sparse: deprecate old sparse support
Deprecate old sparse support as Zephyr now provides a proper
infrastructure for SCA tools. Set ZEPHYR_SCA_VARIANT to sparse if user
is using deprecated way.

This allows to cleanup sparse code in various places and thus have a
cleaner build system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-01-27 20:28:58 +09:00
Flavio Ceolin 56ec06f344 kconfig: linker: Add --no-relax build option
In some architectures the linker performs global optimization relaxing
address modes and changing intructions in the output object file. This
is a problem when userspace is enabled since it assumes that addresses
won't change after certain build stage. In no supported architectures
this option is ignored.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-01-16 11:20:32 +00:00
Stephanos Ioannidis 404e7a9bf7 treewide: Use CONFIG_CPP_EXCEPTIONS instead of CONFIG_EXCEPTIONS
This commit updates all in-tree code to use `CONFIG_CPP_EXCEPTIONS`
instead of `CONFIG_EXCEPTIONS`, which is now deprecated.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Christian Taedcke 1fde62ef35 cmake: linker: lld: add missing -no-pie flag
See also
https://github.com/zephyrproject-rtos/zephyr/pull/38903

This is required when building tests for native_posix on ubuntu 22.04 using
clang-14 from the normal deb repository.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2022-11-22 13:02:44 +09:00
Yuval Peress fae9923ff2 unittest: update coverage library non gcc toolchains
When building with clang, the unittests were giving us an error:
```
error: undefined symbol: llvm_gcda_start_file
```

This seems to be from linking in `gcov` regardless of the toolchain.
It appears that clang doesn't need any special library for coverage.
With this change the following now produce identical coverage reports:

```
$ ZEPHYR_TOOLCHAIN_VARIANT=zephyr ./scripts/twister -p unit_testing \
  --coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=host ./scripts/twister -p unit_testing \
  --coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=llvm ./scripts/twister -p unit_testing \
  --coverage -i --coverage-tool lcov                              \
  --gcov-tool $(pwd)/scripts/utils/llvm-gcov.sh                   \
  -T tests/unit/intmath/
```

Signed-off-by: Yuval Peress <peress@google.com>
2022-11-21 16:09:46 -05:00
Peter Marheine 5eb75b81f7 arm: rename default RAM region from 'SRAM' to 'RAM'
It's useful for RAMABLE_REGION to have a uniform name when
CODE_DATA_RELOCATION is supported, because otherwise the build system
needs to be aware of how the region name differs between architectures.
Since architectures tend to prefer one of 'SRAM' or 'RAM' for that
region, prefer to use 'RAM' as the more general term.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2022-10-03 10:09:53 +02:00
Marc Herbert 3ebb18b882 cmake: fix utterly cryptic error handling in the -DSPARSE=y build
Fixes commit 7a85ff7683 ("add sparse support")

The sparse build needs (at least) two things:
1. sparse to be in the PATH
2. the environment variable REAL_CC to be defined and to match the
   value expected by CMake

Fix error messages when either condition is wrong.

- New error message when 1. is not satisfied:
```
CMake Error at zephyr/cmake/compiler/gcc/target.cmake:12 (find_program):
  Could not find CMAKE_C_COMPILER using the following names: cgcc
```

- Previous error "message" when 1. is not satisfied:
```
CMake Error at zephyr/cmake/compiler/gcc/target.cmake:17 (message):
  C compiler
  ZSDK/xtensa-intel_s1000_zephyr-elf/bin/xtensa-intel_s1000_zephyr-elf-gcc
  not found - Please check your toolchain installation
```
Note the "not found" cross-compiler actually exists!

- New error message when 2. is not satisfied:
```
Kconfig header saved to 'ws/build-tgl/zephyr/include/generated/autoconf.h'
-- Found sparse: /home/user/sparse/cgcc
CMake Error at ws/zephyr/cmake/compiler/gcc/target.cmake:25 (message):
  The only way to override its 'cc' default when cross-compiling with
  sparse is unfortunately an environment variable.  So you _must_ set
  REAL_CC at both configuration time and build time to:
  $ZSDK/xtensa-intel_s1000_zephyr-elf/bin/xtensa-intel_s1000_zephyr-elf-gcc

```

- Previous error "message" when 2. is not satisfied:
```
modules/hal/xtensa/include/xtensa/config/core.h:54:10:
    error:unable to open 'core-isa.h'`
```

Also: stop using the same name REAL_CC for both the internal CMake
variable and the external sparse parameter; they're two different
things so name them differently. Environment variable messes are
complicated enough.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2022-09-22 15:12:22 +00:00
Jeremy Bettis 878edeb6ff cmake: Add -gdwarf-4 at link time for gcc
Add a linker option for gcc to force dwarf symbols to be version 4.

Fixes #50106

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2022-09-13 17:05:57 -05:00
Peter Marheine d400b8135c arch/riscv: support CONFIG_CODE_DATA_RELOCATION
This implements support for relocating code to chosen memory regions via
the `zephyr_code_relocate` CMake function for RISC-V SoCs. ARM-specific
assumptions that were made by gen_relocate_app.py need to be corrected,
in particular not assuming any particular name for the default RAM
section (which is 'SRAM' for most ARM pltaforms) and not assuming 32-bit
pointers (so the test works on RV64).

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2022-08-24 10:08:06 +02:00