File gcc-m-fpu.cmake is responsible for determining what should be
passed to -mfpu option. Fortunately GCC and Clang options are compatible
so we can use the file for clang.
The list of supported -mfpu options can be found at
https://github.com/llvm/llvm-project in
llvm/include/llvm/TargetParser/ARMTargetParser.def file.
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Fixes: #63771
The 'compiler/*/generic.cmake' is intended to set a C preprocessor which
can be used for devicetree preprocessing.
No C++ compiler is needed as host tool and should therefore not be set
in this file.
Remove the code to avoid setting a not required C++ compiler.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
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>
This enables -Wshadow to warn about shadow variables on
in tree code under arch/, boards/, drivers/, kernel/,
lib/, soc/, and subsys/.
Note that this does not enable it globally because
out-of-tree modules will probably take some time to fix
(or not at all depending on the project), and it would be
great to avoid introduction of any new shadow variables
in the meantime.
Also note that this tries to be done in a minimally
invasive way so it is easy to revert when we enable
-Wshadow globally. Source files under modules/, samples/
and tests/ are currently excluded because there does not
seem to be a trivial way to add -Wshadow there without
going through all CMakeLists.txt to add the option
(as there are 1000+ files to change).
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Add new option to use thread local storage for stack
canaries. This makes harder to find the canaries location
and value. This is made optional because there is
a performance and size penalty when using it.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
58408 fixed compilation for GCC >= 13.1. But -dumpversion's output
length depends on compile time configuration. It might only yield the
major version. So use -dumpfullversion instead, which is guaranteed to
always include major, minor and patch version.
Signed-off-by: Jan Henke <Jan.Henke@taujhe.de>
Clang/LLVM is natively a cross-compiler, so one set of applications can
compile code to all supported targets. The default target can be changed
using '--target' option.
CMake supports this type of compilers. To change compiling target, one
should set CMAKE_C_COMPILER_TARGET accorgindly.
The '--target' option has impact on the path to clang-rt library
returned by compiler when run with '--print-libgcc-file-name' option.
Without specifying target, Clang will return path to runtime library of
the host target (e.g. x86_64-pc-linux-gnu).
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Clang provides runtime library `libclang_rt.builtins.<arch>.a` but
`libgcc.a` is also supported.
The compiler can provide full path to the selected library using the
`--print-libgcc-file-name` option, for example:
```
/usr/lib64/clang/17/lib/baremetal/libclang_rt.builtins-armv7m.a
```
If `--rtlib=libgcc` option is provided, clang will also provide
appropriate path.
This patch replaces hardcoded `libgcc` with library name extracted from
path, so we are compatible with both libraries.
Signed-off-by: Patryk Duda <pdk@semihalf.com>
This property specifies the flag used to pass the linker script filename
through the compiler front end tot he linker.
For clang, we use the general purpose linker-pass through -Wl flag with -T:
-Wl,-T as clang doesn't support -T.
For gcc, we use -T directly as this keeps the picolibc specs file from
inserting the picolibc linker script as well.
If the compiler doesn't specify a value, we continue to use -Wl,-T as
before.
Signed-off-by: Keith Packard <keithp@keithp.com>
So they depend or select on the right NATIVE_BUILD
instead of NATIVE_APPLICATION.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
As of today MWDT toolchain in case of Zephyr may use few
tools from GNU toolchain - GNU compiler for DTS preprocessing
and objcopy for section renaming.
Currently we were trying to find any GNU compiler & objcopy
which start to cause compatibility issues for new targets -
i.e. not every objcopy knows new ARC targets.
Let's use ARC GNU tools from Zephyr SDK as we still usually
require it when building with MWDT for other tools like DTC
(device tree compiler)
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Configuration error:
| -- Configuring done (4.9s)
| CMake Error in CMakeLists.txt:
| Target "zephyr_interface" contains relative path in its
| INTERFACE_INCLUDE_DIRECTORIES:
|
| "include-fixed"
With GCC-13, limits.h and syslimits.h header files
are always being installed to include folder.
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=be9dd80f933480
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
Add a new compiler option to control tracking locations of tokens across
macro expansions. It may be useful to disable it when debugging long
macro expansion chains.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
arm-clang utilizes the gcc fpu flags, however -mfpu=auto is not a
supported option in arm-clang. For arm-clang we can mimic the auto
behavior by just not setting the -mfpu option.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
On mps2_an521 GCC_M_CPU gets set to cortex-m33+nodsp, however that is
not a valid setting for CMAKE_SYSTEM_PROCESSOR. We need to strip the
extra options (+<OPTION>) from GCC_M_CPU so that we get just cortex-m33.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
These flags were added to avoid warnings when main was declared to return
void. Now that main returns int, those warnings will flag errors.
Signed-off-by: Keith Packard <keithp@keithp.com>
Add a Kconfig option to set the compiler save-temps flag and set the GCC
implementation. This is very useful for troubleshooting macro expansion
issues, having an option allows a user to set it like any other config
option.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
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>
When we build for a SoC that has a cortex-m4 w/o a FPU that
utilizes CMSIS headers with armclang (like mec1501modular_assy6885)
we get the following warning:
modules/hal/cmsis/CMSIS/Core/Include/core_cm4.h:93:8: warning:
"Compiler generates FPU instructions for a device without
an FPU (check __FPU_PRESENT)" [-W#warnings]
#warning "Compiler generates FPU instructions for a device
without an FPU (check __FPU_PRESENT)"
Fix the by setting -mfloat-abi=soft for such cases that don't have FPU
enabled.
Fixes#56068
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
When building with C++ the icx compiler will try to utilize optimized
versions of memset/memcpy that are provided as part of libirc. However
libirc also has dependencies on things likes getenv/setenv, etc that
are expect in a linux host environment. So disable use of libirc
via compiler flag -no-intel-lib=libirc.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
New C++ versions have deprecated "register" variables and restricted
"volatile" semantics, so new gcc's will emit warnings when they see
that syntax. Zephyr uses both in our C headers (though we should
probably get rid of register and unify with C++'s volatile model), so
we're disabling the resulting warnings.
But OLD gcc variants (like xcc, sigh) don't understand new -Wvolatile
and -Wregister on the command line, so they get confused. Limit the
uses to the standard versions for which gcc would emit warnigns; xcc
doesn't support those anyway.
Signed-off-by: Andy Ross <andyross@google.com>
The toolchain support was developed and tested against arm clang
version 6.17. So add a check to ensure we are utilizing 6.17 or
newer.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Unlike gcc, clang splits out the flag controlling warnings about the return
type of `main' from other warnings related to that function. Add the extra
-Wno-main-return-type flag to mask these warnings when building Zephyr
without -ffreestanding, as when using picolibc.
Signed-off-by: Keith Packard <keithp@keithp.com>
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>
nostdinc_include flag needs to contain path to llvm libraries
and remove other relative paths. Change compiler flag to add
default C includes on building C++ code using xcc-clang compiler.
Fixes#54730
Signed-off-by: Aastha Grover <aastha.grover@intel.com>
This avoids a cryptic DTC failure when compiling trying to compile
native_posix with a missing gcc or clang.
REQUIRED is available since CMake 3.18
Example with clang, cryptic error without this commit:
```
ZEPHYR_TOOLCHAIN_VARIANT=llvm west build \
-p -b native_posix samples/hello_world/
-- Found toolchain: host (clang/ld) <= this is wrong
-- Found Dtc: /usr/bin/dtc (found suitable version "1.6.1", minimum ...
-- Found BOARD.dts: zephyr/boards/posix/native_posix/native_posix.dts
CMake Error at /zephyr/cmake/modules/dts.cmake:191 (message):
command failed with return code: No such file or directory
Call Stack (most recent call first):
zephyr/cmake/modules/zephyr_default.cmake:113 (include)
zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boil...
CMakeLists.txt:5 (find_package)
```
Well hidden behind the scenes, dts.cmake fails above because it invokes
`CMAKE_C_COMPILER-NOTFOUND`
With this commit:
```
ZEPHYR_TOOLCHAIN_VARIANT=llvm west build \
-p -b native_posix samples/hello_world/
-- Found toolchain: host (clang/ld) <= this is still wrong
CMake Error at zephyr/cmake/compiler/clang/generic.cmake:7 (find_program):
Could not find CMAKE_C_COMPILER using the following names: clang
```
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Clang does not have printf return value optimizations like GCC, so there's
no flag to turn them off when building against a non-standard printf
implementation (e.g., picolibc without float support).
Signed-off-by: Keith Packard <keithp@keithp.com>
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>
Add a compiler option to not merge globals. gen_kobject_list.py
is not capable of distinguish addresses of merged objects. The script
itself does not look wrong. The dward specification says that the
attribute DW_AT_location with opcode DW_OP_addr encodes a machine
address and whose size is the size of an address on the target machine
but for merged objects the address is longer, not clear why.
Disable global merge when userspace is enabled to avoid this problem.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
When using picolibc from the toolchain, we need to use the standard include
paths to make sure the library headers are found, especially for libstdc++.
Add toolchain picolibc to the list of cases for which this is the case.
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit updates all in-tree code to use `CONFIG_CPP` instead of
`CONFIG_CPLUSPLUS`, which is now deprecated.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
Currently we try to manually specify C/C++ headers locations
with -isystem flag which lead to issues with "include_next"
directive which is used in C/C++ headers. As advised by MWDT
R&D team let's rely on the default C/C++ include locations
which are provided by MWDT if we do build with MW C / C++
libraries. For that case we still need to manually specify
header directory to ASM builds which bay use 'stdbool.h'
In case of building with minimal libc (provided by Zephyr)
we rely on minimal libc headers and manually specify
toolchain's C header directory (as minimal libc still uses some
toolchain's C headers.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
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>
Clang version used by ARCMWDT does not support -fno-pic and -fno-pie
flags.
Flags were added into arcmwdt branch by
commit 8259931fce ("xcc-clang: Do not used unavailable options").
Initially they were set in common CMakeLists.txt via
zephyr_cc_option() function, which filtered them out, and they
did not used in builing process.
Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
This adds a choice of three different libc API buffer overflow detection
modes:
* None
* Compile-time
* Compile-time and Run-time
These correspond with the clang/gcc _FORTIFY_SOURCE modes (0/1/2).
_FORTIFY_SOURCE depends on compiler optimizations and require libc support
which the minimal C library doesn't include, so _FORTIFY_SOURCE is disabled
by default in those cases. Native tooling might also enable
_FORTIFY_SOURCE, so don't enable it by default in that case either.
Signed-off-by: Keith Packard <keithp@keithp.com>
GCC will compute expected sprintf (et al) return values internally and use
them in place of the actual return value. When the printf implementation
has reduced functionality, gcc may compute a different value.
For picolibc, this means disabling the optimization unless floating point
output is enabled.
Signed-off-by: Keith Packard <keithp@keithp.com>
Regexp suggested in #50173 PR is too strictly and
needs to be corrected. Previous regexp declines
engineering MWDT versions
(pattern ENG-2022.12-D1039-C39098348").
Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
The whole set of architecture flags must be specified together as
they might not make sense in isolation, e.g. -mfloat-abi=hard requires
a -mcpu value that might have an FPU. Use the NO_SPLIT feature to
bind all of the linker options together so that the linker can
compute the correct linker paths for toolchain-provided libraries like
libc and libgcc.
Signed-off-by: Keith Packard <keithp@keithp.com>
Make sure the linker knows what the target is, in case it needs to find
additional target-specific libraries (like picolibc).
Signed-off-by: Keith Packard <keithp@keithp.com>
Clang 15 added a new warning type `-Wdeprecated-non-prototype` that
warns about the functions without prototypes, which have been
deprecated since the C89 and will not work in the upcoming C2x.
This commit disables the warning because Zephyr deliberately makes use
of the functions without prototypes to allow the use of a "generic"
function pointer (notoriously in the cbprintf implementation) and
Zephyr will not move to the C2x in the foreseeable future.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
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>
After recent changes Zephyr became incompatible with old
MWDT versions (older than 2022.06).
Version checking may help to avoid build errors
related this incompatibility.
Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
Fixes: #47588
Use `check_set_compiler_property(... "SHELL:-Wformat -W<format-option>")`
to ensure that compiler options requiring `-Wformat` to work properly
are tested with said option.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
ARC processors are highly configurable, so ARC toolchain supports
big amount of mcpu options for all that HW configurations.
As difference in many configurations among the same processor
family usually doesn't affect Zephyr code we don't want
to create Kconfig option for each possible CPU configuration
(just to map Kconfig option to correspondent mcpu value
in 'cmake/gcc-m-cpu.cmake').
Instead we prefer being able to set proper mcpu value
individually for any ARC SoC and using 'cmake/gcc-m-cpu.cmake'
just for reasonable defaults.
To apply SoC-related changes for build-options on early stages of building
'tune_build_ops.cmake' should be created in appropriate SoC directory.
Example:
./soc/arc/snps_qemu/tune_build_ops.cmake
File content:
set(GCC_ARC_TUNED_CPU hs4xd)
Signed-off-by: Nikolay Agishev <agishev@synopsys.com>