Skip to contentSkip to conversation

Makefile.extrawarn: move -Wcast-align to W=3

PATCH In review Arnd Bergmann 3 participants 8 messages Oct 26, 2020 – Nov 24, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Makefile.extrawarn: move -Wcast-align to W=3

From: Arnd Bergmann <[email protected]>

This warning behaves differently depending on the architecture and compiler. Using x86 gcc, we get no output at all because gcc knows the architecture can handle unaligned accesses.

Using x86 clang, or gcc on an architecture that needs to manually deal with unaligned accesses, the build log is completely flooded with these warnings, as they are commonly invoked by inline functions of networking headers, e.g.

include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]

The compiler is correct to point this out, as we are dealing with undefined behavior that does cause problems in practice, but there is also no good way to rewrite the code in commonly included headers to a safer method.

---
 scripts/Makefile.extrawarn | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.extrawarn +1 -1
index 95e4cdb94fe9..6baee1200615 100644
@@ -60,7 +60,6 @@ endif
 #
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
-KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wdisabled-optimization
 KBUILD_CFLAGS += -Wnested-externs
 KBUILD_CFLAGS += -Wshadow
@@ -80,6 +79,7 @@ endif
 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
 
 KBUILD_CFLAGS += -Wbad-function-cast
+KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wcast-qual
 KBUILD_CFLAGS += -Wconversion
 KBUILD_CFLAGS += -Wpacked
Signature · 1 line
2.27.0
#1 lore raw

PATCH 2/2 Makefile.extrawarn: limit -Wnested-externs to clang

From: Arnd Bergmann <[email protected]>

The -Wnested-externs warning has become useless with gcc, since this warns every time that BUILD_BUG_ON() or similar macros are used.

---
 scripts/Makefile.extrawarn | 3 +++
 1 file changed, 3 insertions(+)
scripts/Makefile.extrawarn +3 -0
index 6baee1200615..9406f752e355 100644
@@ -61,7 +61,10 @@ endif
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
 KBUILD_CFLAGS += -Wdisabled-optimization
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += -Wnested-externs
+endif
+
 KBUILD_CFLAGS += -Wshadow
 KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
 KBUILD_CFLAGS += -Wmissing-field-initializers
Signature · 1 line
2.27.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] Makefile.extrawarn: limit -Wnested-externs to clang

Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The -Wnested-externs warning has become useless with gcc, since this warns every time that BUILD_BUG_ON() or similar macros are used.

Also see:

2486baae2cf6 ("objtool: Allow nested externs to enable BUILD_BUG()") 6cf4ecf5c51d ("perf build: Allow nested externs to enable BUILD_BUG() usage")

Quoted 22 lines
---
 scripts/Makefile.extrawarn | 3 +++
 1 file changed, 3 insertions(+)
scripts/Makefile.extrawarn +3 -0
index 6baee1200615..9406f752e355 100644
@@ -61,7 +61,10 @@ endif
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
 KBUILD_CFLAGS += -Wdisabled-optimization
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += -Wnested-externs
+endif
+
 KBUILD_CFLAGS += -Wshadow
 KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
 KBUILD_CFLAGS += -Wmissing-field-initializers
Signature · 1 line
2.27.0
#3 lore raw

Re: [PATCH 2/2] Makefile.extrawarn: limit -Wnested-externs to clang

Quoted 7 lines · Nathan Chancellor
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The -Wnested-externs warning has become useless with gcc, since this warns every time that BUILD_BUG_ON() or similar macros are used.

Quoted 8 lines
Quoted 1 line

Also see:

2486baae2cf6 ("objtool: Allow nested externs to enable BUILD_BUG()") 6cf4ecf5c51d ("perf build: Allow nested externs to enable BUILD_BUG() usage")

Actually, just delete this line altogether. -Wnested-externs is a GCC only warning, the flag is only present in clang for compatibility with GCC:

https://clang.llvm.org/docs/DiagnosticsReference.html#wnested-externs

With that, my reviewed by still stands.

Cheers,
Nathan

#4 lore raw

Re: [PATCH 2/2] Makefile.extrawarn: limit -Wnested-externs to clang

Quoted 18 lines · Nathan Chancellor
Quoted 7 lines · Nathan Chancellor
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The -Wnested-externs warning has become useless with gcc, since this warns every time that BUILD_BUG_ON() or similar macros are used.

Quoted 8 lines
Quoted 1 line

Also see:

2486baae2cf6 ("objtool: Allow nested externs to enable BUILD_BUG()") 6cf4ecf5c51d ("perf build: Allow nested externs to enable BUILD_BUG() usage")

Quoted 8 lines

Actually, just delete this line altogether. -Wnested-externs is a GCC only warning, the flag is only present in clang for compatibility with GCC:

https://clang.llvm.org/docs/DiagnosticsReference.html#wnested-externs

With that, my reviewed by still stands.

I agree.

Arnd, will you send v2?

Please include
https://clang.llvm.org/docs/DiagnosticsReference.html#wnested-externs
as a reference.

Thanks.

Signature · 2 lines
Best Regards
Masahiro Yamada
Reviewed-by on v1 1/2
#5 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This warning behaves differently depending on the architecture and compiler. Using x86 gcc, we get no output at all because gcc knows the architecture can handle unaligned accesses.

Using x86 clang, or gcc on an architecture that needs to manually deal with unaligned accesses, the build log is completely flooded with these warnings, as they are commonly invoked by inline functions of networking headers, e.g.

Quoted 8 lines

include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]

The compiler is correct to point this out, as we are dealing with undefined behavior that does cause problems in practice, but there is also no good way to rewrite the code in commonly included headers to a safer method.

Always sad to see a warning move further down the list but noisy headers are rough to deal with. This seems okay.

Quoted 27 lines
---
 scripts/Makefile.extrawarn | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.extrawarn +1 -1
index 95e4cdb94fe9..6baee1200615 100644
@@ -60,7 +60,6 @@ endif
 #
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
-KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wdisabled-optimization
 KBUILD_CFLAGS += -Wnested-externs
 KBUILD_CFLAGS += -Wshadow
@@ -80,6 +79,7 @@ endif
 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
 
 KBUILD_CFLAGS += -Wbad-function-cast
+KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wcast-qual
 KBUILD_CFLAGS += -Wconversion
 KBUILD_CFLAGS += -Wpacked
Signature · 1 line
2.27.0
#6 lore raw
Quoted 46 lines · Nathan Chancellor
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This warning behaves differently depending on the architecture and compiler. Using x86 gcc, we get no output at all because gcc knows the architecture can handle unaligned accesses.

Using x86 clang, or gcc on an architecture that needs to manually deal with unaligned accesses, the build log is completely flooded with these warnings, as they are commonly invoked by inline functions of networking headers, e.g.

Quoted 8 lines

include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]

The compiler is correct to point this out, as we are dealing with undefined behavior that does cause problems in practice, but there is also no good way to rewrite the code in commonly included headers to a safer method.

Always sad to see a warning move further down the list but noisy headers are rough to deal with. This seems okay.

Quoted 19 lines
---
 scripts/Makefile.extrawarn | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.extrawarn +0 -1
index 95e4cdb94fe9..6baee1200615 100644
@@ -60,7 +60,6 @@ endif
 #
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
-KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wdisabled-optimization
 KBUILD_CFLAGS += -Wnested-externs
 KBUILD_CFLAGS += -Wshadow
@@ -80,6 +79,7 @@ endif
 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
 
Quoted 8 lines
Quoted 8 lines
scripts/Makefile.extrawarn +1 -1
 KBUILD_CFLAGS += -Wbad-function-cast
+KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wcast-qual
 KBUILD_CFLAGS += -Wconversion
 KBUILD_CFLAGS += -Wpacked
--

2.27.0

Applied to linux-kbuild. Thanks.

But, I think people already tend to ignore W=2 warnings.

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw
Quoted 4 lines · Masahiro Yamada

Applied to linux-kbuild. Thanks.

But, I think people already tend to ignore W=2 warnings.

Yes, this is what I was trying to change with this series and a couple of other patches I sent. When all the warnings from commonly included headers are gone, W=2 actually becomes somewhat useful.

Arnd