Skip to content

Commit a79be02

Browse files
committed
Fix mis-uses of 'cc-option' for warning disablement
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>
1 parent 82efd56 commit a79be02

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,11 @@ NOSTDINC_FLAGS += -nostdinc
10531053
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
10541054

10551055
#Currently, disable -Wstringop-overflow for GCC 11, globally.
1056-
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
1056+
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow)
10571057
KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
10581058

10591059
#Currently, disable -Wunterminated-string-initialization as broken
1060-
KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization)
1060+
KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization)
10611061

10621062
# disable invalid "can't wrap" optimizations for signed / pointers
10631063
KBUILD_CFLAGS += -fno-strict-overflow

arch/loongarch/kernel/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ obj-$(CONFIG_CPU_HAS_LBT) += lbt.o
2121

2222
obj-$(CONFIG_ARCH_STRICT_ALIGN) += unaligned.o
2323

24-
CFLAGS_module.o += $(call cc-option,-Wno-override-init,)
25-
CFLAGS_syscall.o += $(call cc-option,-Wno-override-init,)
26-
CFLAGS_traps.o += $(call cc-option,-Wno-override-init,)
27-
CFLAGS_perf_event.o += $(call cc-option,-Wno-override-init,)
24+
CFLAGS_module.o += $(call cc-disable-warning, override-init)
25+
CFLAGS_syscall.o += $(call cc-disable-warning, override-init)
26+
CFLAGS_traps.o += $(call cc-disable-warning, override-init)
27+
CFLAGS_perf_event.o += $(call cc-disable-warning, override-init)
2828

2929
ifdef CONFIG_FUNCTION_TRACER
3030
ifndef CONFIG_DYNAMIC_FTRACE

arch/loongarch/kvm/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ kvm-y += intc/eiointc.o
2121
kvm-y += intc/pch_pic.o
2222
kvm-y += irqfd.o
2323

24-
CFLAGS_exit.o += $(call cc-option,-Wno-override-init,)
24+
CFLAGS_exit.o += $(call cc-disable-warning, override-init)

arch/riscv/kernel/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE)
99
CFLAGS_REMOVE_sbi.o = $(CC_FLAGS_FTRACE)
1010
CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
1111
endif
12-
CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,)
13-
CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,)
12+
CFLAGS_syscall_table.o += $(call cc-disable-warning, override-init)
13+
CFLAGS_compat_syscall_table.o += $(call cc-disable-warning, override-init)
1414

1515
ifdef CONFIG_KEXEC_CORE
1616
AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax)

scripts/Makefile.extrawarn

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ KBUILD_CFLAGS += -Werror=return-type
1515
KBUILD_CFLAGS += -Werror=strict-prototypes
1616
KBUILD_CFLAGS += -Wno-format-security
1717
KBUILD_CFLAGS += -Wno-trigraphs
18-
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
18+
KBUILD_CFLAGS += $(call cc-disable-warning, frame-address)
1919
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
2020
KBUILD_CFLAGS += -Wmissing-declarations
2121
KBUILD_CFLAGS += -Wmissing-prototypes

0 commit comments

Comments
 (0)