summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2020-12-14 14:35:31 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-15 03:55:58 +0000
commitdfc24d03d58e0c4b015898f605228f12c9c4015e (patch)
tree294a14d33e5b360a9c5304e2a479e83eed0c155a
parent1a697dfdc386066b8d2c8d0224679ed82741580a (diff)
downloadchrome-ec-dfc24d03d58e0c4b015898f605228f12c9c4015e.tar.gz
toolchain: provide definition for chroot host-based LLVM toolchain
This provides a definition for an LLVM toolchain, which acts as a chroot host-based toolchain. This is for compiling unit tests and the posix-ec project, not for real devices. We need this to enable unit tests and posix-ec build in the commit queue, since Zephyr SDK is not available in the chroot. BUG=b:175248887 TEST=zmake configure -b -B $BUILD -t llvm projects/experimental/posix-ec $BUILD/build-singleimage/zephyr/zephyr.elf works Change-Id: Ie71f53cf53503f9279aab654170c7bc2b7a80d20 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/zephyr-chrome/+/2590992 Tested-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2630160
-rw-r--r--zephyr/cmake/bintools/llvm/generic.cmake10
-rw-r--r--zephyr/cmake/bintools/llvm/target.cmake9
-rw-r--r--zephyr/cmake/compiler/clang/compiler_flags.cmake8
-rw-r--r--zephyr/cmake/compiler/clang/generic.cmake5
-rw-r--r--zephyr/cmake/compiler/clang/target.cmake6
-rw-r--r--zephyr/cmake/linker/lld/linker_flags.cmake6
-rw-r--r--zephyr/cmake/linker/lld/target.cmake26
-rw-r--r--zephyr/cmake/toolchain/coreboot-sdk/generic.cmake10
-rw-r--r--zephyr/cmake/toolchain/llvm/generic.cmake7
-rw-r--r--zephyr/cmake/toolchain/llvm/target.cmake16
10 files changed, 94 insertions, 9 deletions
diff --git a/zephyr/cmake/bintools/llvm/generic.cmake b/zephyr/cmake/bintools/llvm/generic.cmake
new file mode 100644
index 0000000000..94b35ed51d
--- /dev/null
+++ b/zephyr/cmake/bintools/llvm/generic.cmake
@@ -0,0 +1,10 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set(CMAKE_AR "/usr/bin/llvm-ar")
+set(CMAKE_NM "/usr/bin/llvm-nm")
+set(CMAKE_OBJCOPY "/usr/bin/llvm-objcopy")
+set(CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
+set(CMAKE_RANLIB "/usr/bin/llvm-ranlib")
+set(CMAKE_READELF "/usr/bin/llvm-readelf")
diff --git a/zephyr/cmake/bintools/llvm/target.cmake b/zephyr/cmake/bintools/llvm/target.cmake
new file mode 100644
index 0000000000..a77d459288
--- /dev/null
+++ b/zephyr/cmake/bintools/llvm/target.cmake
@@ -0,0 +1,9 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Use generic bintools.
+include("${TOOLCHAIN_ROOT}/cmake/bintools/llvm/generic.cmake")
+
+# Include the GNU bintools properties as a base.
+include("${ZEPHYR_BASE}/cmake/bintools/gnu/target_bintools.cmake")
diff --git a/zephyr/cmake/compiler/clang/compiler_flags.cmake b/zephyr/cmake/compiler/clang/compiler_flags.cmake
new file mode 100644
index 0000000000..1f71650975
--- /dev/null
+++ b/zephyr/cmake/compiler/clang/compiler_flags.cmake
@@ -0,0 +1,8 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+include("${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake")
+
+# Disable -fno-freestanding.
+set_compiler_property(PROPERTY hosted)
diff --git a/zephyr/cmake/compiler/clang/generic.cmake b/zephyr/cmake/compiler/clang/generic.cmake
new file mode 100644
index 0000000000..33d82b38e1
--- /dev/null
+++ b/zephyr/cmake/compiler/clang/generic.cmake
@@ -0,0 +1,5 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set(CMAKE_C_COMPILER "/usr/bin/x86_64-pc-linux-gnu-clang")
diff --git a/zephyr/cmake/compiler/clang/target.cmake b/zephyr/cmake/compiler/clang/target.cmake
new file mode 100644
index 0000000000..6702087df5
--- /dev/null
+++ b/zephyr/cmake/compiler/clang/target.cmake
@@ -0,0 +1,6 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set(CMAKE_C_COMPILER "${CROSS_COMPILE}clang")
+set(CMAKE_CXX_COMPILER "${CROSS_COMPILE}clang++")
diff --git a/zephyr/cmake/linker/lld/linker_flags.cmake b/zephyr/cmake/linker/lld/linker_flags.cmake
new file mode 100644
index 0000000000..99307bbeee
--- /dev/null
+++ b/zephyr/cmake/linker/lld/linker_flags.cmake
@@ -0,0 +1,6 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Include definitions for bfd as a base.
+include("${ZEPHYR_BASE}/cmake/linker/ld/linker_flags.cmake")
diff --git a/zephyr/cmake/linker/lld/target.cmake b/zephyr/cmake/linker/lld/target.cmake
new file mode 100644
index 0000000000..1bbc6f479d
--- /dev/null
+++ b/zephyr/cmake/linker/lld/target.cmake
@@ -0,0 +1,26 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Include definitions for bfd as a base. We need to pretend that
+# LINKER=ld to do this.
+set(LINKER ld)
+include("${ZEPHYR_BASE}/cmake/linker/ld/target.cmake")
+set(LINKER lld)
+
+# Override the path to the linker.
+set(CMAKE_LINKER "${CROSS_COMPILE}ld.lld")
+
+# Zephyr CMake system expects this macro to be defined to provide
+# default linker flags.
+macro(toolchain_ld_base)
+ # For linker scripts, we pretend to bfd-like
+ set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES
+ -D__GCC_LINKER_CMD__)
+
+ # Default flags
+ zephyr_ld_options(
+ ${TOOLCHAIN_LD_FLAGS}
+ -Wl,--gc-sections
+ --build-id=none)
+endmacro()
diff --git a/zephyr/cmake/toolchain/coreboot-sdk/generic.cmake b/zephyr/cmake/toolchain/coreboot-sdk/generic.cmake
index 7f5f6d3df5..1b86948bcd 100644
--- a/zephyr/cmake/toolchain/coreboot-sdk/generic.cmake
+++ b/zephyr/cmake/toolchain/coreboot-sdk/generic.cmake
@@ -6,12 +6,4 @@
# (e.g., for device-tree). Thus, we should use LLVM for this
# actually, as that's what's currently supported compiler-wise in the
# chroot right now.
-
-set(CMAKE_C_COMPILER "/usr/bin/x86_64-pc-linux-gnu-clang")
-
-set(CMAKE_AR "/usr/bin/llvm-ar")
-set(CMAKE_NM "/usr/bin/llvm-nm")
-set(CMAKE_OBJCOPY "/usr/bin/llvm-objcopy")
-set(CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
-set(CMAKE_RANLIB "/usr/bin/llvm-ar")
-set(CMAKE_READELF "/usr/bin/llvm-readelf")
+include("${TOOLCHAIN_ROOT}/cmake/toolchain/llvm/generic.cmake")
diff --git a/zephyr/cmake/toolchain/llvm/generic.cmake b/zephyr/cmake/toolchain/llvm/generic.cmake
new file mode 100644
index 0000000000..6a248a13cf
--- /dev/null
+++ b/zephyr/cmake/toolchain/llvm/generic.cmake
@@ -0,0 +1,7 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set(COMPILER clang)
+set(LINKER lld)
+set(BINTOOLS llvm)
diff --git a/zephyr/cmake/toolchain/llvm/target.cmake b/zephyr/cmake/toolchain/llvm/target.cmake
new file mode 100644
index 0000000000..d79d73d1ae
--- /dev/null
+++ b/zephyr/cmake/toolchain/llvm/target.cmake
@@ -0,0 +1,16 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set(COMPILER clang)
+set(LINKER lld)
+set(BINTOOLS llvm)
+
+# Mapping of Zephyr architecture -> toolchain triple
+# Note only "posix" is supported at the moment.
+set(CROSS_COMPILE_TARGET_posix x86_64-pc-linux-gnu)
+
+set(CROSS_COMPILE_TARGET ${CROSS_COMPILE_TARGET_${ARCH}})
+
+set(CC clang)
+set(CROSS_COMPILE "/usr/bin/${CROSS_COMPILE_TARGET}-")