aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBehan Webster2013-09-03 21:27:23 -0500
committerBehan Webster2014-04-09 15:44:34 -0500
commit61163efae02040f66a95c8ed17f4407951ba58fa (patch)
treef4153900fa31a58ff6efeafc9db53b45cb71cfb4 /Makefile
parent39de65aa2c3eee901db020a4f1396998e09602a3 (diff)
downloadlinux-phy-61163efae02040f66a95c8ed17f4407951ba58fa.tar.gz
linux-phy-61163efae02040f66a95c8ed17f4407951ba58fa.tar.xz
linux-phy-61163efae02040f66a95c8ed17f4407951ba58fa.zip
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 cf3e07516a04..10812e495e8d 100644
--- a/Makefile
+++ b/Makefile
@@ -248,6 +248,11 @@ HOSTCXX = g++
248HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer 248HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
249HOSTCXXFLAGS = -O2 249HOSTCXXFLAGS = -O2
250 250
251ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
252HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
253 -Wno-missing-field-initializers -fno-delete-null-pointer-checks
254endif
255
251# Decide whether to build built-in, modular, or both. 256# Decide whether to build built-in, modular, or both.
252# Normally, just do built-in. 257# Normally, just do built-in.
253 258
@@ -324,6 +329,14 @@ endif
324 329
325export quiet Q KBUILD_VERBOSE 330export quiet Q KBUILD_VERBOSE
326 331
332ifneq ($(CC),)
333ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
334COMPILER := clang
335else
336COMPILER := gcc
337endif
338export COMPILER
339endif
327 340
328# Look for make include files relative to root of kernel src 341# Look for make include files relative to root of kernel src
329MAKEFLAGS += --include-dir=$(srctree) 342MAKEFLAGS += --include-dir=$(srctree)
@@ -383,7 +396,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
383 -fno-strict-aliasing -fno-common \ 396 -fno-strict-aliasing -fno-common \
384 -Werror-implicit-function-declaration \ 397 -Werror-implicit-function-declaration \
385 -Wno-format-security \ 398 -Wno-format-security \
386 -fno-delete-null-pointer-checks 399 $(call cc-option,-fno-delete-null-pointer-checks,)
387KBUILD_AFLAGS_KERNEL := 400KBUILD_AFLAGS_KERNEL :=
388KBUILD_CFLAGS_KERNEL := 401KBUILD_CFLAGS_KERNEL :=
389KBUILD_AFLAGS := -D__ASSEMBLY__ 402KBUILD_AFLAGS := -D__ASSEMBLY__
@@ -623,9 +636,24 @@ endif
623endif 636endif
624KBUILD_CFLAGS += $(stackp-flag) 637KBUILD_CFLAGS += $(stackp-flag)
625 638
639ifeq ($(COMPILER),clang)
640KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
641KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
642KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
643KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
644KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
645# Quiet clang warning: comparison of unsigned expression < 0 is always false
646KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
647# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
648# source of a reference will be _MergedGlobals and not on of the whitelisted names.
649# See modpost pattern 2
650KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
651else
652
626# This warning generated too much noise in a regular build. 653# This warning generated too much noise in a regular build.
627# Use make W=1 to enable this warning (see scripts/Makefile.build) 654# Use make W=1 to enable this warning (see scripts/Makefile.build)
628KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 655KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
656endif
629 657
630ifdef CONFIG_FRAME_POINTER 658ifdef CONFIG_FRAME_POINTER
631KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 659KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls