]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Fix mis-uses of 'cc-option' for warning disablement
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 Apr 2025 17:08:29 +0000 (10:08 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 Apr 2025 17:08:29 +0000 (10:08 -0700)
This was triggered by one of my mis-uses causing odd build warnings on
sparc in linux-next, but while figuring out why the "obviously correct"
use of cc-option caused such odd breakage, I found eight other cases of
the same thing in the tree.

The root cause is that 'cc-option' doesn't work for checking negative
warning options (ie things like '-Wno-stringop-overflow') because gcc
will silently accept options it doesn't recognize, and so 'cc-option'
ends up thinking they are perfectly fine.

And it all works, until you have a situation where _another_ warning is
emitted.  At that point the compiler will go "Hmm, maybe the user
intended to disable this warning but used that wrong option that I
didn't recognize", and generate a warning for the unrecognized negative
option.

Which explains why we have several cases of this in the tree: the
'cc-option' test really doesn't work for this situation, but most of the
time it simply doesn't matter that ity doesn't work.

The reason my recently added case caused problems on sparc was pointed
out by Thomas Weißschuh: the sparc build had a previous explicit warning
that then triggered the new one.

I think the best fix for this would be to make 'cc-option' a bit smarter
about this sitation, possibly by adding an intentional warning to the
test case that then triggers the unrecognized option warning reliably.

But the short-term fix is to replace 'cc-option' with an existing helper
designed for this exact case: 'cc-disable-warning', which picks the
negative warning but uses the positive form for testing the compiler
support.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Link: https://lore.kernel.org/all/20250422204718.0b4e3f81@canb.auug.org.au/
Explained-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Makefile
arch/loongarch/kernel/Makefile
arch/loongarch/kvm/Makefile
arch/riscv/kernel/Makefile
scripts/Makefile.extrawarn

index e94bbb2298c8d61d92c4d71bd36160c717e4bd8c..07f818186151a1f67e60671998caedca527e67a8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1053,11 +1053,11 @@ NOSTDINC_FLAGS += -nostdinc
 KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
 
 #Currently, disable -Wstringop-overflow for GCC 11, globally.
-KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
+KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow)
 KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
 
 #Currently, disable -Wunterminated-string-initialization as broken
-KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization)
+KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization)
 
 # disable invalid "can't wrap" optimizations for signed / pointers
 KBUILD_CFLAGS  += -fno-strict-overflow
index 4853e8b04c6fbead5c58cade6d77df65f073e537..f9dcaa60033d95c77ad7b8337b204aa2eccad886 100644 (file)
@@ -21,10 +21,10 @@ obj-$(CONFIG_CPU_HAS_LBT)   += lbt.o
 
 obj-$(CONFIG_ARCH_STRICT_ALIGN)        += unaligned.o
 
-CFLAGS_module.o                += $(call cc-option,-Wno-override-init,)
-CFLAGS_syscall.o       += $(call cc-option,-Wno-override-init,)
-CFLAGS_traps.o         += $(call cc-option,-Wno-override-init,)
-CFLAGS_perf_event.o    += $(call cc-option,-Wno-override-init,)
+CFLAGS_module.o                += $(call cc-disable-warning, override-init)
+CFLAGS_syscall.o       += $(call cc-disable-warning, override-init)
+CFLAGS_traps.o         += $(call cc-disable-warning, override-init)
+CFLAGS_perf_event.o    += $(call cc-disable-warning, override-init)
 
 ifdef CONFIG_FUNCTION_TRACER
   ifndef CONFIG_DYNAMIC_FTRACE
index f4c8e35c216a4bed66eb5ebc434c0e7f58985cac..cb41d9265662f4070b1410afa5700a5f19bc9c5b 100644 (file)
@@ -21,4 +21,4 @@ kvm-y += intc/eiointc.o
 kvm-y += intc/pch_pic.o
 kvm-y += irqfd.o
 
-CFLAGS_exit.o  += $(call cc-option,-Wno-override-init,)
+CFLAGS_exit.o  += $(call cc-disable-warning, override-init)
index 8d186bfced451ea03d7cd8b1a660f449c92fdb08..f7480c9c6f8d73be6652eba46343b9dcf22b8a53 100644 (file)
@@ -9,8 +9,8 @@ CFLAGS_REMOVE_patch.o   = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_sbi.o    = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
 endif
-CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,)
-CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,)
+CFLAGS_syscall_table.o += $(call cc-disable-warning, override-init)
+CFLAGS_compat_syscall_table.o += $(call cc-disable-warning, override-init)
 
 ifdef CONFIG_KEXEC_CORE
 AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax)
index d75897559d184070ecdf79cc5774b8a45d443107..2d6e59561c9d041895339c922c55545b883b0025 100644 (file)
@@ -15,7 +15,7 @@ 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, frame-address)
 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 KBUILD_CFLAGS += -Wmissing-declarations
 KBUILD_CFLAGS += -Wmissing-prototypes