kbuild, LLVMLinux: Add -Werror to cc-option to support clang
PATCH 1/1 kbuild, LLVMLinux: Add -Werror to cc-option to support clang
From: Mark Charlebois <[email protected]>
Clang will warn about unknown warnings but will not return false unless -Werror is set. GCC will return false if an unknown warning is passed.
Adding -Werror make both compiler behave the same.
--- scripts/Kbuild.include | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/Kbuild.include +3 -3
@@ -111,12 +111,12 @@ as-instr = $(call try-run,\ # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) cc-option = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) # cc-option-yn # Usage: flag := $(call cc-option-yn,-march=winchip-c6) cc-option-yn = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) # cc-option-align # Prefix align with either -falign or -malign
@@ -126,7 +126,7 @@ cc-option-align = $(subst -functions=0,,\ # cc-disable-warning # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) cc-disable-warning = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) # cc-version # Usage gcc-ver := $(call cc-version)
Signature · 1 line
1.9.1
Quoted 3 lines · On 2014-09-23 21:28, [email protected] wrote:
From: Mark Charlebois <[email protected]>
Clang will warn about unknown warnings but will not return false
You mean unknown options, right?
Quoted 4 lines
unless -Werror is set. GCC will return false if an unknown warning is passed.
Adding -Werror make both compiler behave the same.
Can you please limit it to the clang case? Add an internal variable that either contains -Werror or nothing, depending on the compiler. What I fear is that if we use -Werror unconditionally and the user (or some automated build system) decides to add some silly option to KCFLAGS, we will get silent failures in the cc-option tests. Of course, the same can happen with clang, but there seems to be no way around it.
BTW, is there a chance that this would be fixed in some later clang version? Accepting unknown commandline options is a rather unusual behavior. How are all the ./configure scripts going to cope with it?
Thanks,
Michal
Quoted 5 lines · Michal Marek
Quoted 3 lines · On 2014-09-23 21:28, [email protected] wrote:
From: Mark Charlebois <[email protected]>
Clang will warn about unknown warnings but will not return false
You mean unknown options, right?
2 kinds of options: flags and warnings. clang used to merely warn about unused/unsupported flags/warnings. It now returns errors for unknown flags, but not warnings (unless you specify -Werror).
The issue is that a lot of existing projects which use clang expect the former behaviour (I agree that makes no sense, but there you go).
Quoted 6 lines
Quoted 4 lines
unless -Werror is set. GCC will return false if an unknown warning is passed.
Adding -Werror make both compiler behave the same.
Can you please limit it to the clang case? Add an internal variable that either contains -Werror or nothing, depending on the compiler.
I can do that. Will fix.
Quoted 4 lines
What I
fear is that if we use -Werror unconditionally and the user (or some automated build system) decides to add some silly option to KCFLAGS, we will get silent failures in the cc-option tests.
A valid concern for sure.
Quoted 3 lines
BTW, is there a chance that this would be fixed in some later clang version? Accepting unknown commandline options is a rather unusual behavior. How are all the ./configure scripts going to cope with it?
Again, clang does error out on unknown compiler flags (as opposed to warnings).
Getting clang to error on unused flags wasn't trivial (this change broke a lot of builds apparently). Fortunately we weren't the only ones who wanted it to behave like gcc in this case. I think it's going to be *much* harder to do the same for warnings. The argument given by supporters of the current situation is that if a warning isn't supported, why break the build? *sigh*
The LLVMLinux project is pushing hard to fix these sorts of things in clang, but some changes are more likely than others.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]
Quoted 9 lines · Behan Webster
Quoted 5 lines · Michal Marek
Quoted 3 lines · On 2014-09-23 21:28, [email protected] wrote:
From: Mark Charlebois <[email protected]>
Clang will warn about unknown warnings but will not return false
You mean unknown options, right?
2 kinds of options: flags and warnings. clang used to merely warn about unused/unsupported flags/warnings. It now returns errors for unknown flags, but not warnings (unless you specify -Werror).
Ah, unknown warning options. Now I understand.
Quoted 6 lines
Getting clang to error on unused flags wasn't trivial (this change broke a lot of builds apparently). Fortunately we weren't the only ones who wanted it to behave like gcc in this case. I think it's going to be *much* harder to do the same for warnings. The argument given by supporters of the current situation is that if a warning isn't supported, why break the build? *sigh*
I guess the reason to accept unknown warnings opentions is compatibility with Makefiles with hardcoded gcc-isms. BTW, GCC at some point started to ignore unknown -Wno-* options, for everyone's good of course. That's why we ended up with the cc-disable-warning function. If -W* options for clang need special care, then it might be a good idea to introduce cc-warning with the conditional -Werror for clang. There are not that many places where we add warnings, so the patch would be still short. That way, the possible silent failure is limited only to warning options with clang, which is not such a big deal.
Michal
Quoted 7 lines · Michal Marek
Quoted 6 lines · Behan Webster
Getting clang to error on unused flags wasn't trivial (this change broke a lot of builds apparently). Fortunately we weren't the only ones who wanted it to behave like gcc in this case. I think it's going to be *much* harder to do the same for warnings. The argument given by supporters of the current situation is that if a warning isn't supported, why break the build? *sigh*
Quoted 9 lines
I guess the reason to accept unknown warnings opentions is compatibility with Makefiles with hardcoded gcc-isms. BTW, GCC at some point started to ignore unknown -Wno-* options, for everyone's good of course. That's why we ended up with the cc-disable-warning function. If -W* options for clang need special care, then it might be a good idea to introduce cc-warning with the conditional -Werror for clang. There are not that many places where we add warnings, so the patch would be still short. That way, the possible silent failure is limited only to warning options with clang, which is not such a big deal.
I'll try this approach.
Thanks,
Behan
Signature · 2 lines
Behan Webster [email protected]