aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-04-12 20:00:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-12 20:00:40 -0400
commit09c9b61d5da24174b867a6ffda29b7435e1fda74 (patch)
tree89f5775bfeb0305f3b87a97c488b7e8347294821
parent141eaccd018ef0476e94b180026d973db35460fd (diff)
parentc4586256f0c440bc2bdb29d2cbb915f0ca785d26 (diff)
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
-rw-r--r--Documentation/dontdiff3
-rw-r--r--Makefile30
-rw-r--r--arch/x86/Makefile2
-rw-r--r--include/asm-generic/cmpxchg-local.h3
-rw-r--r--include/linux/compiler-clang.h12
-rw-r--r--include/linux/compiler.h7
-rw-r--r--include/linux/mod_devicetable.h5
-rw-r--r--scripts/Makefile.build12
-rwxr-xr-xscripts/mkcompile_h2
9 files changed, 71 insertions, 5 deletions
diff --git a/Documentation/dontdiff b/Documentation/dontdiff
index b89a739a3276..9de9813d0ec5 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -1,5 +1,6 @@
1*.a 1*.a
2*.aux 2*.aux
3*.bc
3*.bin 4*.bin
4*.bz2 5*.bz2
5*.cis 6*.cis
@@ -21,6 +22,7 @@
21*.i 22*.i
22*.jpeg 23*.jpeg
23*.ko 24*.ko
25*.ll
24*.log 26*.log
25*.lst 27*.lst
26*.lzma 28*.lzma
@@ -35,6 +37,7 @@
35*.out 37*.out
36*.patch 38*.patch
37*.pdf 39*.pdf
40*.plist
38*.png 41*.png
39*.pot 42*.pot
40*.ps 43*.ps
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
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 3b9348a0c1a4..602f57e590b5 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -108,7 +108,7 @@ else
108 108
109 # this works around some issues with generating unwind tables in older gccs 109 # this works around some issues with generating unwind tables in older gccs
110 # newer gccs do it by default 110 # newer gccs do it by default
111 KBUILD_CFLAGS += -maccumulate-outgoing-args 111 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
112endif 112endif
113 113
114# Make sure compiler does not have buggy stack-protector support. 114# Make sure compiler does not have buggy stack-protector support.
diff --git a/include/asm-generic/cmpxchg-local.h b/include/asm-generic/cmpxchg-local.h
index d8d4c898c1bb..70bef78912b7 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -4,7 +4,8 @@
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/irqflags.h> 5#include <linux/irqflags.h>
6 6
7extern unsigned long wrong_size_cmpxchg(volatile void *ptr); 7extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
8 __noreturn;
8 9
9/* 10/*
10 * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned 11 * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
new file mode 100644
index 000000000000..d1e49d52b640
--- /dev/null
+++ b/include/linux/compiler-clang.h
@@ -0,0 +1,12 @@
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
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 2472740d7ab2..ee7239ea1583 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -63,6 +63,13 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63# include <linux/compiler-intel.h> 63# include <linux/compiler-intel.h>
64#endif 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 * Generic compiler-dependent macros required for kernel 74 * Generic compiler-dependent macros required for kernel
68 * build go below this comment. Actual compiler/compiler version 75 * build go below this comment. Actual compiler/compiler version
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 9a165a213d93..44eeef0da186 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -556,6 +556,11 @@ struct amba_id {
556 * See documentation of "x86_match_cpu" for details. 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
559struct x86_cpu_id { 564struct x86_cpu_id {
560 __u16 vendor; 565 __u16 vendor;
561 __u16 family; 566 __u16 family;
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 9f0ee22b914f..003bc263105a 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -65,12 +65,22 @@ warning- := $(empty)
65warning-1 := -Wextra -Wunused -Wno-unused-parameter 65warning-1 := -Wextra -Wunused -Wno-unused-parameter
66warning-1 += -Wmissing-declarations 66warning-1 += -Wmissing-declarations
67warning-1 += -Wmissing-format-attribute 67warning-1 += -Wmissing-format-attribute
68warning-1 += -Wmissing-prototypes 68warning-1 += $(call cc-option, -Wmissing-prototypes)
69warning-1 += -Wold-style-definition 69warning-1 += -Wold-style-definition
70warning-1 += $(call cc-option, -Wmissing-include-dirs) 70warning-1 += $(call cc-option, -Wmissing-include-dirs)
71warning-1 += $(call cc-option, -Wunused-but-set-variable) 71warning-1 += $(call cc-option, -Wunused-but-set-variable)
72warning-1 += $(call cc-disable-warning, missing-field-initializers) 72warning-1 += $(call cc-disable-warning, missing-field-initializers)
73 73
74# Clang
75warning-1 += $(call cc-disable-warning, initializer-overrides)
76warning-1 += $(call cc-disable-warning, unused-value)
77warning-1 += $(call cc-disable-warning, format)
78warning-1 += $(call cc-disable-warning, unknown-warning-option)
79warning-1 += $(call cc-disable-warning, sign-compare)
80warning-1 += $(call cc-disable-warning, format-zero-length)
81warning-1 += $(call cc-disable-warning, uninitialized)
82warning-1 += $(call cc-option, -fcatch-undefined-behavior)
83
74warning-2 := -Waggregate-return 84warning-2 := -Waggregate-return
75warning-2 += -Wcast-align 85warning-2 += -Wcast-align
76warning-2 += -Wdisabled-optimization 86warning-2 += -Wdisabled-optimization
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index f221ddf69080..cfb8440cc0b2 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -76,7 +76,7 @@ UTS_TRUNCATE="cut -b -$UTS_LEN"
76 echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\" 76 echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
77 echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\" 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) > .tmpcompile 80) > .tmpcompile
81 81
82# Only replace the real compile.h if the new one is different, 82# Only replace the real compile.h if the new one is different,