From: Matthias Kaehlcke <mka@chromium.org>
To: Michal Marek <mmarek@suse.com>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
Behan Webster <behanw@converseincode.com>,
Grant Grundler <grundler@chromium.org>,
Greg Hackmann <ghackmann@google.com>,
Michael Davidson <md@google.com>,
Peter Foley <pefoley2@pefoley.com>,
Matthias Kaehlcke <mka@chromium.org>
Subject: [PATCH] kbuild: Add better clang cross build support
Date: Fri, 24 Mar 2017 17:02:48 -0700 [thread overview]
Message-ID: <20170325000248.101855-1-mka@chromium.org> (raw)
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@converseincode.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
Reviewed-by: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Makefile | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index b2faa9319372..b0f6ef67028d 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 := $(dir $(CROSS_COMPILE))
+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.1.578.ge9c3154ca4-goog
reply other threads:[~2017-03-25 0:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170325000248.101855-1-mka@chromium.org \
--to=mka@chromium.org \
--cc=behanw@converseincode.com \
--cc=ghackmann@google.com \
--cc=grundler@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=md@google.com \
--cc=mmarek@suse.com \
--cc=pefoley2@pefoley.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®