* [PATCH 1/6] [v3] kbuild: turn on -Wextra by default
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 16:16 ` Kees Cook
2024-04-15 12:20 ` [PATCH 2/6] [v3] kbuild: remove redundant extra warning flags Arnd Bergmann
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
The -Wextra option controls a number of different warnings that differ
slightly by compiler version. Some are useful in general, others are
better left at W=1 or higher. Based on earlier work, the ones that
should be disabled by default are left for the higher warning levels
already, and a lot of the useful ones have no remaining output when
enabled.
Move the -Wextra option up into the set of default-enabled warnings
and just rely on the individual ones getting disabled as needed.
The -Wunused warning was always grouped with this, so turn it on
by default as well, except for the -Wunused-parameter warning that
really has no value at all for the kernel since many interfaces
have intentionally unused arguments.
Acked-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
| 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index c5af566e911a..c247552c192c 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -82,12 +82,14 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
# Warn if there is an enum types mismatch
KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
+KBUILD_CFLAGS += -Wextra
+KBUILD_CFLAGS += -Wunused
+
#
# W=1 - warnings which may be relevant and do not occur too often
#
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
-KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
KBUILD_CFLAGS += $(call cc-option, -Wrestrict)
KBUILD_CFLAGS += -Wmissing-format-attribute
KBUILD_CFLAGS += -Wold-style-definition
@@ -190,6 +192,7 @@ else
# The following turn off the warnings enabled by -Wextra
KBUILD_CFLAGS += -Wno-sign-compare
+KBUILD_CFLAGS += -Wno-unused-parameter
endif
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/6] [v3] kbuild: turn on -Wextra by default
2024-04-15 12:20 ` [PATCH 1/6] [v3] kbuild: turn on -Wextra " Arnd Bergmann
@ 2024-04-15 16:16 ` Kees Cook
0 siblings, 0 replies; 11+ messages in thread
From: Kees Cook @ 2024-04-15 16:16 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel
On Mon, Apr 15, 2024 at 02:20:32PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The -Wextra option controls a number of different warnings that differ
> slightly by compiler version. Some are useful in general, others are
> better left at W=1 or higher. Based on earlier work, the ones that
> should be disabled by default are left for the higher warning levels
> already, and a lot of the useful ones have no remaining output when
> enabled.
>
> Move the -Wextra option up into the set of default-enabled warnings
> and just rely on the individual ones getting disabled as needed.
>
> The -Wunused warning was always grouped with this, so turn it on
> by default as well, except for the -Wunused-parameter warning that
> really has no value at all for the kernel since many interfaces
> have intentionally unused arguments.
>
> Acked-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/6] [v3] kbuild: remove redundant extra warning flags
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
2024-04-15 12:20 ` [PATCH 1/6] [v3] kbuild: turn on -Wextra " Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 12:20 ` [PATCH 3/6] [v3] kbuild: turn on -Wrestrict by default Arnd Bergmann
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
There is no point in turning individual options off and then on again,
or vice versa, as the last one always wins. Now that -Wextra always
gets passed first, remove all the redundant lines about warnings
that are implied by either -Wall or -Wextra, and keep only the last
one that disables it in some configurations.
This should not have any effect but keep the Makefile more readable
and the command line shorter.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
| 15 ---------------
1 file changed, 15 deletions(-)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index c247552c192c..8b3f5b62b837 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -37,11 +37,6 @@ else
KBUILD_CFLAGS += -Wno-main
endif
-# These warnings generated too much noise in a regular build.
-# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
-KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
-KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
-
# These result in bogus false positives
KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
@@ -90,16 +85,9 @@ KBUILD_CFLAGS += -Wunused
#
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
-KBUILD_CFLAGS += $(call cc-option, -Wrestrict)
KBUILD_CFLAGS += -Wmissing-format-attribute
-KBUILD_CFLAGS += -Wold-style-definition
KBUILD_CFLAGS += -Wmissing-include-dirs
-KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
-KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
-KBUILD_CFLAGS += $(call cc-option, -Wformat-overflow)
-KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation)
-KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
KBUILD_CPPFLAGS += -Wundef
KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
@@ -150,9 +138,6 @@ ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
KBUILD_CFLAGS += -Wdisabled-optimization
KBUILD_CFLAGS += -Wshadow
KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
-KBUILD_CFLAGS += -Wmissing-field-initializers
-KBUILD_CFLAGS += -Wtype-limits
-KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/6] [v3] kbuild: turn on -Wrestrict by default
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
2024-04-15 12:20 ` [PATCH 1/6] [v3] kbuild: turn on -Wextra " Arnd Bergmann
2024-04-15 12:20 ` [PATCH 2/6] [v3] kbuild: remove redundant extra warning flags Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 16:14 ` Kees Cook
2024-04-15 12:20 ` [PATCH 4/6] [v3] kbuild: enable -Wformat-truncation on clang Arnd Bergmann
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
All known -Wrestrict warnings are addressed now, so don't disable the warning
any more.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
| 1 -
1 file changed, 1 deletion(-)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 8b3f5b62b837..95466a04d51b 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -98,7 +98,6 @@ else
# Suppress them by using -Wno... except for W=1.
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
-KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] [v3] kbuild: turn on -Wrestrict by default
2024-04-15 12:20 ` [PATCH 3/6] [v3] kbuild: turn on -Wrestrict by default Arnd Bergmann
@ 2024-04-15 16:14 ` Kees Cook
0 siblings, 0 replies; 11+ messages in thread
From: Kees Cook @ 2024-04-15 16:14 UTC (permalink / raw)
To: Arnd Bergmann, Gatlin Newhouse
Cc: Andrew Morton, Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel
On Mon, Apr 15, 2024 at 02:20:34PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> All known -Wrestrict warnings are addressed now, so don't disable the warning
> any more.
Ah, great! Yes, I know Gatlin was also looking at this and doing a bunch
of builds across compiler versions to verify this was ready to do too.
Gatlin, are you able to provide a "Tested-by:" tag for this patch?
-Kees
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> scripts/Makefile.extrawarn | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 8b3f5b62b837..95466a04d51b 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -98,7 +98,6 @@ else
> # Suppress them by using -Wno... except for W=1.
> KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
> KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
> -KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
> KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
> KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
> KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
> --
> 2.39.2
>
--
Kees Cook
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/6] [v3] kbuild: enable -Wformat-truncation on clang
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
` (2 preceding siblings ...)
2024-04-15 12:20 ` [PATCH 3/6] [v3] kbuild: turn on -Wrestrict by default Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 12:20 ` [PATCH 5/6] [v3] kbuild: enable -Wcast-function-type-strict unconditionally Arnd Bergmann
2024-04-15 12:20 ` [PATCH 6/6] [v3] kbuild: enable -Wstringop-truncation globally Arnd Bergmann
5 siblings, 0 replies; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
This warning option still produces output on gcc but is now clean when
building with clang, so enable it conditionally on the compiler for now.
As far as I can tell, the remaining warnings with gcc are the result of
analysing the code more deeply across inlining, while clang only does
this within a function.
Link: https://lore.kernel.org/lkml/20240326230511.GA2796782@dev-arch.thelio-3990X/
Link: https://lore.kernel.org/linux-patches/20231002-disable-wformat-truncation-overflow-non-kprintf-v1-1-35179205c8d9@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
| 7 +++++++
1 file changed, 7 insertions(+)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 95466a04d51b..202e26e6f29f 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -100,7 +100,14 @@ KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
+ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
+else
+# Clang checks for overflow/truncation with '%p', while GCC does not:
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219
+KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
+KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
+endif
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/6] [v3] kbuild: enable -Wcast-function-type-strict unconditionally
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
` (3 preceding siblings ...)
2024-04-15 12:20 ` [PATCH 4/6] [v3] kbuild: enable -Wformat-truncation on clang Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 16:15 ` Kees Cook
2024-04-15 12:20 ` [PATCH 6/6] [v3] kbuild: enable -Wstringop-truncation globally Arnd Bergmann
5 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
All known function cast warnings are now addressed, so the warning can
be enabled globally to catch new ones more quickly.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
| 1 -
1 file changed, 1 deletion(-)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 202e26e6f29f..1d13cecc7cc7 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -129,7 +129,6 @@ endif
KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
-KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
KBUILD_CFLAGS += -Wno-enum-compare-conditional
KBUILD_CFLAGS += -Wno-enum-enum-conversion
endif
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 5/6] [v3] kbuild: enable -Wcast-function-type-strict unconditionally
2024-04-15 12:20 ` [PATCH 5/6] [v3] kbuild: enable -Wcast-function-type-strict unconditionally Arnd Bergmann
@ 2024-04-15 16:15 ` Kees Cook
0 siblings, 0 replies; 11+ messages in thread
From: Kees Cook @ 2024-04-15 16:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, linux-kbuild, linux-kernel
On Mon, Apr 15, 2024 at 02:20:36PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> All known function cast warnings are now addressed, so the warning can
> be enabled globally to catch new ones more quickly.
Also yay! :)
Reviewed-by: Kees Cook <keescook@chromium.org>
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> scripts/Makefile.extrawarn | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 202e26e6f29f..1d13cecc7cc7 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -129,7 +129,6 @@ endif
> KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
> KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
> KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
> -KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
> KBUILD_CFLAGS += -Wno-enum-compare-conditional
> KBUILD_CFLAGS += -Wno-enum-enum-conversion
> endif
> --
> 2.39.2
>
--
Kees Cook
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 6/6] [v3] kbuild: enable -Wstringop-truncation globally
2024-04-15 12:20 [PATCH 0/6] [v3] kbuild: enable more warnings by default Arnd Bergmann
` (4 preceding siblings ...)
2024-04-15 12:20 ` [PATCH 5/6] [v3] kbuild: enable -Wcast-function-type-strict unconditionally Arnd Bergmann
@ 2024-04-15 12:20 ` Arnd Bergmann
2024-04-15 16:15 ` Kees Cook
5 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2024-04-15 12:20 UTC (permalink / raw)
To: Andrew Morton
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Kees Cook, linux-kbuild, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
The remaining warnings of this type have been addressed, so it can
now be enabled by default, rather than only for W=1.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v3: no changes
v2: no changes
---
| 1 -
1 file changed, 1 deletion(-)
--git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 1d13cecc7cc7..17c511ddf48a 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -108,7 +108,6 @@ else
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
endif
-KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang
--
2.39.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 6/6] [v3] kbuild: enable -Wstringop-truncation globally
2024-04-15 12:20 ` [PATCH 6/6] [v3] kbuild: enable -Wstringop-truncation globally Arnd Bergmann
@ 2024-04-15 16:15 ` Kees Cook
0 siblings, 0 replies; 11+ messages in thread
From: Kees Cook @ 2024-04-15 16:15 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Gustavo A. R. Silva, Arnd Bergmann,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier, linux-kbuild,
linux-kernel
On Mon, Apr 15, 2024 at 02:20:37PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The remaining warnings of this type have been addressed, so it can
> now be enabled by default, rather than only for W=1.
Yeah, I know Gustavo had been working on these too. Yay!
Reviewed-by: Kees Cook <keescook@chromium.org>
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v3: no changes
> v2: no changes
> ---
> scripts/Makefile.extrawarn | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 1d13cecc7cc7..17c511ddf48a 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -108,7 +108,6 @@ else
> KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
> KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
> endif
> -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
>
> KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang
>
> --
> 2.39.2
>
--
Kees Cook
^ permalink raw reply [flat|nested] 11+ messages in thread