Skip to content

Commit 3f856d5

Browse files
torvaldsgregkh
authored andcommitted
Fix mis-uses of 'cc-option' for warning disablement
commit a79be02 upstream. 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 <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Explained-by: Thomas Weißschuh <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d66cf77 commit 3f856d5

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,11 @@ NOSTDINC_FLAGS += -nostdinc
998998
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
999999

10001000
#Currently, disable -Wstringop-overflow for GCC 11, globally.
1001-
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
1001+
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow)
10021002
KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
10031003

10041004
#Currently, disable -Wunterminated-string-initialization as broken
1005-
KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization)
1005+
KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization)
10061006

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

arch/loongarch/kernel/Makefile

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ kvm-y += tlb.o
1919
kvm-y += vcpu.o
2020
kvm-y += vm.o
2121

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

arch/riscv/kernel/Makefile

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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)