kbuild: LLVMLinux: Initial updates to kbuild to enable the kernel to be compiled with clang/LLVM
Subsystems (4)
cover kbuild: LLVMLinux: Initial updates to kbuild to enable the kernel to be compiled with clang/LLVM
From: Behan Webster <[email protected]>
These patches add initial support for compiling the x86 kernel with clang. More patches to the kernel code are required to actually compile the kernel with clang. The intent of these patches are just to get things started with kbuild.
The LLVMLinux project aims to fully build the Linux kernel using both gcc and clang (the C front end for the LLVM compiler infrastructure project).
Behan Webster (1):
kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
Jan-Simon Möller (3):
kbuild: LLVMLinux: Adapt warnings for compilation with clang
kbuild: LLVMLinux: Fix LINUX_COMPILER definition script for
compilation with clang
x86 kbuild: LLVMLinux: More cc-options added for clang
Mark Charlebois (1):
LLVMLinux: Add support for clang to compiler.h and new
compiler-clang.h
Makefile | 32 +++++++++++++++++++++++++++++++- arch/x86/Makefile | 8 +++++++- include/linux/compiler-clang.h | 12 ++++++++++++ include/linux/compiler.h | 7 +++++++ scripts/Makefile.build | 13 ++++++++++++- scripts/mkcompile_h | 2 +- 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 include/linux/compiler-clang.h
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/5 kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
From: Behan Webster <[email protected]>
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.
--- Makefile | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
Makefile +31 -1
@@ -247,6 +247,15 @@ 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) +HOSTCOMPILER := clang +HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-delete-null-pointer-checks +else +HOSTCOMPILER := gcc +endif +export HOSTCOMPILER + # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
@@ -323,6 +332,12 @@ endif export quiet Q KBUILD_VERBOSE +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILER # Look for make include files relative to root of kernel src MAKEFLAGS += --include-dir=$(srctree)
@@ -382,7 +397,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__
@@ -620,9 +635,24 @@ else 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
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
Quoted 24 lines · On Tue, Feb 25, 2014 at 05:08:39PM -0800, [email protected] wrote:
From: Behan Webster <[email protected]>
Add support to toplevel
Makefilefor 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 <[email protected]>Signed-off-by Jan-Simon Möller <[email protected]>Signed-off-by Mark Charlebois <[email protected]>Cc PaX Team <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)Makefile +0
-0@@ -247,6 +247,15 @@ HOSTCXX = g++ HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
Makefile HOSTCXX = g++ · line 257
Quoted 10 lines
Makefile +8
-0HOSTCXXFLAGS = -O2 +ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) +HOSTCOMPILER := clang +HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-delete-null-pointer-checks +else +HOSTCOMPILER := gcc +endif +export HOSTCOMPILER
I see no use of HOSTCOMPLIER anywhere in this patchset not in the kernel. Can we drop this?
Quoted 5 lines
Makefile +1
-0+ # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
Makefile endif · line 340
Quoted 9 lines
Makefile +6
-0@@ -323,6 +332,12 @@ endif export quiet Q KBUILD_VERBOSE +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILER
Likewise - COMPILER seems unsued- can it be dropped?
Quoted 13 lines
Makefile +1
-1# Look for make include files relative to root of kernel src MAKEFLAGS += --include-dir=$(srctree)@@ -382,7 +397,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__
Makefile else · line 638
Quoted 4 lines
Makefile +1
-0@@ -620,9 +635,24 @@ else endif KBUILD_CFLAGS += $(stackp-flag) +ifeq ($(COMPILER),clang)
Except that COMPILER is used here. But this does not warrant the export.
Makefile else · line 639
Quoted 1 line
Makefile +1
-0+KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
Is this really needed today?
https://bugzilla.mozilla.org/show_bug.cgi?id=717713 suggest that this is default.
Makefile else · line 640
Quoted 1 line
Makefile +1
-0+KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
https://bugzilla.mozilla.org/show_bug.cgi?id=731316 seems to suggest this is default
Makefile else · line 643
Quoted 3 lines
Makefile +3
-0+KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) +KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
Is it really justified to disable these warnings?
# of warnign for a defconfig build would be a nice figure to judge from.
Makefile else · line 645
Quoted 2 lines
Makefile +2
-0+# Quiet clang warning: comparison of unsigned expression < 0 is always false +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
Same with this.
Makefile else · line 649
Quoted 4 lines
Makefile +4
-0+# 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,)
Should we fix modpost?
Sam
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
Quoted 27 lines · Sam Ravnborg
Quoted 26 lines · On Tue, Feb 25, 2014 at 05:08:39PM -0800, [email protected] wrote:
From: Behan Webster <[email protected]>
Add support to toplevel
Makefilefor 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 <[email protected]>Signed-off-by Jan-Simon Möller <[email protected]>Signed-off-by Mark Charlebois <[email protected]>Cc PaX Team <[email protected]>--- Makefile | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)Makefile +0
-0@@ -247,6 +247,15 @@ HOSTCXX = g++ HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer HOSTCXXFLAGS = -O2
Quoted 9 lines
Makefile HOSTCXX = g++ · line 257
Quoted 8 lines
Makefile +8
-0+ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) +HOSTCOMPILER := clang +HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-delete-null-pointer-checks +else +HOSTCOMPILER := gcc +endif +export HOSTCOMPILERI see no use of HOSTCOMPLIER anywhere in this patchset not in the kernel. Can we drop this?
Actually, we're not using it anymore, though we were at one point. We'll drop it.
Quoted 8 lines
Quoted 8 lines
Makefile +1
-0+ # Decide whether to build built-in, modular, or both. # Normally, just do built-in.@@ -323,6 +332,12 @@ endif export quiet Q KBUILD_VERBOSE
Quoted 7 lines
Makefile endif · line 340
Quoted 6 lines
Makefile +6
-0+ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILERLikewise - COMPILER seems unsued- can it be dropped?
We use COMPILER a lot in upcoming patches. :(
It's here in order to be available early so that the other patches can use it. I hope that's okay.
Quoted 15 lines
Quoted 15 lines
Makefile +1
-1# Look for make include files relative to root of kernel src MAKEFLAGS += --include-dir=$(srctree)@@ -382,7 +397,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__@@ -620,9 +635,24 @@ else endif KBUILD_CFLAGS += $(stackp-flag)
Quoted 2 lines
Makefile else · line 638
Quoted 1 line
Makefile +1
-0+ifeq ($(COMPILER),clang)Except that COMPILER is used here. But this does not warrant the export.
Like I said. It is used in at least 4 other patches which are unrelated to kbuild... Well, okay, one in the arm portion of kbuild.
I don't actually like using it, and would prefer not to, but we needed the equivalent of an "#ifdef __clang__" in the Makefiles for various reasons. :(
Quoted 6 lines
Makefile else · line 639
Quoted 1 line
Makefile +1
-0+KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)Is this really needed today?
https://bugzilla.mozilla.org/show_bug.cgi?id=717713 suggest that this is default.Makefile else · line 640
Quoted 1 line
Makefile +1
-0+KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)https://bugzilla.mozilla.org/show_bug.cgi?id=731316 seems to suggest this is default
These haven't always been the defaults. I will check on when they became defaults, retest, and reply back.
Though thanks for pointing this out! Very thorough. :)
Quoted 5 lines
Makefile else · line 643
Quoted 3 lines
Makefile +3
-0+KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) +KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier) +KBUILD_CFLAGS += $(call cc-disable-warning, gnu)Is it really justified to disable these warnings?
# of warnign for a defconfig build would be a nice figure to judge from.
To be honest, the number one complaint we get from kernel devs who've tried clang is that there are too many warnings. We don't want to turn them off, but merely to stem the tide for now so as not to put people off. The idea is to turn them on once we've had time to address the warnings more fully. I'd quite like to see all (most) of the clang warnings on by default eventually. Does that make sense?
However, the unused-variable warning will likely need to stay on IMHO. There are quite a few things in the kernel which create variables which are intended to be optimized away (last I checked). gcc doesn't complain about this, but clang get's very noisy about it.
Though if the consensus is to have more warnings on by default, I'm happy to oblige.
Quoted 3 lines
Makefile else · line 645
Quoted 2 lines
Makefile +2
-0+# Quiet clang warning: comparison of unsigned expression < 0 is always false +KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)Same with this.
Actually, if is my understanding that comparing signed and unsigned values are considered valid in the kernel code. Certainly I've seen many patches rejected which were trying to fix "tautological compare errors".
Quoted 5 lines
Makefile else · line 649
Quoted 4 lines
Makefile +4
-0+# 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,)Should we fix modpost?
We looked at doing this, but the symbol name compares in modpost seem like a Good Idea (tm). By using _MergedGlobals you lose information which modpost relies on. I think modpost can catch more potential problems by not using clang merged globals. But I'll easily be swayed by someone who knows better. :)
Thanks for the feedback,
Behan
Signature · 2 lines
Behan Webster [email protected]
PATCH v2 1/5 kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang
In reply to Sam RavnborgFrom: Behan Webster <[email protected]>
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.
--- Makefile | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
Makefile +27 -1
@@ -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,12 @@ endif export quiet Q KBUILD_VERBOSE +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +else +COMPILER := gcc +endif +export COMPILER # Look for make include files relative to root of kernel src MAKEFLAGS += --include-dir=$(srctree)
@@ -382,7 +393,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 +633,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
Signature · 1 line
1.8.3.2
PATCH 2/5 kbuild: LLVMLinux: Adapt warnings for compilation with clang
In reply to [email protected]From: Jan-Simon Möller <[email protected]>
When compiling kernel with clang, disable warnings which are too noisy, and add the clang flag catch-undefined-behavior.
--- scripts/Makefile.build | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
scripts/Makefile.build +12 -1
@@ -65,12 +65,23 @@ warning- := $(empty) warning-1 := -Wextra -Wunused -Wno-unused-parameter warning-1 += -Wmissing-declarations warning-1 += -Wmissing-format-attribute -warning-1 += -Wmissing-prototypes +warning-1 += $(call cc-option, -Wmissing-prototypes) warning-1 += -Wold-style-definition warning-1 += $(call cc-option, -Wmissing-include-dirs) warning-1 += $(call cc-option, -Wunused-but-set-variable) warning-1 += $(call cc-disable-warning, missing-field-initializers) +# Clang +warning-1 += $(call cc-disable-warning, initializer-overrides) +warning-1 += $(call cc-disable-warning, unused-value) +warning-1 += $(call cc-disable-warning, format) +warning-1 += $(call cc-disable-warning, unknown-warning-option) +warning-1 += $(call cc-disable-warning, self-assign) +warning-1 += $(call cc-disable-warning, sign-compare) +warning-1 += $(call cc-disable-warning, format-zero-length) +warning-1 += $(call cc-disable-warning, uninitialized) +warning-1 += $(call cc-option, -fcatch-undefined-behavior) + warning-2 := -Waggregate-return warning-2 += -Wcast-align warning-2 += -Wdisabled-optimization
Signature · 1 line
1.8.3.2
Re: [PATCH 2/5] kbuild: LLVMLinux: Adapt warnings for compilation with clang
scripts/Makefile.build warning- := $(empty) · line 83
Quoted 13 lines · On Tue, Feb 25, 2014 at 05:08:40PM -0800, [email protected] wrote:
When compiling kernel with clang, disable warnings which are too noisy, and add the clang flag catch-undefined-behavior.
scripts/Makefile.build +10
-0+# Clang +warning-1 += $(call cc-disable-warning, initializer-overrides) +warning-1 += $(call cc-disable-warning, unused-value) +warning-1 += $(call cc-disable-warning, format) +warning-1 += $(call cc-disable-warning, unknown-warning-option) +warning-1 += $(call cc-disable-warning, self-assign) +warning-1 += $(call cc-disable-warning, sign-compare) +warning-1 += $(call cc-disable-warning, format-zero-length) +warning-1 += $(call cc-disable-warning, uninitialized) +warning-1 += $(call cc-option, -fcatch-undefined-behavior)
Do you have a pointer to an example log-file from before this change ? I'm curious for eg, which self-assign warnings are showing up, because I've been fixing up the ones that Coverity found, of which there are only a dozen or so left iirc.
Some of the others may also be interesting.
Dave
Re: [PATCH 2/5] kbuild: LLVMLinux: Adapt warnings for compilation with clang
Quoted 9 lines · Dave Jones
Quoted 1 line · On Tue, Feb 25, 2014 at 05:08:40PM -0800, [email protected] wrote:
+warning-1 += $(call cc-disable-warning, self-assign)
Do you have a pointer to an example log-file from before this change ? I'm curious for eg, which self-assign warnings are showing up, because I've been fixing up the ones that Coverity found, of which there are only a dozen or so left iirc.
Some of the others may also be interesting.
I don't have one now, but I can generate a log and send it to you. We've had that option set from near the beginning of the porting effort.
This are primarily off due to the amount of noise these warnings produce at this time (clang produces a LOT of warnings straight out of the box). I'd love to eventually turn some of these back on again.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]
H. Peter Anvin
reviewerRe: [PATCH 2/5] kbuild: LLVMLinux: Adapt warnings for compilation with clang
Quoted 5 lines · Behan Webster
This are primarily off due to the amount of noise these warnings produce at this time (clang produces a LOT of warnings straight out of the box). I'd love to eventually turn some of these back on again.
It would also be nice if someone would be willing to look at the sparse warnings the kernel output -- there are tens of thousands of them it seems, although some are from header files.
-hpa
Re: [PATCH 2/5] kbuild: LLVMLinux: Adapt warnings for compilation with clang
In reply to Dave JonesQuoted 5 lines · Dave Jones
Quoted 3 lines · On Tue, Feb 25, 2014 at 05:08:40PM -0800, [email protected] wrote:
When compiling kernel with clang, disable warnings which are too noisy, and add the clang flag catch-undefined-behavior.
Quoted 15 lines
scripts/Makefile.build warning- := $(empty) · line 83
Quoted 10 lines
scripts/Makefile.build +10
-0+# Clang +warning-1 += $(call cc-disable-warning, initializer-overrides) +warning-1 += $(call cc-disable-warning, unused-value) +warning-1 += $(call cc-disable-warning, format) +warning-1 += $(call cc-disable-warning, unknown-warning-option) +warning-1 += $(call cc-disable-warning, self-assign) +warning-1 += $(call cc-disable-warning, sign-compare) +warning-1 += $(call cc-disable-warning, format-zero-length) +warning-1 += $(call cc-disable-warning, uninitialized) +warning-1 += $(call cc-option, -fcatch-undefined-behavior)Do you have a pointer to an example log-file from before this change ? I'm curious for eg, which self-assign warnings are showing up, because I've been fixing up the ones that Coverity found, of which there are only a dozen or so left iirc.
I count 22 in this particular x86 kernel build (some of which you may well have fixed already). Enjoy.
http://buildbot.llvm.linuxfoundation.org/self-assign-build.log.txt
Perhaps I should re-enable that warning, considering the number has dropped so dramatically from when I last checked over a year ago.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]
PATCH v2 2/5 kbuild: LLVMLinux: Adapt warnings for compilation with clang
In reply to [email protected]From: Jan-Simon Möller <[email protected]>
When compiling kernel with clang, disable warnings which are too noisy, and add the clang flag catch-undefined-behavior.
Re-enable warnings for self-assigns due to David Jones removing most of them already from the kernel code base.
--- scripts/Makefile.build | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
scripts/Makefile.build +11 -1
@@ -65,12 +65,22 @@ warning- := $(empty) warning-1 := -Wextra -Wunused -Wno-unused-parameter warning-1 += -Wmissing-declarations warning-1 += -Wmissing-format-attribute -warning-1 += -Wmissing-prototypes +warning-1 += $(call cc-option, -Wmissing-prototypes) warning-1 += -Wold-style-definition warning-1 += $(call cc-option, -Wmissing-include-dirs) warning-1 += $(call cc-option, -Wunused-but-set-variable) warning-1 += $(call cc-disable-warning, missing-field-initializers) +# Clang +warning-1 += $(call cc-disable-warning, initializer-overrides) +warning-1 += $(call cc-disable-warning, unused-value) +warning-1 += $(call cc-disable-warning, format) +warning-1 += $(call cc-disable-warning, unknown-warning-option) +warning-1 += $(call cc-disable-warning, sign-compare) +warning-1 += $(call cc-disable-warning, format-zero-length) +warning-1 += $(call cc-disable-warning, uninitialized) +warning-1 += $(call cc-option, -fcatch-undefined-behavior) + warning-2 := -Waggregate-return warning-2 += -Wcast-align warning-2 += -Wdisabled-optimization
Signature · 1 line
1.8.3.2
PATCH 3/5 kbuild: LLVMLinux: Fix LINUX_COMPILER definition script for compilation with clang
In reply to [email protected]From: Jan-Simon Möller <[email protected]>
When building the LINUX_COMPILER definition, instead of merely taking the last line from "$(CC) -v", grep for ' version ' in the output. This supports both gcc and clang.
--- scripts/mkcompile_h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mkcompile_h +1 -1
@@ -76,7 +76,7 @@ UTS_TRUNCATE="cut -b -$UTS_LEN" echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\" echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\" - echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" + echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version '`\" ) > .tmpcompile # Only replace the real compile.h if the new one is different,
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/5 LLVMLinux: Add support for clang to compiler.h and new compiler-clang.h
In reply to [email protected]From: Mark Charlebois <[email protected]>
Add a compiler-clang.h file to add specific macros needed for compiling the kernel with clang.
Initially the only override required is the macro for silencing the compiler for a purposefully uninintialized variable.
Author: Mark Charlebois <[email protected]>
--- include/linux/compiler-clang.h | 12 ++++++++++++ include/linux/compiler.h | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 include/linux/compiler-clang.h
include/linux/compiler-clang.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef __LINUX_COMPILER_H +#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead." +#endif + +/* Some compiler specific definitions are overwritten here +* for Clang compiler +*/ + +#ifdef uninitialized_var +#undef uninitialized_var +#define uninitialized_var (x) x = *(&(x)) +#endif
include/linux/compiler.h +7 -0
@@ -63,6 +63,13 @@ extern void __chk_io_ptr(const volatile void __iomem *);# include <linux/compiler-intel.h> #endif +/* Clang compiler defines __GNUC__. So we will overwrite implementations +* coming from above header files here +*/ +#ifdef __clang__ +#include <linux/compiler-clang.h> +#endif +/* * Generic compiler-dependent macros required for kernel * build go below this comment. Actual compiler/compiler version
Signature · 1 line
1.8.3.2
PATCH 5/5 x86 kbuild: LLVMLinux: More cc-options added for clang
In reply to [email protected]From: Jan-Simon Möller <[email protected]>
Protect more options for x86 with cc-option so that we don't get errors when using clang instead of gcc. Add more or different options when using clang as well. Also need to enforce that SSE is off for clang and the stack is 8-byte aligned.
--- arch/x86/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/Makefile +7 -1
@@ -108,7 +108,7 @@ else # this works around some issues with generating unwind tables in older gccs # newer gccs do it by default - KBUILD_CFLAGS += -maccumulate-outgoing-args + KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args) endif # Make sure compiler does not have buggy stack-protector support.
@@ -144,6 +144,12 @@ endif sp-$(CONFIG_X86_32) := esp sp-$(CONFIG_X86_64) := rsp +# enforce no-sse for clang +ifneq ($(COMPILER),clang) + KBUILD_CFLAGS += $(call cc-option,-mno-sse) + KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) +endif + # do binutils support CFI? cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1) # is .cfi_signal_frame supported too?
Signature · 1 line
1.8.3.2
H. Peter Anvin
reviewerRe: [PATCH 5/5] x86 kbuild: LLVMLinux: More cc-options added for clang
arch/x86/Makefile endif · line 152
Quoted 7 lines · On 02/25/2014 05:08 PM, [email protected] wrote:
arch/x86/Makefile +6
-0+# enforce no-sse for clang +ifneq ($(COMPILER),clang) + KBUILD_CFLAGS += $(call cc-option,-mno-sse) + KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) +endif +
I'm *very* confused. You're doing ifneq here but you're talking about it as if you are *adding* them for Clang, also these options are already added elsewhere (lines 57, 64, 86, 89) so why add them here?
-hpa
Re: [PATCH 5/5] x86 kbuild: LLVMLinux: More cc-options added for clang
Quoted 11 lines · H. Peter Anvin
arch/x86/Makefile endif · line 152
Quoted 7 lines · On 02/25/2014 05:08 PM, [email protected] wrote:
arch/x86/Makefile +6
-0+# enforce no-sse for clang +ifneq ($(COMPILER),clang) + KBUILD_CFLAGS += $(call cc-option,-mno-sse) + KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) +endif +I'm *very* confused. You're doing ifneq here but you're talking about it as if you are *adding* them for Clang, also these options are already added elsewhere (lines 57, 64, 86, 89) so why add them here?
Because when David Woodhouse's recent .code16 changes made it upstream (which invalidated most of our original patch) it seems I didn't remove this properly from our patch as well. :)
Thanks David for your patches. Thanks Peter for your sharp eyes!
Another example of why reviewing code on the mailing list works so well.
I will fix and resend.
Behan
Signature · 2 lines
Behan Webster [email protected]
PATCH v2 5/5 x86 kbuild: LLVMLinux: More cc-options added for clang
In reply to H. Peter AnvinFrom: Jan-Simon Möller <[email protected]>
Protect more options for x86 with cc-option so that we don't get errors when using clang instead of gcc. Add more or different options when using clang as well. Also need to enforce that SSE is off for clang and the stack is 8-byte aligned.
Removed improper reassetion of -mno-sse and -mpreferred-stack-boundary
--- arch/x86/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Makefile +1 -1
@@ -108,7 +108,7 @@ else # this works around some issues with generating unwind tables in older gccs # newer gccs do it by default - KBUILD_CFLAGS += -maccumulate-outgoing-args + KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args) endif # Make sure compiler does not have buggy stack-protector support.
Signature · 1 line
1.8.3.2