Commit graph

91 commits

Author SHA1 Message Date
Oleg Zhurakivskyy
a3999243a1 cmake: clang: Don't unconditionally use gcc's fortify
clang doesn't understand fortify at all, provide no op macro,
in order to handle the request to fortify in a generic way.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-04-30 09:33:54 -04:00
Oleg Zhurakivskyy
2688bfad8e cmake: clang: Detect host installed clang
In case TOOLCHAIN_HOME isn't explicitly reuqested,
(or indirectly forced with CLANG_ROOT_DIR), detect
any host installed clang in the path.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-04-30 09:33:54 -04:00
Mark Ruvald Pedersen
1f01325ee5 cmake: Toolchain abstraction: use LINKER, introduce toolchain_ld_base
toolchain_ld_base() represents flags that are fundamental to linking or
otherwise does not belong in any further specified linker flag category.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-28 12:52:18 -04:00
Mark Ruvald Pedersen
3481dc876e cmake: fix whitespace
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-28 12:52:18 -04:00
Anas Nashif
3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Marc Herbert
7d3fbfccd1 host-gcc/target.cmake: stop discarding CMAKE_<tool>_FLAGS for x86
Prepend -m32 to existing flags as opposed to silently override and
discard them:

- set(CMAKE_<tool>_FLAGS                -m32 )
+ string(PREPEND CMAKE_<tool>_FLAGS   " -m32")

This stops discarding additional flags passed with either cmake
-DCMAKE_<tool>_FLAGS="-fu -bar" or cmake -C params.cmake.

Note this bug was affecting only the combination of x86 and
CMAKE_<tool>_FLAGS. x86_64 wasn't affected and other, non-empty
CMAKE_<tool>_FLAGS_[DEBUG/RELEASE/etc.] weren't affected either.

Also convert flags string to list when invoking --print-libgcc-file-name
to support more than one CMAKE_C_FLAGS.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-03-21 00:21:27 -07:00
Kumar Gala
7aa8e43add libc: newlib: Cleanup/fix setting of system include paths
When we build with newlib we don't set -nostdinc.  In that case make
sure that we leave it to the toolchain to set the system include paths.

The one exception to leaving to the toolchain to set the system include
paths is the path to the newlib headers.  Since we build
with -ffreestanding we need to make sure the newlib header path is the
before the toolchain headers. Otherwise the toolchain's 'freestanding'
headers get picked up and that causes issues (for example getting PRI*64
defined properly from inttypes.h due to __STDC_HOSTED__ being '0').

For newlib we accomplish this by having the only system header specified
by zephyr_system_include_directories() being just the newlib headers.

Note: for minlibc we leave things alone as things just happen to work as
the -I include of the libc headers takes precedence over -isystem so we
get the libc headers over the toolchain ones.  For the newlib case it
appears that setting both -I and -isystem for the same dir causes the
-I to be ignored.

Fixes #14310

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 06:50:23 -05:00
Flavio Ceolin
18d96436a0 compiler: clang: Include missing target
Adding baremetal target when using clang/llvm.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-06 22:40:25 -05:00
Anas Nashif
aa049e5d8f toolchain: abstract setting -nostdinc
- newlib needs c standard includes (so no -nostdinc)
- xcc needs toolchain headers (so no -nostdinc)
- with host gcc:
  - x86_64 should not build with standard includes (-nostdinc needed)
  - native_posix should build with standard include (no -nostdinc)
..
..

To simplify, abstract this and move it to compilers/toolchains and still
depend on what the application wants.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-24 17:48:10 -05:00
Anas Nashif
6cd15825e1 compiler: add xcc as a standalone compiler
XCC is based on xcc, but is nothing like gcc and his many differences.
Instead of ifdeffing the gcc code with Xcc specifics, maintain it
standalone.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-24 17:48:10 -05:00
Mark Ruvald Pedersen
cb0fd451c2 cmake: Toolchain abstraction: Assembly
Introduce toolchain_cc_asm macro to capture toolchain specific flags
related to assembly.

-D_ASMLANGUAGE is kept common for all, assuming -D as define flag is
supported by all compilers (which is almost the case).

No functional change expected.

Clang's flags are compatible with gcc, and are thus inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-23 07:41:46 -05:00
Kumar Gala
9c2ac77861 cmake: Fix setting of -nostdinc
We where defining the variable NOSTDINC_F after we tried to use it.
Move the definition before the first reference fixes things.  When
-nostdinc now enabled we need to explicitly add the compiler include
path for x86_64 based builds (x86_64 and ARCH_POSIX).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-20 12:13:45 -06:00
Mark Ruvald Pedersen
63df409906 cmake: Toolchain abstraction: C++
Introduce toolchain_cc_cpp_*-family of macros.

Move the following into the toolchain_cc_cpp_* macros:
 * Common base set of flags
 * C++ standard version
 * RTTI
 * Exceptions

These macros must be implemented by every compiler port.
These macros set the respective flags, but leaves logic and control to
the root CMakeLists.txt file.

No functional change expected.

Clang's C++ flags are compatible with gcc, and are thus
inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 12:33:19 -05:00
Mark Ruvald Pedersen
0b3c65feea cmake: Toolchain abstraction: optimizations
Introduce toolchain_cc_optimize_for_* family of macros.
Each macro represents a general optimization class.
Each macro is then responsible for setting an output variable to that
class-of-optimization's flag.
The names of these output variables are decided from the root
CMakeLists.txt.

No functional change expected.

Clang's optimization flags are compatible with gcc, and are thus
inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-18 08:22:42 -05:00
Anas Nashif
33ca224ffd x86_64: use host toolchain
We were select host compiler from the generic gcc compiler section which
is used for cross toolchains. This arch should use the host-gcc compiler
definition instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-10 11:57:17 -06:00
Marc Herbert
e526a2b80a host-gcc: exclude -lgcc to fix -mx32 [qemu_]x86_64 regression
PR #9522 series ending with commit c2c9265b7d ("tests: cmsis: Disable
two cmsis portability tests on x86_64") added -mx32 support for the
x86_64 ARCH and qemu_x86_64. While this was implemented in
"compiler/gcc/target.cmake" as fall back from cross-compilation to the
host compiler, it worked with a direct ZEPHYR_TOOLCHAIN_VARIANT=host
too.

Later, -lgcc was added to "compiler/host-gcc/target.cmake" by PR #12674
to fix the -m32 x86 build. This broke the x86_64 build when using
ZEPHYR_TOOLCHAIN_VARIANT=host because even "multilib" packages usually
don't feature the -mx32 version of libgcc.

Fix this by excluding -lgcc in compiler/host-gcc/target.cmake just like
compiler/gcc/target.cmake always did for x86_64.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-01-30 22:08:30 -05:00
Mark Ruvald Pedersen
01592071f1 cmake: Toolchain abstraction: security
Introduce the first of the toolchain_cc-family of macros:
toolchain_cc_security_fortify and toolchain_cc_security_canaries.

No functional change expected.

Fortify source is not supported by Clang, but this commit retains
current behavior.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-01-30 08:42:11 -05:00
Marc Herbert
aa4ed2ae8c host-gcc: TOOLCHAIN_LIBS += libgcc (copied from compiler/gcc/)
Add missing -lgcc when compiling with ZEPHYR_TOOLCHAIN_VARIANT=host
merely copying some existing code from
'compiler/{clang,gcc}/target.cmake'.

This fixes compilation for the following boards with an x86
microprocessor:

 galileo, minnowboard, qemu_x86, qemu_x86_nommu, up_squared,
 up_squared_sbl

Compilation of the following boards with an X86_IAMCU microcontroller
still fail with a "cannot find -lgcc" error:

 arduino_101, qemu_x86_iamcu, quark_d2000_crb, quark_se_c1000_devboard,
 tinytile

This is _not_ a regression because these boards _already_ failed with
"undefined reference to __udivdi3" and other libgcc symbols.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-01-26 12:06:04 -05:00
Marc Herbert
5ac9cfd131 host-gcc: add missing set(CMAKE_ASM_FLAGS -m32)
This fixes the following error on all x86 BOARDs (qemu_x86,
galileo,... see "make usage" for the complete list) when compiling
assembly files with ZEPHYR_TOOLCHAIN_VARIANT=host:

 cc1: error: CPU you selected does not support x86-64 instruction set

This also fixes the following error when compiling minnowboard,
up_squared and up_squared_sbl boards with ZEPHYR_TOOLCHAIN_VARIANT=host:

  cc1: error: -mpreferred-stack-boundary=2 is not between 3 and 12

This fix alone is not enough to compile any of these boards; however it
moves compilation much further to the next, unrelated failure(s),
namely: 'undefined __udivdi3' and other libgcc symbols for all x86
boards; + some other, additional issues for some boards. See next
commit.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-01-26 12:06:04 -05:00
Marti Bolivar
4d36c23060 cmake: gcc.cmake: allow users to influence CMAKE_REQUIRED_FLAGS
A GCC-based toolchain may require additional, toolchain-specific
values in CMAKE_REQUIRED_FLAGS to perform compiler checks properly,
but gcc.cmake clobbers any values the user provides.

Preserve them instead, allowing users to give their own compiler
checking flags at generation time.

The details for the particular issue that inspired this are described
in https://github.com/pulp-platform/pulpino/issues/240.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2019-01-25 11:59:46 -05:00
Andy Ross
ff0ab5dc7a cmake/compiler/gcc: Fall back to host compiler for x86_64
If we don't have a detected cross compiler for x86_64, use the host
compiler instead.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
9c24867512 arch/x86_64: cmake: Make libgcc detection optional
Host toolchains don't tend to provide an x32 libgcc.  But we don't
actually need one for existing code.  This is fragile, but better to
work for all but obscure cases than break outright.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Mark Ruvald Pedersen
0efad5f7fd cmake: Whitespace and commentary fixes
Cosmetics, no functional change expected.
Fixed leading space alignment.
Replaced tabs with spaces.
Emulation error message output is now aligned.

To locate tabs in cmake, the following bash is useful:
grep -PRil "\t" * | grep -i cmake | grep -v ^sanity

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 12:23:50 +01:00
Sebastian Bøe
a0a63ac344 cmake: Split toolchain configuration into pre-and post-DT
Split up the toolchain configuration into two phases, generic and
target. The 'generic' phase configures the toolchain just enough to be
able to preprocess DT files. The 'target' phase completes the
configuration with target-specific configuration.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-14 13:16:28 +01:00
Sebastian Bøe
3e4b9ded0b cmake: clang: Add the runtime library to the link command
When building with clang symbols from the runtime library, like
__divdi3 were not being resolved. To fix this we add the "library path
for the currently used compiler runtime library" to the link path.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 08:36:58 -06:00
Sebastian Bøe
ef5cdbb390 cmake: toolchain: clang: Use 'find_program' and TOOLCHAIN_HOME
Align 'clang' with 'gcc' by having it also use 'find_program' instead
of 'set' to assign toolchain paths.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 08:36:58 -06:00
Sebastian Bøe
ab2139a90f cmake: toolchain: llvm: Move the compiler assignment into 'compiler'
Align 'clang' with gcc by having it also set CMAKE_C_COMPILER in the
'compiler' build script instead of the 'toolchain' build script.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 08:36:58 -06:00
Sebastian Bøe
bb278b688e cmake: toolchain: Change the names of 'clang' and 'llvm'
The 'llvm' and 'clang' build scripts have been named strangely. It is
more natural for 'clang' to be the compiler, and 'llvm' to be the
toolchain.

This commit rectifies this by renaming the files.

This also fixes #11187

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 08:36:58 -06:00
Sebastian Bøe
87858fd4e2 cmake: toolchain: Minor refactoring
Fixed whitespace such that 'XTOOLS_TOOLCHAIN_PATH' is vertically
aligned.

Also, combined two cmake invocations of 'list' into one.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-07 12:53:20 -05:00
Aurelien Jarno
c6727d49b7 arch: ARM: set -mthumb, -mcpu, -mfpu and -mfloat-abi in linker flags
Some toolchains are built with multilib enabled in order to provide
multiple versions of the same library, optimized for different ABI
or architecture. They require the the ABI/architecture/CPU selection
options to be passed at linked time. This is important for example
when linking with newlib.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-04 19:40:39 -05:00
Sebastian Bøe
5a2ddf37d9 msys: Drop support for building in an MSYS environment
MSYS support was added as a stop-gap while native windows support was
unsupported. Now that Native windows support is stable we can drop
support for MSYS.

Dropping support for MSYS fixes #11260 and allows us to spend more
resources on native windows support.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-13 10:28:33 +01:00
Daniel Leung
3829cb5c41 cmake: parameterized flags to not include standard defines/files
Not all compiles/linkers support the GCC flags to not include standard
defines, include files and libraries. So make these parameters such
that the toolchain can define them when supported.

Also, according to documentation, -nostdlib does the same for both
-nostartfiles and -nodefaultlibs. So remove the redundant ones.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-11-01 16:30:02 -04:00
Sebastian Bøe
b6a65a97aa kconfig: Make CONIG_FP_SOFTABI generate floating point instructions
This re-applies a patch that was merged in pr #6989, but then
accidentally reverted in a bad merge conflict resolution in pr #6842.

The actual behaviour of CONIG_FP_SOFTABI has not been matching the
documenation. The Kconfig documentation states that floating point
instructions should be generated, but this Kconfig option has been
turning off floating point instructions instead.

This commit causes floating point instructions to be generated when
CONFIG_FP_SOFTABI is enabled, as was originally intended and
documented.

This commit can cause regressions if users have been relying on the
actual behaviour instead of the documented behaviour.

Kconfig documentation:

config FP_SOFTABI
	help
	  This option selects the Floating point ABI in which hardware
	  floating point instructions are generated but soft-float calling
	  conventions.

GCC documentation:

Specifying ‘soft’ causes GCC to generate output containing library
calls for floating-point operations. ‘softfp’ allows the generation of
code using hardware floating-point instructions, but still uses the
soft-float calling conventions. ‘hard’ allows generation of
floating-point instructions and uses FPU-specific calling conventions.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-19 10:13:30 -04:00
Sebastian Bøe
1d90bcdc75 cmake: Use find_program on CMAKE_CXX_COMPILER
'find_program' should be used instead of 'set' for determining the
paths of host programs. It resolves #9582 and various other issues.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-12 09:36:33 -04:00
Sebastian Bøe
c1bf7350b1 cmake: Improve the error message when the compiler is not executable
When the SDK/toolchain has been incorrectly installed such that the
user does not have permissions to execute it an incomprehensible
errror message occurs.

This patch tests that executing 'gcc --version' does not give an error
code and errors out with an appropriate error message if it does.

This fixes #8977

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-07-31 12:40:37 -04:00
Anas Nashif
72edc4e15f clang/llvm: add initial configuration file for clang
Add an LLVM backend and a clang toolchain variant to support building
with llvm coming with popular Linux distributions.

This has been tested with X86 boards:
- quark_d2000_crb
- quark_se_c1000_devboard/Arduino 101

Use:

export ZEPHYR_TOOLCHAIN_VARIANT=clang

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:09 +02:00
Rajavardhan Gundi
08172cdf83 xtensa: provide XCC compiler support for Xtensa
This patchset provides Xtensa's xcc compiler support for Xtensa
projects in Cmake. This requires the below environment variables
to be defined aptly. The appropriate xcc license information also
need to be supplied.

ZEPHYR_GCC_VARIANT=xcc
TOOLCHAIN_VER=RF-2015.3-linux
XTENSA_CORE=cavs21_LX6HiFi3_RF3_WB16
XTENSA_SYSTEM=/opt/xtensa/XtDevTools/install/tools/
		RF-2015.3-linux/XtensaTools/config/
XTENSA_BUILD_PATHS=/opt/xtensa/XtDevTools/install/builds/

Change-Id: Ib3c10e8095439b0e32276ff37c00eca8420773ec
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-05-01 16:46:41 -04:00
Sebastian Bøe
8bcf30e21a cmake: posix: Use absolute paths for toolchain paths
Make posix align with non-posix platforms by having CMAKE_C_COMPILER
and friends use absolute paths.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-27 12:06:02 +02:00
Sebastian Bøe
f10fddeb56 cmake: toolchain: Improve error feedback when toolchain is not found
Improve the error feedback when the toolchain is not found.

Currently, for some setups, presumably primarily SDK-less setups,
users can get an error message like this for certain types of
misconfigurations:

CMake Error at zephyr/cmake/extensions.cmake:984 (message):
  No such file or directory: CMAKE_READELF: 'CMAKE_READELF-NOTFOUND'
Call Stack (most recent call first):
  zephyr/cmake/compiler/gcc.cmake:14 (assert_exists)
  zephyr/cmake/toolchain.cmake:38 (include)
  zephyr/cmake/app/boilerplate.cmake:243 (include)
  CMakeLists.txt:1 (include)

This commit will improve the error feedback to give a explanation for
what kind of failure has occured and will also dump relevant variables
to ease debugging.

This fixes #7075

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-19 12:53:43 -07:00
Sebastian Bøe
9be27f73db kconfig: Make CONIG_FP_SOFTABI generate floating point instructions
The actual behaviour of CONIG_FP_SOFTABI has not been matching the
documenation. The Kconfig documentation states that floating point
instructions should be generated, but this Kconfig option has been
turning off floating point instructions instead.

This commit causes floating point instructions to be generated when
CONFIG_FP_SOFTABI is enabled, as was originally intended and
documented.

This commit can cause regressions if users have been relying on the
actual behaviour instead of the documented behaviour.

Kconfig documentation:

config FP_SOFTABI
	help
	  This option selects the Floating point ABI in which hardware
	  floating point instructions are generated but soft-float calling
	  conventions.

GCC documentation:

Specifying ‘soft’ causes GCC to generate output containing library
calls for floating-point operations. ‘softfp’ allows the generation of
code using hardware floating-point instructions, but still uses the
soft-float calling conventions. ‘hard’ allows generation of
floating-point instructions and uses FPU-specific calling conventions.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-10 08:36:28 -05:00
Anas Nashif
622ab2f6fd toolchain: organise toolchain/compiler files
Move toolchain definitions into toolchain/ and move compilers to
compilers/
Usage of toolchain- for everything was confusing, there are the actual
compiler related definitions and there is the toolchain/SDK related
configs, so keeping them separate helps understand the different and
prevents confusion.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-13 07:44:45 -08:00