[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170410210904.68211-1-mka@chromium.org>
Date: Mon, 10 Apr 2017 14:09:04 -0700
From: Matthias Kaehlcke <mka@...omium.org>
To: Michal Marek <mmarek@...e.com>
Cc: linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
Behan Webster <behanw@...verseincode.com>,
Grant Grundler <grundler@...omium.org>,
Greg Hackmann <ghackmann@...gle.com>,
Michael Davidson <md@...gle.com>,
Peter Foley <pefoley2@...oley.com>,
Matthias Kaehlcke <mka@...omium.org>
Subject: [PATCH v2] kbuild: Add better clang cross build support
Add cross target to CC if using clang. Also add custom gcc toolchain
path for fallback gcc tools.
COMPILER is previously set to "clang" if CC=clang was set from the
make command line. So -target and -gcc-toolchain can be added to CC,
since we already know that it is set.
Clang will fallback to using things like ld, as, and libgcc if
(respectively) one of the llvm linkers isn't available, the integrated
assembler is turned off, or an appropriately cross-compiled version of
compiler-rt isn't available. To this end, you can specify the path to
this fallback gcc toolchain with GCC_TOOLCHAIN.
From: Behan Webster <behanw@...verseincode.com>
Signed-off-by: Behan Webster <behanw@...verseincode.com>
Reviewed-by: Jan-Simon Möller <dl9pf@....de>
Reviewed-by: Mark Charlebois <charlebm@...il.com>
Signed-off-by: Greg Hackmann <ghackmann@...gle.com>
Signed-off-by: Matthias Kaehlcke <mka@...omium.org>
---
Changes in v2:
- Fix GCC_TOOLCHAIN definition. $(LD) is needed to link the kernel, use
its path to determine the installation prefix of the toolchain.
(From: Greg Hackmann <ghackmann@...gle.com>)
Makefile | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index e11989d36c87..d3a02786bb53 100644
--- a/Makefile
+++ b/Makefile
@@ -375,6 +375,16 @@ LDFLAGS_vmlinux =
CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized
CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
+ifeq ($(cc-name),clang)
+ifneq ($(CROSS_COMPILE),)
+CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%))
+GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
+endif
+ifneq ($(GCC_TOOLCHAIN),)
+CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN)
+endif
+CLANG_FLAGS := $(CLANG_TARGET) $(CLANG_GCC_TC)
+endif
# Use USERINCLUDE when you must reference the UAPI directories only.
USERINCLUDE := \
@@ -395,18 +405,18 @@ LINUXINCLUDE := \
LINUXINCLUDE += $(filter-out $(LINUXINCLUDE),$(USERINCLUDE))
-KBUILD_CPPFLAGS := -D__KERNEL__
+KBUILD_CPPFLAGS := -D__KERNEL__ $(CLANG_FLAGS)
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-Werror-implicit-function-declaration \
-Wno-format-security \
- -std=gnu89 $(call cc-option,-fno-PIE)
-
+ -std=gnu89 $(call cc-option,-fno-PIE) \
+ $(CLANG_FLAGS)
KBUILD_AFLAGS_KERNEL :=
KBUILD_CFLAGS_KERNEL :=
-KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE)
+KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE) $(CLANG_FLAGS)
KBUILD_AFLAGS_MODULE := -DMODULE
KBUILD_CFLAGS_MODULE := -DMODULE
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
--
2.12.2.715.g7642488e1d-goog
Powered by blists - more mailing lists