aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorBehan Webster <behanw@converseincode.com>2013-09-03 22:27:23 -0400
committerBehan Webster <behanw@converseincode.com>2014-03-31 00:07:17 -0700
commit24447ae381b1ebc29aa0c141cd1b4e39b12618d4 (patch)
tree51e21aee013421db512b4d6552be44513a932692 /Makefile
parent455c6fdbd219161bd09b1165f11699d6d73de11c (diff)
kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
Add support to toplevel Makefile for compiling with clang, both for HOSTCC and CC. Use cc-option to prevent gcc option from breaking clang, and from clang options from breaking gcc. Clang 3.4 semantics are the same as gcc semantics for unsupported flags. For unsupported warnings clang 3.4 returns true but shows a warning and gcc shows a warning and returns false. Signed-off-by: Behan Webster <behanw@converseincode.com> Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de> Signed-off-by: Mark Charlebois <charlebm@gmail.com> Cc: PaX Team <pageexec@freemail.hu>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile30
1 files changed, 29 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index e5ac8a62e6e..67e0ba35c73 100644
--- a/Makefile
+++ b/Makefile
@@ -247,6 +247,11 @@ HOSTCXX = g++
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
+ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
+HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
+ -Wno-missing-field-initializers -fno-delete-null-pointer-checks
+endif
+
# Decide whether to build built-in, modular, or both.
# Normally, just do built-in.
@@ -323,6 +328,14 @@ endif
export quiet Q KBUILD_VERBOSE
+ifneq ($(CC),)
+ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
+COMPILER := clang
+else
+COMPILER := gcc
+endif
+export COMPILER
+endif
# Look for make include files relative to root of kernel src
MAKEFLAGS += --include-dir=$(srctree)
@@ -382,7 +395,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-Werror-implicit-function-declaration \
-Wno-format-security \
- -fno-delete-null-pointer-checks
+ $(call cc-option,-fno-delete-null-pointer-checks,)
KBUILD_AFLAGS_KERNEL :=
KBUILD_CFLAGS_KERNEL :=
KBUILD_AFLAGS := -D__ASSEMBLY__
@@ -622,9 +635,24 @@ endif
endif
KBUILD_CFLAGS += $(stackp-flag)
+ifeq ($(COMPILER),clang)
+KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
+KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
+KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
+KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
+# Quiet clang warning: comparison of unsigned expression < 0 is always false
+KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
+# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
+# source of a reference will be _MergedGlobals and not on of the whitelisted names.
+# See modpost pattern 2
+KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
+else
+
# This warning generated too much noise in a regular build.
# Use make W=1 to enable this warning (see scripts/Makefile.build)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
+endif
ifdef CONFIG_FRAME_POINTER
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls