|
| 1 | +From a79be02bba5c31f967885c7f3bf3a756d77d11d9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Linus Torvalds < [email protected]> |
| 3 | +Date: Wed, 23 Apr 2025 10:08:29 -0700 |
| 4 | +Subject: Fix mis-uses of 'cc-option' for warning disablement |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +This was triggered by one of my mis-uses causing odd build warnings on |
| 10 | +sparc in linux-next, but while figuring out why the "obviously correct" |
| 11 | +use of cc-option caused such odd breakage, I found eight other cases of |
| 12 | +the same thing in the tree. |
| 13 | + |
| 14 | +The root cause is that 'cc-option' doesn't work for checking negative |
| 15 | +warning options (ie things like '-Wno-stringop-overflow') because gcc |
| 16 | +will silently accept options it doesn't recognize, and so 'cc-option' |
| 17 | +ends up thinking they are perfectly fine. |
| 18 | + |
| 19 | +And it all works, until you have a situation where _another_ warning is |
| 20 | +emitted. At that point the compiler will go "Hmm, maybe the user |
| 21 | +intended to disable this warning but used that wrong option that I |
| 22 | +didn't recognize", and generate a warning for the unrecognized negative |
| 23 | +option. |
| 24 | + |
| 25 | +Which explains why we have several cases of this in the tree: the |
| 26 | +'cc-option' test really doesn't work for this situation, but most of the |
| 27 | +time it simply doesn't matter that ity doesn't work. |
| 28 | + |
| 29 | +The reason my recently added case caused problems on sparc was pointed |
| 30 | +out by Thomas Weißschuh: the sparc build had a previous explicit warning |
| 31 | +that then triggered the new one. |
| 32 | + |
| 33 | +I think the best fix for this would be to make 'cc-option' a bit smarter |
| 34 | +about this sitation, possibly by adding an intentional warning to the |
| 35 | +test case that then triggers the unrecognized option warning reliably. |
| 36 | + |
| 37 | +But the short-term fix is to replace 'cc-option' with an existing helper |
| 38 | +designed for this exact case: 'cc-disable-warning', which picks the |
| 39 | +negative warning but uses the positive form for testing the compiler |
| 40 | +support. |
| 41 | + |
| 42 | +Reported-by: Stephen Rothwell < [email protected]> |
| 43 | +Link: https://lore.kernel.org/all/ [email protected]/ |
| 44 | +Explained-by: Thomas Weißschuh < [email protected]> |
| 45 | +Signed-off-by: Linus Torvalds < [email protected]> |
| 46 | +--- |
| 47 | +Link: https://git.kernel.org/linus/a79be02bba5c31f967885c7f3bf3a756d77d11d9 |
| 48 | +--- |
| 49 | + Makefile | 4 ++-- |
| 50 | + arch/loongarch/kernel/Makefile | 8 ++++---- |
| 51 | + arch/loongarch/kvm/Makefile | 2 +- |
| 52 | + arch/riscv/kernel/Makefile | 4 ++-- |
| 53 | + scripts/Makefile.extrawarn | 2 +- |
| 54 | + 5 files changed, 10 insertions(+), 10 deletions(-) |
| 55 | + |
| 56 | +diff --git a/Makefile b/Makefile |
| 57 | +index 5f1754a87c13..525083444cb9 100644 |
| 58 | +--- a/Makefile |
| 59 | ++++ b/Makefile |
| 60 | +@@ -998,11 +998,11 @@ NOSTDINC_FLAGS += -nostdinc |
| 61 | + KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) |
| 62 | + |
| 63 | + #Currently, disable -Wstringop-overflow for GCC 11, globally. |
| 64 | +-KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow) |
| 65 | ++KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow) |
| 66 | + KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow) |
| 67 | + |
| 68 | + #Currently, disable -Wunterminated-string-initialization as broken |
| 69 | +-KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization) |
| 70 | ++KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization) |
| 71 | + |
| 72 | + # disable invalid "can't wrap" optimizations for signed / pointers |
| 73 | + KBUILD_CFLAGS += -fno-strict-overflow |
| 74 | +diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile |
| 75 | +index c9bfeda89e40..66132683f1ed 100644 |
| 76 | +--- a/arch/loongarch/kernel/Makefile |
| 77 | ++++ b/arch/loongarch/kernel/Makefile |
| 78 | +@@ -21,10 +21,10 @@ obj-$(CONFIG_CPU_HAS_LBT) += lbt.o |
| 79 | + |
| 80 | + obj-$(CONFIG_ARCH_STRICT_ALIGN) += unaligned.o |
| 81 | + |
| 82 | +-CFLAGS_module.o += $(call cc-option,-Wno-override-init,) |
| 83 | +-CFLAGS_syscall.o += $(call cc-option,-Wno-override-init,) |
| 84 | +-CFLAGS_traps.o += $(call cc-option,-Wno-override-init,) |
| 85 | +-CFLAGS_perf_event.o += $(call cc-option,-Wno-override-init,) |
| 86 | ++CFLAGS_module.o += $(call cc-disable-warning, override-init) |
| 87 | ++CFLAGS_syscall.o += $(call cc-disable-warning, override-init) |
| 88 | ++CFLAGS_traps.o += $(call cc-disable-warning, override-init) |
| 89 | ++CFLAGS_perf_event.o += $(call cc-disable-warning, override-init) |
| 90 | + |
| 91 | + ifdef CONFIG_FUNCTION_TRACER |
| 92 | + ifndef CONFIG_DYNAMIC_FTRACE |
| 93 | +diff --git a/arch/loongarch/kvm/Makefile b/arch/loongarch/kvm/Makefile |
| 94 | +index b2f4cbe01ae8..2e188e8f1468 100644 |
| 95 | +--- a/arch/loongarch/kvm/Makefile |
| 96 | ++++ b/arch/loongarch/kvm/Makefile |
| 97 | +@@ -19,4 +19,4 @@ kvm-y += tlb.o |
| 98 | + kvm-y += vcpu.o |
| 99 | + kvm-y += vm.o |
| 100 | + |
| 101 | +-CFLAGS_exit.o += $(call cc-option,-Wno-override-init,) |
| 102 | ++CFLAGS_exit.o += $(call cc-disable-warning, override-init) |
| 103 | +diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile |
| 104 | +index 69dc8aaab3fb..6b3b5255c889 100644 |
| 105 | +--- a/arch/riscv/kernel/Makefile |
| 106 | ++++ b/arch/riscv/kernel/Makefile |
| 107 | +@@ -9,8 +9,8 @@ CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE) |
| 108 | + CFLAGS_REMOVE_sbi.o = $(CC_FLAGS_FTRACE) |
| 109 | + CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) |
| 110 | + endif |
| 111 | +-CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) |
| 112 | +-CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) |
| 113 | ++CFLAGS_syscall_table.o += $(call cc-disable-warning, override-init) |
| 114 | ++CFLAGS_compat_syscall_table.o += $(call cc-disable-warning, override-init) |
| 115 | + |
| 116 | + ifdef CONFIG_KEXEC_CORE |
| 117 | + AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax) |
| 118 | +diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn |
| 119 | +index dc081cf46d21..c38067c1d655 100644 |
| 120 | +--- a/scripts/Makefile.extrawarn |
| 121 | ++++ b/scripts/Makefile.extrawarn |
| 122 | +@@ -15,7 +15,7 @@ KBUILD_CFLAGS += -Werror=return-type |
| 123 | + KBUILD_CFLAGS += -Werror=strict-prototypes |
| 124 | + KBUILD_CFLAGS += -Wno-format-security |
| 125 | + KBUILD_CFLAGS += -Wno-trigraphs |
| 126 | +-KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) |
| 127 | ++KBUILD_CFLAGS += $(call cc-disable-warning, frame-address) |
| 128 | + KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) |
| 129 | + KBUILD_CFLAGS += -Wmissing-declarations |
| 130 | + KBUILD_CFLAGS += -Wmissing-prototypes |
| 131 | +-- |
| 132 | +cgit 1.2.3-korg |
| 133 | + |
0 commit comments