Skip to contentSkip to conversation

kbuild, LLVMLinux: Add -Werror to cc-option to support clang

PATCH In review Arnd Bergmann 3 participants 5 messages Mar 31, 2017 – Apr 11, 2017 Kbuild

lore
Share & tools
lore
#0 lore raw

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.

[arnd: it turns out we need the same patch for testing whether -ffunction-sections
works right with gcc. I've build tested extensively with this patch applied, so let's just merge this one now.]

---
 scripts/Kbuild.include | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/Kbuild.include +3 -3
index d6ca649cb0e9..a70fd26204de 100644
@@ -116,12 +116,12 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
 
 cc-option = $(call try-run,\
-	$(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_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) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
 
 # cc-option-align
 # Prefix align with either -falign or -malign
@@ -131,7 +131,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) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+	$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
 
 # cc-name
 # Expands to either gcc or clang
Signature · 1 line
2.9.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Arnd Bergmann

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.

Quoted 8 lines

[arnd: it turns out we need the same patch for testing whether -ffunction-sections
works right with gcc. I've build tested extensively with this patch applied, so let's just merge this one now.]

-Kees

Quoted 35 lines
---
 scripts/Kbuild.include | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/Kbuild.include +3 -4
index d6ca649cb0e9..a70fd26204de 100644
@@ -116,12 +116,12 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
 
 cc-option = $(call try-run,\
-       $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
+       $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_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) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+       $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
 
 # cc-option-align
 # Prefix align with either -falign or -malign
@@ -131,7 +131,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) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+       $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
 
 # cc-name
 # Expands to either gcc or clang
--

2.9.0

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
In reply to Arnd Bergmann

Hi Arnd,

2017-04-01 5:38 GMT+09:00 Arnd Bergmann <[email protected]>:

Quoted 8 lines

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.

Quoted 8 lines

[arnd: it turns out we need the same patch for testing whether -ffunction-sections
works right with gcc. I've build tested extensively with this patch applied, so let's just merge this one now.]

Thank you for forwarding this patch.

The code diff looks good to me,
but I'd like to be sure about git-log before applying it.

As far as I tested, the statement
"Clang will warn about unknown warnings but will not return false unless -Werror is set." does not seem true on recent versions.

[1] When I use version 3.3

masahiro@grover:~$ clang --version
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
masahiro@grover:~$ clang  -foobar -c -x c /dev/null
clang: warning: argument unused during compilation: '-foobar'
masahiro@grover:~$ echo $?
0

[2] When I use version 3.4

masahiro@grover:~$ clang --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
masahiro@grover:~$ clang  -foobar -c -x c /dev/null
clang: error: unknown argument: '-foobar'
masahiro@grover:~$ echo $?
1

I agree we can apply this patch anyway
even if the original motivation is not true anymore.

Can you check it out,
and add a little more comments if you agree?

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw

Hi Arnd,

2017-04-03 6:46 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 62 lines

Hi Arnd,

2017-04-01 5:38 GMT+09:00 Arnd Bergmann <[email protected]>:

Quoted 8 lines

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.

Quoted 8 lines

[arnd: it turns out we need the same patch for testing whether -ffunction-sections
works right with gcc. I've build tested extensively with this patch applied, so let's just merge this one now.]

Thank you for forwarding this patch.

The code diff looks good to me,
but I'd like to be sure about git-log before applying it.

As far as I tested, the statement
"Clang will warn about unknown warnings but will not return false unless -Werror is set." does not seem true on recent versions.

[1] When I use version 3.3

masahiro@grover:~$ clang --version
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
masahiro@grover:~$ clang  -foobar -c -x c /dev/null
clang: warning: argument unused during compilation: '-foobar'
masahiro@grover:~$ echo $?
0

[2] When I use version 3.4

masahiro@grover:~$ clang --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
masahiro@grover:~$ clang  -foobar -c -x c /dev/null
clang: error: unknown argument: '-foobar'
masahiro@grover:~$ echo $?
1
Quoted 6 lines

I agree we can apply this patch anyway
even if the original motivation is not true anymore.

Can you check it out,
and add a little more comments if you agree?

Sorry. This was my misunderstanding.
You do not have to answer my question.

I found this patch is still useful for recent clang versions.

I will apply this patch shortly. Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada
#4 lore raw
In reply to Arnd Bergmann

2017-04-01 5:38 GMT+09:00 Arnd Bergmann <[email protected]>:

Quoted 8 lines

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.

Quoted 8 lines

[arnd: it turns out we need the same patch for testing whether -ffunction-sections
works right with gcc. I've build tested extensively with this patch applied, so let's just merge this one now.]

Applied to linux-kbuild/kbuild.
Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada