From 660e899103e29aabcc05447ab20684811ea86107 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Sat, 20 Dec 2025 12:02:19 +0100 Subject: kbuild: remove gcc's -Wtype-limits W=2 builds are heavily polluted by the -Wtype-limits warning. Here are some W=12 statistics on Linux v6.19-rc1 for an x86_64 defconfig (with just CONFIG_WERROR set to "n") using gcc 14.3.1: Warning name count percent ------------------------------------------------- -Wlogical-op 2 0.00 % -Wmaybe-uninitialized 138 0.20 % -Wunused-macros 869 1.24 % -Wmissing-field-initializers 1418 2.02 % -Wshadow 2234 3.19 % -Wtype-limits 65378 93.35 % ------------------------------------------------- Total 70039 100.00 % As we can see, -Wtype-limits represents the vast majority of all warnings. The reason behind this is that these warnings appear in some common header files, meaning that some unique warnings are repeated tens of thousands of times (once per header inclusion). Add to this the fact that each warning is coupled with a dozen lines detailing some macro expansion. The end result is that the W=2 output is just too bloated and painful to use. Three years ago, I proposed in [1] modifying one such header to silence that noise. Because the code was not faulty, Linus rejected the idea and instead suggested simply removing that warning. At that time, I could not bring myself to send such a patch because, despite its problems, -Wtype-limits would still catch the below bug: unsigned int ret; ret = check(); if (ret < 0) error(); Meanwhile, based on another suggestion from Linus, I added a new check to sparse [2] that would catch the above bug without the useless spam. With this, remove gcc's -Wtype-limits. People who still want to catch incorrect comparisons between unsigned integers and zero can now use sparse instead. On a side note, clang also has a -Wtype-limits warning but: * it is not enabled in the kernel at the moment because, contrary to gcc, clang did not include it under -Wextra. * it does not warn if the code results from a macro expansion. So, if activated, it would not cause as much spam as gcc does. * -Wtype-limits is split into four sub-warnings [3] meaning that if it were to be activated, we could select which one to keep. So there is no present need to explicitly disable -Wtype-limits in clang. [1] linux/bits.h: GENMASK_INPUT_CHECK: reduce W=2 noise by 31% treewide Link: https://lore.kernel.org/all/20220308141201.2343757-1-mailhol.vincent@wanadoo.fr/ [2] Warn about "unsigned value that used to be signed against zero" Link: https://lore.kernel.org/all/20250921061337.3047616-1-mailhol@kernel.org/ [3] clang's -Wtype-limits Link: https://clang.llvm.org/docs/DiagnosticsReference.html#wtype-limits Reviewed-by: Nicolas Schier Signed-off-by: Vincent Mailhol Link: https://patch.msgid.link/20251220-remove_wtype-limits-v3-1-24b170af700e@kernel.org Signed-off-by: Nathan Chancellor --- scripts/Makefile.warn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts/Makefile.warn') diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn index 68e6fafcb80c..c593ab1257de 100644 --- a/scripts/Makefile.warn +++ b/scripts/Makefile.warn @@ -55,6 +55,9 @@ else KBUILD_CFLAGS += -Wno-main endif +# Too noisy on range checks and in macros handling both signed and unsigned. +KBUILD_CFLAGS += -Wno-type-limits + # These result in bogus false positives KBUILD_CFLAGS += $(call cc-option, -Wno-dangling-pointer) @@ -174,7 +177,6 @@ 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 -- cgit v1.2.3 From 379b749add7eff1d1e9fdd53206e1ec5e7cd2266 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Tue, 13 Jan 2026 08:29:58 +0100 Subject: kbuild: Drop superfluous compiler option checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many of the compiler option checks are not necessary anymore with the current supported versions of compilers (clang 15+, GCC 8.1+). Remove them. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20260113-kbuild-cc-option-v1-1-011314a0f7f1@weissschuh.net [nathan: Add minor note about currently supported compilers] Signed-off-by: Nathan Chancellor --- Makefile | 2 +- scripts/Makefile.warn | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'scripts/Makefile.warn') diff --git a/Makefile b/Makefile index ad91e6a936aa..362df202fb8a 100644 --- a/Makefile +++ b/Makefile @@ -1102,7 +1102,7 @@ KBUILD_CFLAGS += -fno-builtin-wcslen # change __FILE__ to the relative path to the source directory ifdef building_out_of_srctree -KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=) +KBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/= endif # include additional Makefiles when needed diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn index c593ab1257de..5567da6c7dfe 100644 --- a/scripts/Makefile.warn +++ b/scripts/Makefile.warn @@ -16,7 +16,7 @@ KBUILD_CFLAGS += -Werror=return-type KBUILD_CFLAGS += -Werror=strict-prototypes KBUILD_CFLAGS += -Wno-format-security KBUILD_CFLAGS += -Wno-trigraphs -KBUILD_CFLAGS += $(call cc-option, -Wno-frame-address) +KBUILD_CFLAGS += -Wno-frame-address KBUILD_CFLAGS += $(call cc-option, -Wno-address-of-packed-member) KBUILD_CFLAGS += -Wmissing-declarations KBUILD_CFLAGS += -Wmissing-prototypes @@ -75,7 +75,7 @@ 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) +KBUILD_CFLAGS += -Wcast-function-type # Currently, disable -Wstringop-overflow for GCC 11, globally. KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow) @@ -102,7 +102,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH) KBUILD_CFLAGS += -Werror=date-time # enforce correct pointer usage -KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) +KBUILD_CFLAGS += -Werror=incompatible-pointer-types # Require designated initializers for all marked structures KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) @@ -119,7 +119,7 @@ ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wmissing-format-attribute KBUILD_CFLAGS += -Wmissing-include-dirs -KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) +KBUILD_CFLAGS += -Wunused-const-variable KBUILD_CPPFLAGS += -Wundef KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 @@ -128,12 +128,12 @@ else # Some diagnostics enabled by default are noisy. # Suppress them by using -Wno... except for W=1. -KBUILD_CFLAGS += $(call cc-option, -Wno-unused-but-set-variable) -KBUILD_CFLAGS += $(call cc-option, -Wno-unused-const-variable) +KBUILD_CFLAGS += -Wno-unused-but-set-variable +KBUILD_CFLAGS += -Wno-unused-const-variable KBUILD_CFLAGS += $(call cc-option, -Wno-packed-not-aligned) KBUILD_CFLAGS += $(call cc-option, -Wno-format-overflow) ifdef CONFIG_CC_IS_GCC -KBUILD_CFLAGS += $(call cc-option, -Wno-format-truncation) +KBUILD_CFLAGS += -Wno-format-truncation endif KBUILD_CFLAGS += $(call cc-option, -Wno-stringop-truncation) @@ -148,14 +148,11 @@ KBUILD_CFLAGS += -Wno-format # problematic. KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull -# Requires clang-12+. -ifeq ($(call clang-min-version, 120000),y) KBUILD_CFLAGS += -Wformat-insufficient-args endif -endif -KBUILD_CFLAGS += $(call cc-option, -Wno-pointer-to-enum-cast) +KBUILD_CFLAGS += -Wno-pointer-to-enum-cast KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare -KBUILD_CFLAGS += $(call cc-option, -Wno-unaligned-access) +KBUILD_CFLAGS += -Wno-unaligned-access KBUILD_CFLAGS += -Wno-enum-compare-conditional endif @@ -169,7 +166,7 @@ ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wdisabled-optimization KBUILD_CFLAGS += -Wshadow KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) -KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +KBUILD_CFLAGS += -Wunused-macros KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 -- cgit v1.2.3