Commit 09c9b61d5da24174b867a6ffda29b7435e1fda74

Authored by Linus Torvalds

Merge tag 'llvmlinux-for-v3.15' of git://git.linuxfoundation.org/llvmlinux/kernel

Pull llvm patches from Behan Webster:
 "These are some initial updates to support compiling the kernel with
  clang.

  These patches have been through the proper reviews to the best of my
  ability, and have been soaking in linux-next for a few weeks.  These
  patches by themselves still do not completely allow clang to be used
  with the kernel code, but lay the foundation for other patches which
  are still under review.

  Several other of the LLVMLinux patches have been already added via
  maintainer trees"

* tag 'llvmlinux-for-v3.15' of git://git.linuxfoundation.org/llvmlinux/kernel:
  x86: LLVMLinux: Fix "incomplete type const struct x86cpu_device_id"
  x86 kbuild: LLVMLinux: More cc-options added for clang
  x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
  LLVMLinux: Add support for clang to compiler.h and new compiler-clang.h
  LLVMLinux: Remove warning about returning an uninitialized variable
  kbuild: LLVMLinux: Fix LINUX_COMPILER definition script for compilation with clang
  Documentation: LLVMLinux: Update Documentation/dontdiff
  kbuild: LLVMLinux: Adapt warnings for compilation with clang
  kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang

Showing 9 changed files Side-by-side Diff

Documentation/dontdiff
1 1 *.a
2 2 *.aux
  3 +*.bc
3 4 *.bin
4 5 *.bz2
5 6 *.cis
... ... @@ -21,6 +22,7 @@
21 22 *.i
22 23 *.jpeg
23 24 *.ko
  25 +*.ll
24 26 *.log
25 27 *.lst
26 28 *.lzma
... ... @@ -35,6 +37,7 @@
35 37 *.out
36 38 *.patch
37 39 *.pdf
  40 +*.plist
38 41 *.png
39 42 *.pot
40 43 *.ps
... ... @@ -248,6 +248,11 @@
248 248 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
249 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 256 # Decide whether to build built-in, modular, or both.
252 257 # Normally, just do built-in.
253 258  
... ... @@ -324,6 +329,14 @@
324 329  
325 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 341 # Look for make include files relative to root of kernel src
329 342 MAKEFLAGS += --include-dir=$(srctree)
... ... @@ -383,7 +396,7 @@
383 396 -fno-strict-aliasing -fno-common \
384 397 -Werror-implicit-function-declaration \
385 398 -Wno-format-security \
386   - -fno-delete-null-pointer-checks
  399 + $(call cc-option,-fno-delete-null-pointer-checks,)
387 400 KBUILD_AFLAGS_KERNEL :=
388 401 KBUILD_CFLAGS_KERNEL :=
389 402 KBUILD_AFLAGS := -D__ASSEMBLY__
390 403  
... ... @@ -623,9 +636,24 @@
623 636 endif
624 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 653 # This warning generated too much noise in a regular build.
627 654 # Use make W=1 to enable this warning (see scripts/Makefile.build)
628 655 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
  656 +endif
629 657  
630 658 ifdef CONFIG_FRAME_POINTER
631 659 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
... ... @@ -108,7 +108,7 @@
108 108  
109 109 # this works around some issues with generating unwind tables in older gccs
110 110 # newer gccs do it by default
111   - KBUILD_CFLAGS += -maccumulate-outgoing-args
  111 + KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
112 112 endif
113 113  
114 114 # Make sure compiler does not have buggy stack-protector support.
include/asm-generic/cmpxchg-local.h
... ... @@ -4,7 +4,8 @@
4 4 #include <linux/types.h>
5 5 #include <linux/irqflags.h>
6 6  
7   -extern unsigned long wrong_size_cmpxchg(volatile void *ptr);
  7 +extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
  8 + __noreturn;
8 9  
9 10 /*
10 11 * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
include/linux/compiler-clang.h
  1 +#ifndef __LINUX_COMPILER_H
  2 +#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
  3 +#endif
  4 +
  5 +/* Some compiler specific definitions are overwritten here
  6 + * for Clang compiler
  7 + */
  8 +
  9 +#ifdef uninitialized_var
  10 +#undef uninitialized_var
  11 +#define uninitialized_var(x) x = *(&(x))
  12 +#endif
include/linux/compiler.h
... ... @@ -63,6 +63,13 @@
63 63 # include <linux/compiler-intel.h>
64 64 #endif
65 65  
  66 +/* Clang compiler defines __GNUC__. So we will overwrite implementations
  67 + * coming from above header files here
  68 + */
  69 +#ifdef __clang__
  70 +#include <linux/compiler-clang.h>
  71 +#endif
  72 +
66 73 /*
67 74 * Generic compiler-dependent macros required for kernel
68 75 * build go below this comment. Actual compiler/compiler version
include/linux/mod_devicetable.h
... ... @@ -556,6 +556,11 @@
556 556 * See documentation of "x86_match_cpu" for details.
557 557 */
558 558  
  559 +/*
  560 + * MODULE_DEVICE_TABLE expects this struct to be called x86cpu_device_id.
  561 + * Although gcc seems to ignore this error, clang fails without this define.
  562 + */
  563 +#define x86cpu_device_id x86_cpu_id
559 564 struct x86_cpu_id {
560 565 __u16 vendor;
561 566 __u16 family;
scripts/Makefile.build
... ... @@ -65,11 +65,21 @@
65 65 warning-1 := -Wextra -Wunused -Wno-unused-parameter
66 66 warning-1 += -Wmissing-declarations
67 67 warning-1 += -Wmissing-format-attribute
68   -warning-1 += -Wmissing-prototypes
  68 +warning-1 += $(call cc-option, -Wmissing-prototypes)
69 69 warning-1 += -Wold-style-definition
70 70 warning-1 += $(call cc-option, -Wmissing-include-dirs)
71 71 warning-1 += $(call cc-option, -Wunused-but-set-variable)
72 72 warning-1 += $(call cc-disable-warning, missing-field-initializers)
  73 +
  74 +# Clang
  75 +warning-1 += $(call cc-disable-warning, initializer-overrides)
  76 +warning-1 += $(call cc-disable-warning, unused-value)
  77 +warning-1 += $(call cc-disable-warning, format)
  78 +warning-1 += $(call cc-disable-warning, unknown-warning-option)
  79 +warning-1 += $(call cc-disable-warning, sign-compare)
  80 +warning-1 += $(call cc-disable-warning, format-zero-length)
  81 +warning-1 += $(call cc-disable-warning, uninitialized)
  82 +warning-1 += $(call cc-option, -fcatch-undefined-behavior)
73 83  
74 84 warning-2 := -Waggregate-return
75 85 warning-2 += -Wcast-align
... ... @@ -76,7 +76,7 @@
76 76 echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
77 77 echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
78 78  
79   - echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
  79 + echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version '`\"
80 80 ) > .tmpcompile
81 81  
82 82 # Only replace the real compile.h if the new one is different,