Kbuild: warning options cleanup and more warnings
Subsystems (2)
cover Kbuild: warning options cleanup and more warnings
From: Arnd Bergmann <[email protected]>
This is a series I've had in my randconfig test tree for a long time, and I'd like to get these patches applied in mainline so I can stop rebasing them on top of other changes, as well as get fewer regressions.
There are roughly three groups of changes in here:
1. Clean up the Makefile and Makefile.extrawarn to be organized more logically so we can see which warnings are actually enabled at which level
2. Enable some of the warnings that have traditionally been disabled at either the W=1 or W=2 levels where they arguably should have been to start with
3. Enable some of the W=1 warnings by default now that the warnings we got in the past have been addressed.
I sent the -Wmissing-prototypes enablement separately, since that is really the big one that probably found the most bugs but also still caused the most warnings until my recent cleanups.
Along the same lines as that other series, I would hope that we can get the first eight patches into the merge window, but should probably give the last patch another release in linux-next before any remaining output has been addressed and we can apply it.
Arnd
Arnd Bergmann (9):
Kbuild: only pass -fno-inline-functions-called-once for gcc
Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
Kbuild: avoid duplicate warning options
extrawarn: don't turn off -Wshift-negative-value for gcc-9
extrawarn: enable format and stringop overflow warnings in W=1
extrawarn: move -Wrestrict into W=1 warnings
extrawarn: do not disable -Wmain at W=1 level
extrawarn: enable more warnings in W=2
[RFC] extrawarn: enable more W=1 warnings by default
Makefile | 90 +------------------------ scripts/Makefile.extrawarn | 133 ++++++++++++++++++++++++++++++++----- 2 files changed, 118 insertions(+), 105 deletions(-)
Signature · 11 lines
2.39.2 Cc: Masahiro Yamada <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Lee Jones <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: [email protected] Cc: [email protected]
PATCH 1/9 Kbuild: only pass -fno-inline-functions-called-once for gcc
From: Arnd Bergmann <[email protected]>
clang ignores the -fno-inline-functions-called-once option, but warns when building with -Wignored-optimization-argument enabled:
clang: error: optimization flag '-fno-inline-functions-called-once' is not supported [-Werror,-Wignored-optimization-argument]
Move it back to using cc-option for this one.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -967,7 +967,7 @@ endif # We trigger additional mismatches with less inlining ifdef CONFIG_DEBUG_SECTION_MISMATCH -KBUILD_CFLAGS += -fno-inline-functions-called-once +KBUILD_CFLAGS += $(call cc-option,-fno-inline-functions-called-once) endif # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
Signature · 1 line
2.39.2
Nathan Chancellor
maintainerRe: [PATCH 1/9] Kbuild: only pass -fno-inline-functions-called-once for gcc
Quoted 11 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
clang ignores the -fno-inline-functions-called-once option, but warns when building with -Wignored-optimization-argument enabled:
clang: error: optimization flag '-fno-inline-functions-called-once' is not supported [-Werror,-Wignored-optimization-argument]
Move it back to using cc-option for this one.
Fixes 7d73c3e9c514 ("Makefile: remove stale cc-option checks")Signed-off-by Arnd Bergmann <[email protected]>
How can this even be hit with clang, as CONFIG_DEBUG_SECTION_MISMATCH was changed to depend on GCC in the same commit?
Quoted 20 lines
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +1
-1@@ -967,7 +967,7 @@ endif # We trigger additional mismatches with less inlining ifdef CONFIG_DEBUG_SECTION_MISMATCH -KBUILD_CFLAGS += -fno-inline-functions-called-once +KBUILD_CFLAGS += $(call cc-option,-fno-inline-functions-called-once) endif # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).Signature · 1 line
2.39.2
Arnd Bergmann
maintainerRe: [PATCH 1/9] Kbuild: only pass -fno-inline-functions-called-once for gcc
Quoted 8 lines · Nathan Chancellor
Quoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
clang ignores the -fno-inline-functions-called-once option, but warns when building with -Wignored-optimization-argument enabled:
clang: error: optimization flag '-fno-inline-functions-called-once' is not supported [-Werror,-Wignored-optimization-argument]
Quoted 7 lines
Quoted 4 lines
Move it back to using cc-option for this one.
Fixes 7d73c3e9c514 ("Makefile: remove stale cc-option checks")Signed-off-by Arnd Bergmann <[email protected]>How can this even be hit with clang, as
CONFIG_DEBUG_SECTION_MISMATCHwas changed to depend on GCC in the same commit?
Good question, I have not noticed that part, but I'm pretty sure I keep hitting this issue. I'll drop it from my series to see if I can reproduce it.
Maybe what happens is that this triggers when changing from gcc to clang in an output directory, the stake CONFIG_* symbols are still evaluated while parsing the initial Makefile but then cause problems.
Arnd
PATCH 2/9 Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn.
This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on.
--- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-)
Makefile +0 -88
@@ -563,14 +563,6 @@ KBUILD_CFLAGS += -funsigned-char KBUILD_CFLAGS += -fno-common KBUILD_CFLAGS += -fno-PIE KBUILD_CFLAGS += -fno-strict-aliasing -KBUILD_CFLAGS += -Wall -KBUILD_CFLAGS += -Wundef -KBUILD_CFLAGS += -Werror=implicit-function-declaration -KBUILD_CFLAGS += -Werror=implicit-int -KBUILD_CFLAGS += -Werror=return-type -KBUILD_CFLAGS += -Werror=strict-prototypes -KBUILD_CFLAGS += -Wno-format-security -KBUILD_CFLAGS += -Wno-trigraphs KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_RUSTFLAGS := $(rust_common_flags) \
@@ -823,10 +815,6 @@ endif # may-sync-config endif # need-config KBUILD_CFLAGS += -fno-delete-null-pointer-checks -KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE KBUILD_CFLAGS += -O2
@@ -857,40 +845,15 @@ ifdef CONFIG_READABLE_ASM KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining endif -ifneq ($(CONFIG_FRAME_WARN),0) -KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN) -endif - stackp-flags-y := -fno-stack-protector stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) -KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror -KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) -KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds - KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y) -ifdef CONFIG_CC_IS_CLANG -# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable. -KBUILD_CFLAGS += -Wno-gnu -else - -# gcc inanely warns about local variables called 'main' -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) - ifdef CONFIG_FRAME_POINTER KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
@@ -1025,51 +988,12 @@ endif # arch Makefile may override CC so keep this after arch Makefile is included NOSTDINC_FLAGS += -nostdinc -# Variable Length Arrays (VLAs) should not be used anywhere in the kernel -KBUILD_CFLAGS += -Wvla - -# disable pointer signed / unsigned warnings in gcc 4.0 -KBUILD_CFLAGS += -Wno-pointer-sign - -# In order to make sure new function cast mismatches are not introduced -# in the kernel (to avoid tripping CFI checking), the kernel should be -# globally built with -Wcast-function-type. -KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) - # To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, # the kernel uses only C99 flexible arrays for dynamically sized trailing # arrays. Enforce this for everything that may examine structure sizes and # perform bounds checking. KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) -# disable stringop warnings in gcc 8+ -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) - -# We'll want to enable this eventually, but it's not going away for 5.7 at least -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) - -# Another good warning that we'll want to enable eventually -KBUILD_CFLAGS += $(call cc-disable-warning, restrict) - -# Enabled with W=2, disabled by default as noisy -ifdef CONFIG_CC_IS_GCC -KBUILD_CFLAGS += -Wno-maybe-uninitialized -endif - -# The allocators already balk at large sizes, so silence the compiler -# warnings for bounds checks involving those possible values. While -# -Wno-alloc-size-larger-than would normally be used here, earlier versions -# of gcc (<9.1) weirdly don't handle the option correctly when _other_ -# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX -# doesn't work (as it is documented to), silently resolving to "0" prior to -# version 9.1 (and producing an error more recently). Numeric values larger -# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently -# ignored, continuing to default to PTRDIFF_MAX. So, left with no other -# choice, we must perform a versioned check to disable this warning. -# https://lore.kernel.org/lkml/[email protected] -KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than -KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH) - # disable invalid "can't wrap" optimizations for signed / pointers KBUILD_CFLAGS += -fno-strict-overflow
@@ -1081,18 +1005,6 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -fconserve-stack endif -# Prohibit date/time macros, which would make the build non-deterministic -KBUILD_CFLAGS += -Werror=date-time - -# enforce correct pointer usage -KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) - -# Require designated initializers for all marked structures -KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) - -# Warn if there is an enum types mismatch -KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) - # change __FILE__ to the relative path from the srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
scripts/Makefile.extrawarn +90 -0
96 lines not on this page · raw message
Signature · 1 line
2.39.2
Nathan Chancellor
maintainerRe: [PATCH 2/9] Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn.
This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on.
Quoted 5 lines
Signed-off-by Arnd Bergmann <[email protected]>--- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-)
This shuffle seems reasonable to me. Would it make sense to rename the Makefile from Makefile.extrawarn to just Makefile.warn or Makefile.warnings? They are still "extra" warnings but to me, the meaning of the Makefile is changing so it seems reasonable to drop the "extra" part.
Cheers,
Nathan
Arnd Bergmann
maintainerRe: [PATCH 2/9] Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
Quoted 17 lines · Nathan Chancellor
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn.
This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on.
Quoted 5 lines
Signed-off-by Arnd Bergmann <[email protected]>--- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-)
Quoted 5 lines
This shuffle seems reasonable to me. Would it make sense to rename the
Makefilefrom Makefile.extrawarn to just Makefile.warn or Makefile.warnings? They are still "extra" warnings but to me, the meaning of theMakefileis changing so it seems reasonable to drop the "extra" part.
Renaming the file seems fine, but I'd much prefer to do that separately if we decide to do it, otherwise rebasing my patches is going to be even more painful.
Arnd
Re: [PATCH 2/9] Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
Quoted 25 lines · Arnd Bergmann
Quoted 17 lines · Nathan Chancellor
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn.
This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on.
Quoted 5 lines
Signed-off-by Arnd Bergmann <[email protected]>--- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-)Quoted 5 lines
This shuffle seems reasonable to me. Would it make sense to rename the
Makefilefrom Makefile.extrawarn to just Makefile.warn or Makefile.warnings? They are still "extra" warnings but to me, the meaning of theMakefileis changing so it seems reasonable to drop the "extra" part.
Quoted 5 lines
Renaming the file seems fine, but I'd much prefer to do that separately if we decide to do it, otherwise rebasing my patches is going to be even more painful.
Arnd
Nice cleanups.
I like this, and renaming the file
(as a separate patch).
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 2/9] Kbuild: consolidate warning flags in scripts/Makefile.extrawarn
In reply to Arnd BergmannQuoted 25 lines · Arnd Bergmann
Quoted 17 lines · Nathan Chancellor
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn.
This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on.
Quoted 5 lines
Signed-off-by Arnd Bergmann <[email protected]>--- Makefile | 88 ------------------------------------- scripts/Makefile.extrawarn | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-)Quoted 5 lines
This shuffle seems reasonable to me. Would it make sense to rename the
Makefilefrom Makefile.extrawarn to just Makefile.warn or Makefile.warnings? They are still "extra" warnings but to me, the meaning of theMakefileis changing so it seems reasonable to drop the "extra" part.
Quoted 5 lines
Renaming the file seems fine, but I'd much prefer to do that separately if we decide to do it, otherwise rebasing my patches is going to be even more painful.
Arnd
Applied to linux-kbuild. Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 3/9 Kbuild: avoid duplicate warning options
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
Some warning options are disabled at one place and then conditionally re-enabled later in scripts/Makefile.extrawarn.
For consistency, rework this file so each of those warnings only gets etiher enabled or disabled based on the W= flags but not both.
--- scripts/Makefile.extrawarn | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-)
scripts/Makefile.extrawarn +26 -17
@@ -56,20 +56,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# disable stringop warnings in gcc 8+ -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) - # We'll want to enable this eventually, but it's not going away for 5.7 at least KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict) -# Enabled with W=2, disabled by default as noisy -ifdef CONFIG_CC_IS_GCC -KBUILD_CFLAGS += -Wno-maybe-uninitialized -endif - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -96,8 +88,6 @@ 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 += $(call cc-disable-warning, packed-not-aligned) - # backward compatibility KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
@@ -122,11 +112,6 @@ 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, -Wstringop-truncation) -# The following turn off the warnings enabled by -Wextra -KBUILD_CFLAGS += -Wno-missing-field-initializers -KBUILD_CFLAGS += -Wno-sign-compare -KBUILD_CFLAGS += -Wno-type-limits -KBUILD_CFLAGS += -Wno-shift-negative-value KBUILD_CPPFLAGS += -Wundef KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
@@ -135,9 +120,12 @@ else # Some diagnostics enabled by default are noisy. # 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, packed-not-aligned) +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ifdef CONFIG_CC_IS_CLANG -KBUILD_CFLAGS += -Wno-initializer-overrides # Clang before clang-16 would warn on default argument promotions. ifneq ($(call clang-min-version, 160000),y) # Disable -Wformat
@@ -151,7 +139,6 @@ ifeq ($(call clang-min-version, 120000),y) KBUILD_CFLAGS += -Wformat-insufficient-args endif endif -KBUILD_CFLAGS += -Wno-sign-compare 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)
@@ -173,8 +160,25 @@ KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Winitializer-overrides +endif + KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 +else + +# The following turn off the warnings enabled by -Wextra +KBUILD_CFLAGS += -Wno-missing-field-initializers +KBUILD_CFLAGS += -Wno-type-limits +KBUILD_CFLAGS += -Wno-shift-negative-value + +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Wno-initializer-overrides +else +KBUILD_CFLAGS += -Wno-maybe-uninitialized +endif + endif #
@@ -196,6 +200,11 @@ KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 +else + +# The following turn off the warnings enabled by -Wextra +KBUILD_CFLAGS += -Wno-sign-compare + endif #
Signature · 1 line
2.39.2
Re: [PATCH 3/9] Kbuild: avoid duplicate warning options
Quoted 93 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Some warning options are disabled at one place and then conditionally re-enabled later in
scripts/Makefile.extrawarn.For consistency, rework this file so each of those warnings only gets etiher enabled or disabled based on the W= flags but not both.
Signed-off-by Arnd Bergmann <[email protected]>--- scripts/Makefile.extrawarn | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-)scripts/Makefile.extrawarn +9
-17@@ -56,20 +56,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# disable stringop warnings in gcc 8+ -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) - # We'll want to enable this eventually, but it's not going away for 5.7 at least KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict) -# Enabled with W=2, disabled by default as noisy -ifdef CONFIG_CC_IS_GCC -KBUILD_CFLAGS += -Wno-maybe-uninitialized -endif - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions@@ -96,8 +88,6 @@ 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 += $(call cc-disable-warning, packed-not-aligned) - # backward compatibility KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)@@ -122,11 +112,6 @@ 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, -Wstringop-truncation) -# The following turn off the warnings enabled by -Wextra -KBUILD_CFLAGS += -Wno-missing-field-initializers -KBUILD_CFLAGS += -Wno-sign-compare -KBUILD_CFLAGS += -Wno-type-limits -KBUILD_CFLAGS += -Wno-shift-negative-value KBUILD_CPPFLAGS += -Wundef KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1@@ -135,9 +120,12 @@ else # Some diagnostics enabled by default are noisy. # 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, packed-not-aligned) +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ifdef CONFIG_CC_IS_CLANG -KBUILD_CFLAGS += -Wno-initializer-overrides # Clang before clang-16 would warn on default argument promotions. ifneq ($(call clang-min-version, 160000),y) # Disable -Wformat@@ -151,7 +139,6 @@ ifeq ($(call clang-min-version, 120000),y) KBUILD_CFLAGS += -Wformat-insufficient-args endif endif -KBUILD_CFLAGS += -Wno-sign-compare 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)@@ -173,8 +160,25 @@ KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Winitializer-overrides +endif + KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 +else
scripts/Makefile.extrawarn KBUILD_CFLAGS += -Wtype-limits · line 179
Quoted 10 lines
scripts/Makefile.extrawarn +10
-0+ +# The following turn off the warnings enabled by -Wextra +KBUILD_CFLAGS += -Wno-missing-field-initializers +KBUILD_CFLAGS += -Wno-type-limits +KBUILD_CFLAGS += -Wno-shift-negative-value + +ifdef CONFIG_CC_IS_CLANG +KBUILD_CFLAGS += -Wno-initializer-overrides +else +KBUILD_CFLAGS += -Wno-maybe-uninitialized
GCC manual says -Wall implies -Wmaybe-uninitialized.
If you move -Wno-maybe-uninitialize to the "W != 2" part, -Wmaybe-uninitialized is unneeded in the 'W == 2" part.
Maybe, the same applies to -Wunused-but-set-parameter.
Shall we drop warnings implied by another, or
is it clearer to explicitly add either -Wfoo or -Wno-foo?
If desired, we can do such a clean-up later, though.
--
Best Regards
Masahiro Yamada
Arnd Bergmann
maintainerRe: [PATCH 3/9] Kbuild: avoid duplicate warning options
Quoted 7 lines · Masahiro Yamada
On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <[email protected]> wrote:
GCC manual says -Wall implies -Wmaybe-uninitialized.
If you move -Wno-maybe-uninitialize to the "W != 2" part, -Wmaybe-uninitialized is unneeded in the 'W == 2" part.
Quoted 6 lines
Maybe, the same applies to -Wunused-but-set-parameter.
Shall we drop warnings implied by another, or
is it clearer to explicitly add either -Wfoo or -Wno-foo?If desired, we can do such a clean-up later, though.
Right, we can probably drop that, I've gone back and forth on this how to handle these. Some of the warnings are handled differently between gcc and clang, or differently between compiler versions, where they are sometimes implied and sometimes need to be specified explicitly.
What I've tried to do here is to do the change in the least invasive way to ensure that this larger patch does not change the behavior. My preference would be for you to merge it like this unless you see a bug, and then do another cleanup pass where we remove the ones implied by either -Wall or -Wextra on all known versions.
I'll be on vacation the next few weeks starting on Tuesday and will be able to reply to emails, but won't have a chance to sufficiently test any significant reworks of my series before the merge window.
Arnd
Re: [PATCH 3/9] Kbuild: avoid duplicate warning options
Quoted 29 lines · Arnd Bergmann
Quoted 7 lines · Masahiro Yamada
On Sat, Aug 12, 2023 at 5:50 PM Arnd Bergmann <[email protected]> wrote:
GCC manual says -Wall implies -Wmaybe-uninitialized.
If you move -Wno-maybe-uninitialize to the "W != 2" part, -Wmaybe-uninitialized is unneeded in the 'W == 2" part.
Quoted 6 lines
Maybe, the same applies to -Wunused-but-set-parameter.
Shall we drop warnings implied by another, or
is it clearer to explicitly add either -Wfoo or -Wno-foo?If desired, we can do such a clean-up later, though.
Right, we can probably drop that, I've gone back and forth on this how to handle these. Some of the warnings are handled differently between gcc and clang, or differently between compiler versions, where they are sometimes implied and sometimes need to be specified explicitly.
What I've tried to do here is to do the change in the least invasive way to ensure that this larger patch does not change the behavior. My preference would be for you to merge it like this unless you see a bug, and then do another cleanup pass where we remove the ones implied by either -Wall or -Wextra on all known versions.
Quoted 6 lines
I'll be on vacation the next few weeks starting on Tuesday and will be able to reply to emails, but won't have a chance to sufficiently test any significant reworks of my series before the merge window.
Arnd
Applied to linux-kbuild. Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 4/9 extrawarn: don't turn off -Wshift-negative-value for gcc-9
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
The warning does nothing for newer versions of gcc since -fno-strict-overflow is used, on old versions it warns about lines that would be undefined otherwise:
fs/isofs/util.c: In function 'iso_date':fs/isofs/util.c:40:14: error: left shift of negative value [-Werror=shift-negative-value]
tz |= (-1 << 8);
^~
drivers/video/fbdev/tdfxfb.c: In function 'tdfxfb_probe':
drivers/video/fbdev/tdfxfb.c:1482:17: error: left shift of negative value [-Werror=shift-negative-value]
(PAGE_MASK << 1);
^~
drivers/tty/serial/8250/8250_core.c: In function 'serial8250_request_rsa_resource':
drivers/tty/serial/8250/8250_core.c:350:38: error: left shift of negative value [-Werror=shift-negative-value]
unsigned long start = UART_RSA_BASE << up->port.regshift;
^~
drivers/tty/serial/8250/8250_core.c: In function 'serial8250_release_rsa_resource':
drivers/tty/serial/8250/8250_core.c:371:39: error: left shift of negative value [-Werror=shift-negative-value]
unsigned long offset = UART_RSA_BASE << up->port.regshift;
^~
drivers/clk/mvebu/dove-divider.c: In function 'dove_set_clock':
drivers/clk/mvebu/dove-divider.c:145:14: error: left shift of negative value [-Werror=shift-negative-value]
mask = ~(~0 << dc->div_bit_size) << dc->div_bit_start;
^~drivers/block/drbd/drbd_main.c: In function 'dcbp_set_pad_bits':drivers/block/drbd/drbd_main.c:1098:37: error: left shift of negative value [-Werror=shift-negative-value]
p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4);
Disable these conditionally to keep the command line a little shorter.
--- scripts/Makefile.extrawarn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/Makefile.extrawarn +3 -1
@@ -171,12 +171,14 @@ else # The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-type-limits -KBUILD_CFLAGS += -Wno-shift-negative-value ifdef CONFIG_CC_IS_CLANG KBUILD_CFLAGS += -Wno-initializer-overrides else KBUILD_CFLAGS += -Wno-maybe-uninitialized +ifneq ($(call gcc-min-version, 90100),y) +KBUILD_CFLAGS += $(call cc-disable-warning, shift-negative-value) +endif endif endif
Signature · 1 line
2.39.2
Re: [PATCH 4/9] extrawarn: don't turn off -Wshift-negative-value for gcc-9
Quoted 27 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The warning does nothing for newer versions of gcc since -fno-strict-overflow is used, on old versions it warns about lines that would be undefined otherwise:
fs/isofs/util.c: In function 'iso_date':fs/isofs/util.c:40:14: error: left shift of negative value [-Werror=shift-negative-value]tz |= (-1 << 8); ^~ drivers/video/fbdev/tdfxfb.c: In function 'tdfxfb_probe': drivers/video/fbdev/tdfxfb.c:1482:17: error: left shift of negative value [-Werror=shift-negative-value] (PAGE_MASK << 1); ^~ drivers/tty/serial/8250/8250_core.c: In function 'serial8250_request_rsa_resource': drivers/tty/serial/8250/8250_core.c:350:38: error: left shift of negative value [-Werror=shift-negative-value] unsigned long start = UART_RSA_BASE << up->port.regshift; ^~ drivers/tty/serial/8250/8250_core.c: In function 'serial8250_release_rsa_resource': drivers/tty/serial/8250/8250_core.c:371:39: error: left shift of negative value [-Werror=shift-negative-value] unsigned long offset = UART_RSA_BASE << up->port.regshift; ^~ drivers/clk/mvebu/dove-divider.c: In function 'dove_set_clock': drivers/clk/mvebu/dove-divider.c:145:14: error: left shift of negative value [-Werror=shift-negative-value] mask = ~(~0 << dc->div_bit_size) << dc->div_bit_start; ^~
Quoted 5 lines
drivers/block/drbd/drbd_main.c: In function 'dcbp_set_pad_bits':drivers/block/drbd/drbd_main.c:1098:37: error: left shift of negative value [-Werror=shift-negative-value]
p->encoding= (p->encoding& (~0x7 << 4)) | (n << 4);Disable these conditionally to keep the command line a little shorter.
Just a nit for the commit subject and description.
It mentions only gcc, but also affects clang.
Is the following a better subject?
extrawarn: don't turn off -Wshift-negative-value for gcc-9+ or clang
or
extrawarn: turn off -Wshift-negative-value only for gcc < 9
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 5/9 extrawarn: enable format and stringop overflow warnings in W=1
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
The stringop and format warnings got disabled globally when they were newly introduced in commit bd664f6b3e376 ("disable new gcc-7.1.1 warnings for now"), 217c3e0196758 ("disable stringop truncation warnings for now") and 5a76021c2eff7 ("gcc-10: disable 'stringop-overflow' warning for now").
In all cases, the sentiment at the time was that the warnings are useful, and we actually addressed a number of real bugs based on them, but we never managed to eliminate them all because even the build bots using W=1 builds only see the -Wstringop-truncation warnings that are enabled at that level.
Move these into the W=1 section to give them a larger build coverage and actually eliminate them over time.
--- scripts/Makefile.extrawarn | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
scripts/Makefile.extrawarn +6 -5
@@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes KBUILD_CFLAGS += -Wno-format-security KBUILD_CFLAGS += -Wno-trigraphs KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifneq ($(CONFIG_FRAME_WARN),0)
@@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# We'll want to enable this eventually, but it's not going away for 5.7 at least -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) - # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
@@ -111,6 +106,9 @@ 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-overflow) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) KBUILD_CPPFLAGS += -Wundef
@@ -123,6 +121,9 @@ else 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) +KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) +KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) ifdef CONFIG_CC_IS_CLANG
Signature · 1 line
2.39.2
Re: [PATCH 5/9] extrawarn: enable format and stringop overflow warnings in W=1
Quoted 46 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The stringop and format warnings got disabled globally when they were newly introduced in commit
bd664f6b3e376("disable new gcc-7.1.1 warnings for now"),217c3e0196758("disable stringop truncation warnings for now") and5a76021c2eff7("gcc-10: disable 'stringop-overflow' warning for now").In all cases, the sentiment at the time was that the warnings are useful, and we actually addressed a number of real bugs based on them, but we never managed to eliminate them all because even the build bots using W=1 builds only see the -Wstringop-truncation warnings that are enabled at that level.
Move these into the W=1 section to give them a larger build coverage and actually eliminate them over time.
Signed-off-by Arnd Bergmann <[email protected]>--- scripts/Makefile.extrawarn | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)scripts/Makefile.extrawarn +0
-5@@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes KBUILD_CFLAGS += -Wno-format-security KBUILD_CFLAGS += -Wno-trigraphs KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifneq ($(CONFIG_FRAME_WARN),0)@@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# We'll want to enable this eventually, but it's not going away for 5.7 at least -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) - # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
scripts/Makefile.extrawarn KBUILD_CFLAGS += -Wmissing-include-dirs · line 110
Quoted 5 lines
scripts/Makefile.extrawarn +2
-0@@ -111,6 +106,9 @@ 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)
These are redundant because -Wall implies
-Wformat-overflow and -Wformat-truncation
according to the GCC manual.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 5/9] extrawarn: enable format and stringop overflow warnings in W=1
Quoted 62 lines · Masahiro Yamada
Quoted 46 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The stringop and format warnings got disabled globally when they were newly introduced in commit
bd664f6b3e376("disable new gcc-7.1.1 warnings for now"),217c3e0196758("disable stringop truncation warnings for now") and5a76021c2eff7("gcc-10: disable 'stringop-overflow' warning for now").In all cases, the sentiment at the time was that the warnings are useful, and we actually addressed a number of real bugs based on them, but we never managed to eliminate them all because even the build bots using W=1 builds only see the -Wstringop-truncation warnings that are enabled at that level.
Move these into the W=1 section to give them a larger build coverage and actually eliminate them over time.
Signed-off-by Arnd Bergmann <[email protected]>--- scripts/Makefile.extrawarn | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)scripts/Makefile.extrawarn +0
-5@@ -16,8 +16,6 @@ KBUILD_CFLAGS += -Werror=strict-prototypes KBUILD_CFLAGS += -Wno-format-security KBUILD_CFLAGS += -Wno-trigraphs KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) -KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifneq ($(CONFIG_FRAME_WARN),0)@@ -56,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# We'll want to enable this eventually, but it's not going away for 5.7 at least -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) - # Another good warning that we'll want to enable eventually KBUILD_CFLAGS += $(call cc-disable-warning, restrict)scripts/Makefile.extrawarn KBUILD_CFLAGS += -Wmissing-include-dirs · line 110
Quoted 5 lines
scripts/Makefile.extrawarn +2
-0@@ -111,6 +106,9 @@ 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)These are redundant because -Wall implies
-Wformat-overflow and -Wformat-truncation
according to the GCC manual.
Quoted 3 lines
--
Best Regards
Masahiro Yamada
Applied to linux-kbuild. Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 5/9] extrawarn: enable format and stringop overflow warnings in W=1
In reply to Masahiro YamadaQuoted 4 lines · Masahiro Yamada
These are redundant because -Wall implies
-Wformat-overflow and -Wformat-truncation
according to the GCC manual.
To triple check this grouping behavior in clang, there's a utility called diagtool.
$ diagtool tree
will print the hierarchy of diagnostics and color code them to explain whether they're on/off by default or not-implemented-but-recognized.
For the above two -Wformat-* warnings, note that clang does not yet implement those. I've filed
https://github.com/llvm/llvm-project/issues/64871 to track that.
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH 6/9 extrawarn: move -Wrestrict into W=1 warnings
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
There are few of these, so enable them whenever W=1 is enabled.
--- scripts/Makefile.extrawarn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
scripts/Makefile.extrawarn +2 -3
@@ -54,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# Another good warning that we'll want to enable eventually -KBUILD_CFLAGS += $(call cc-disable-warning, restrict) - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -99,6 +96,7 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations +KBUILD_CFLAGS += $(call cc-option, -Wrestrict) KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-prototypes KBUILD_CFLAGS += -Wold-style-definition
@@ -120,6 +118,7 @@ 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)
Signature · 1 line
2.39.2
Re: [PATCH 6/9] extrawarn: move -Wrestrict into W=1 warnings
Quoted 25 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
There are few of these, so enable them whenever W=1 is enabled.
Signed-off-by Arnd Bergmann <[email protected]>--- scripts/Makefile.extrawarn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)scripts/Makefile.extrawarn +0
-3@@ -54,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# Another good warning that we'll want to enable eventually -KBUILD_CFLAGS += $(call cc-disable-warning, restrict) - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions
scripts/Makefile.extrawarn ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) · line 99
Quoted 4 lines
scripts/Makefile.extrawarn +1
-0@@ -99,6 +96,7 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations +KBUILD_CFLAGS += $(call cc-option, -Wrestrict)
Like the previous patch, -Wall implies -Wrestrict.
I'd like to remove it as we can save cc-option call.
Quoted 14 lines
scripts/Makefile.extrawarn +1
-1KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-prototypes KBUILD_CFLAGS += -Wold-style-definition@@ -120,6 +118,7 @@ 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
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 6/9] extrawarn: move -Wrestrict into W=1 warnings
In reply to Arnd BergmannQuoted 41 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
There are few of these, so enable them whenever W=1 is enabled.
Signed-off-by Arnd Bergmann <[email protected]>--- scripts/Makefile.extrawarn | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)scripts/Makefile.extrawarn +2
-4@@ -54,9 +54,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign # globally built with -Wcast-function-type. KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) -# Another good warning that we'll want to enable eventually -KBUILD_CFLAGS += $(call cc-disable-warning, restrict) - # The allocators already balk at large sizes, so silence the compiler # warnings for bounds checks involving those possible values. While # -Wno-alloc-size-larger-than would normally be used here, earlier versions@@ -99,6 +96,7 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations +KBUILD_CFLAGS += $(call cc-option, -Wrestrict) KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-prototypes KBUILD_CFLAGS += -Wold-style-definition@@ -120,6 +118,7 @@ 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) --
Quoted 2 lines
2.39.2
Applied to linux-kbuild. Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 7/9 extrawarn: do not disable -Wmain at W=1 level
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
There is only one function in architecture independent code that has a local variable named main(), and it seems fine to warn about this at the W=1 level, so move it there to declutter the normal command line slightly.
--- scripts/Makefile.extrawarn | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/Makefile.extrawarn +2 -4
@@ -29,10 +29,6 @@ KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds ifdef CONFIG_CC_IS_CLANG # The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable. KBUILD_CFLAGS += -Wno-gnu -else - -# gcc inanely warns about local variables called 'main' -KBUILD_CFLAGS += -Wno-main endif # These warnings generated too much noise in a regular build.
@@ -143,6 +139,8 @@ 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) +else +KBUILD_CFLAGS += -Wno-main endif endif
Signature · 1 line
2.39.2
PATCH 8/9 extrawarn: enable more warnings in W=2
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
These four warning options are always disabled, but actually meet the criteria for W=2, as they are sometimes useful and not prohibitively noisy:
-Wformat-security
-Wframe-address
-Waddress-of-packed-member
-Wtrigraphs
--- scripts/Makefile.extrawarn | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
scripts/Makefile.extrawarn +8 -4
@@ -13,10 +13,6 @@ KBUILD_CFLAGS += -Werror=implicit-function-declaration KBUILD_CFLAGS += -Werror=implicit-int KBUILD_CFLAGS += -Werror=return-type KBUILD_CFLAGS += -Werror=strict-prototypes -KBUILD_CFLAGS += -Wno-format-security -KBUILD_CFLAGS += -Wno-trigraphs -KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
@@ -157,6 +153,10 @@ KBUILD_CFLAGS += -Wmissing-field-initializers KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +KBUILD_CFLAGS += $(call cc-option, -Waddress-of-packed-member) +KBUILD_CFLAGS += $(call cc-option, -Wframe-address) +KBUILD_CFLAGS += -Wformat-security +KBUILD_CFLAGS += -Wtrigraphs ifdef CONFIG_CC_IS_CLANG KBUILD_CFLAGS += -Winitializer-overrides
@@ -169,6 +169,10 @@ else # The following turn off the warnings enabled by -Wextra KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-type-limits +KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) +KBUILD_CFLAGS += $(call cc-disable-warning, frame-address) +KBUILD_CFLAGS += -Wno-format-security +KBUILD_CFLAGS += -Wno-trigraphs ifdef CONFIG_CC_IS_CLANG KBUILD_CFLAGS += -Wno-initializer-overrides
Signature · 1 line
2.39.2
RFC PATCH 9/9 extrawarn: enable more W=1 warnings by default
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
A number of warning options from the W=1 set are completely clean in current kernels, so we should just enable them by default, including a lot of warnings that are part of -Wextra, so just turn on -Wextra by default.
The -Woverride-init, -Wvoid-pointer-to-enum-cast and -Wmissing-format-attribute warnings are part of -Wextra but still produce some legitimate warnings that need to be fixed, so leave them at the W=1 level but turn them off otherwise.
--- scripts/Makefile.extrawarn | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
scripts/Makefile.extrawarn +9 -11
@@ -72,6 +72,12 @@ 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 -Wno-unused-parameter +KBUILD_CFLAGS += -Wold-style-definition +KBUILD_CFLAGS += -Wmissing-include-dirs +KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) + # backward compatibility KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
@@ -86,16 +92,11 @@ export KBUILD_EXTRA_WARN # ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) -KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter KBUILD_CFLAGS += -Wmissing-declarations -KBUILD_CFLAGS += $(call cc-option, -Wrestrict) KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-prototypes -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-overflow)
@@ -110,8 +111,7 @@ 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, missing-format-attribute) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
@@ -131,12 +131,10 @@ ifeq ($(call clang-min-version, 120000),y) KBUILD_CFLAGS += -Wformat-insufficient-args endif 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-void-pointer-to-enum-cast else KBUILD_CFLAGS += -Wno-main +KBUILD_CFLAGS += -Wno-override-init endif endif
Signature · 1 line
2.39.2
Nathan Chancellor
maintainerRe: [PATCH 9/9] [RFC] extrawarn: enable more W=1 warnings by default
Quoted 12 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
A number of warning options from the W=1 set are completely clean in current kernels, so we should just enable them by default, including a lot of warnings that are part of -Wextra, so just turn on -Wextra by default.
The -Woverride-init, -Wvoid-pointer-to-enum-cast and -Wmissing-format-attribute warnings are part of -Wextra but still produce some legitimate warnings that need to be fixed, so leave them at the W=1 level but turn them off otherwise.
Signed-off-by Arnd Bergmann <[email protected]>
...
scripts/Makefile.extrawarn ifeq ($(call clang-min-version, 120000),y) · line 137
Quoted 3 lines
scripts/Makefile.extrawarn +0
-3-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)
I am still running through my builds but I don't think that dropping these three is acceptable at the moment. I see a good number of all of these warnings in -next still. I see some patches that I have picked up to address a couple of the really noisy ones but some others that I looked at are not fixed. I'll have a list eventually.
Cheers,
Nathan
Arnd Bergmann
maintainerRe: [PATCH 9/9] [RFC] extrawarn: enable more W=1 warnings by default
Quoted 14 lines · Nathan Chancellor
Quoted 12 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
A number of warning options from the W=1 set are completely clean in current kernels, so we should just enable them by default, including a lot of warnings that are part of -Wextra, so just turn on -Wextra by default.
The -Woverride-init, -Wvoid-pointer-to-enum-cast and -Wmissing-format-attribute warnings are part of -Wextra but still produce some legitimate warnings that need to be fixed, so leave them at the W=1 level but turn them off otherwise.
Signed-off-by Arnd Bergmann <[email protected]>...
Quoted 9 lines
scripts/Makefile.extrawarn ifeq ($(call clang-min-version, 120000),y) · line 137
Quoted 3 lines
scripts/Makefile.extrawarn +0
-3-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)I am still running through my builds but I don't think that dropping these three is acceptable at the moment. I see a good number of all of these warnings in -next still. I see some patches that I have picked up to address a couple of the really noisy ones but some others that I looked at are not fixed. I'll have a list eventually.
Ok, thanks. I have a backlog of warning fixes in my randconfig tree, which is currently clean with these warnings addressed, at least on arm/arm64/x86 and it looks like there are a couple that I've never sent out so far. I'll drop the above for now, as I won't have time to send all the fixes before my vacation.
I can provide the ones I have off-list for reference, but there are a couple that are missing changelog texts or that I'm not entirely sure about myself.
Arnd
Nathan Chancellor
maintainerRe: [PATCH 9/9] [RFC] extrawarn: enable more W=1 warnings by default
Quoted 25 lines · Arnd Bergmann
Quoted 14 lines · Nathan Chancellor
Quoted 12 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
A number of warning options from the W=1 set are completely clean in current kernels, so we should just enable them by default, including a lot of warnings that are part of -Wextra, so just turn on -Wextra by default.
The -Woverride-init, -Wvoid-pointer-to-enum-cast and -Wmissing-format-attribute warnings are part of -Wextra but still produce some legitimate warnings that need to be fixed, so leave them at the W=1 level but turn them off otherwise.
Signed-off-by Arnd Bergmann <[email protected]>...
Quoted 9 lines
scripts/Makefile.extrawarn ifeq ($(call clang-min-version, 120000),y) · line 137
Quoted 3 lines
scripts/Makefile.extrawarn +0
-3-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)I am still running through my builds but I don't think that dropping these three is acceptable at the moment. I see a good number of all of these warnings in -next still. I see some patches that I have picked up to address a couple of the really noisy ones but some others that I looked at are not fixed. I'll have a list eventually.
Quoted 5 lines
Ok, thanks. I have a backlog of warning fixes in my randconfig tree, which is currently clean with these warnings addressed, at least on arm/arm64/x86 and it looks like there are a couple that I've never sent out so far. I'll drop the above for now, as I won't have time to send all the fixes before my vacation.
Thanks, that takes care of the vast majority of extra warnings that this series produces. I have included all my build logs at [1].
The slightly-filtered-warnings file is the result of searching for all warnings in the log files and passing them through 'sort | uniq -c', additionally ignoring the instances of -Wnull-pointer-arithmetic that are present in certain configurations, as those are pretty well known at this point.
The more-filtered-warnings file does the same thing but also ignores instances of the three warnings above, which just reveals some instances of -Wunused-but-set-parameter, which I am pretty sure I have seen you sent fixes for recently, so I think with those three warnings left as disabled, this series should be safe.
Cheers,
Nathan