diff options
author | Behan Webster <behanw@converseincode.com> | 2013-09-03 22:27:23 -0400 |
---|---|---|
committer | Behan Webster <behanw@converseincode.com> | 2014-04-09 16:44:34 -0400 |
commit | 61163efae02040f66a95c8ed17f4407951ba58fa (patch) | |
tree | f4153900fa31a58ff6efeafc9db53b45cb71cfb4 /Makefile | |
parent | 39de65aa2c3eee901db020a4f1396998e09602a3 (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-- | Makefile | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -248,6 +248,11 @@ HOSTCXX = g++ | |||
248 | HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer | 248 | HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer |
249 | HOSTCXXFLAGS = -O2 | 249 | HOSTCXXFLAGS = -O2 |
250 | 250 | ||
251 | ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) | ||
252 | HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ | ||
253 | -Wno-missing-field-initializers -fno-delete-null-pointer-checks | ||
254 | endif | ||
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 | ||
325 | export quiet Q KBUILD_VERBOSE | 330 | export quiet Q KBUILD_VERBOSE |
326 | 331 | ||
332 | ifneq ($(CC),) | ||
333 | ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) | ||
334 | COMPILER := clang | ||
335 | else | ||
336 | COMPILER := gcc | ||
337 | endif | ||
338 | export COMPILER | ||
339 | endif | ||
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 |
329 | MAKEFLAGS += --include-dir=$(srctree) | 342 | MAKEFLAGS += --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,) |
387 | KBUILD_AFLAGS_KERNEL := | 400 | KBUILD_AFLAGS_KERNEL := |
388 | KBUILD_CFLAGS_KERNEL := | 401 | KBUILD_CFLAGS_KERNEL := |
389 | KBUILD_AFLAGS := -D__ASSEMBLY__ | 402 | KBUILD_AFLAGS := -D__ASSEMBLY__ |
@@ -623,9 +636,24 @@ endif | |||
623 | endif | 636 | endif |
624 | KBUILD_CFLAGS += $(stackp-flag) | 637 | KBUILD_CFLAGS += $(stackp-flag) |
625 | 638 | ||
639 | ifeq ($(COMPILER),clang) | ||
640 | KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) | ||
641 | KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,) | ||
642 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) | ||
643 | KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) | ||
644 | KBUILD_CFLAGS += $(call cc-disable-warning, gnu) | ||
645 | # Quiet clang warning: comparison of unsigned expression < 0 is always false | ||
646 | KBUILD_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 | ||
650 | KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,) | ||
651 | else | ||
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) |
628 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) | 655 | KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) |
656 | endif | ||
629 | 657 | ||
630 | ifdef CONFIG_FRAME_POINTER | 658 | ifdef CONFIG_FRAME_POINTER |
631 | KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls | 659 | KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls |