kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS
Subsystems (6)
PATCH v3 1/2 kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS
CONFIG_WERROR turns warnings into errors, which happens only for *.c files because -Werror is added to KBUILD_CFLAGS.
Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors understand the -Werror option.
For example, you can put a #warning directive in any preprocessed code.
warning: #warning "this is a warning message" [-Wcpp]
If -Werror is added, it is promoted to an error.
error: #warning "this is a warning message" [-Werror=cpp]
This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way for *.c, *.S, *.lds.S or whatever needs preprocessing.
---
(no changes since v1)
Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
@@ -859,7 +859,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
Signature · 1 line
2.34.1
PATCH v3 2/2 kbuild: move -Wundef from KBUILD_CFLAGS to KBUILD_CPPFLAGS
The use of an undefined macro in an #if directive is warned, but only in *.c files. No warning from other files such as *.S, *.lds.S.
Since -Wundef is a preprocessor-related warning, it should be added to KBUILD_CPPFLAGS instead of KBUILD_CFLAGS.
Fix some uncovered issues.
[1] Add -D__LINUX_ARM_ARCH__=* to KBUILD_CPPFLAGS
In file included from arch/arm/kernel/vmlinux.lds.S:13:./arch/arm/include/asm/cache.h:23:31: warning: "__LINUX_ARM_ARCH__" is not defined, evaluates to 0 [-Wundef]
23 | #if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
| ^~~~~~~~~~~~~~~~~~
[2] Add missing #include <asm/pgtable.h>
In file included from arch/arm/mm/cache-v7.S:17:arch/arm/mm/proc-macros.S:109:5: warning: "L_PTE_SHARED" is not defined, evaluates to 0 [-Wundef]
109 | #if L_PTE_SHARED != PTE_EXT_SHARED
| ^~~~~~~~~~~~
arch/arm/mm/proc-macros.S:109:21: warning: "PTE_EXT_SHARED" is not defined, evaluates to 0 [-Wundef]
109 | #if L_PTE_SHARED != PTE_EXT_SHARED
| ^~~~~~~~~~~~~~
arch/arm/mm/proc-macros.S:113:10: warning: "L_PTE_XN" is not defined, evaluates to 0 [-Wundef]
113 | (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
| ^~~~~~~~
arch/arm/mm/proc-macros.S:113:19: warning: "L_PTE_USER" is not defined, evaluates to 0 [-Wundef]
113 | (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
| ^~~~~~~~~~
arch/arm/mm/proc-macros.S:113:30: warning: "L_PTE_RDONLY" is not defined, evaluates to 0 [-Wundef]
113 | (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
| ^~~~~~~~~~~~arch/arm/mm/proc-macros.S:113:43: warning: "L_PTE_DIRTY" is not defined, evaluates to 0 [-Wundef]
113 | (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
| ^~~~~~~~~~~arch/arm/mm/proc-macros.S:113:55: warning: "L_PTE_YOUNG" is not defined, evaluates to 0 [-Wundef]
113 | (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
| ^~~~~~~~~~~arch/arm/mm/proc-macros.S:114:10: warning: "L_PTE_PRESENT" is not defined, evaluates to 0 [-Wundef]
114 | L_PTE_PRESENT) > L_PTE_SHARED
| ^~~~~~~~~~~~~
arch/arm/mm/proc-macros.S:114:27: warning: "L_PTE_SHARED" is not defined, evaluates to 0 [-Wundef]
114 | L_PTE_PRESENT) > L_PTE_SHARED
| ^~~~~~~~~~~~[3] #if -> #ifdef
arch/riscv/kernel/head.S:329:5: warning: "CONFIG_RISCV_BOOT_SPINWAIT" is not defined, evaluates to 0 [-Wundef]
329 | #if CONFIG_RISCV_BOOT_SPINWAIT
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
[4] #elif -> #elif defined()
arch/s390/boot/decompressor.c:28:7: warning: "CONFIG_KERNEL_ZSTD" is not defined, evaluates to 0 [-Wundef]
28 | #elif CONFIG_KERNEL_ZSTD
| ^~~~~~~~~~~~~~~~~~
[5] Exclude arm64 for now
In file included from arch/arm64/kernel/vmlinux.lds.S:65:arch/arm64/include/asm/kernel-pgtable.h:135:41: warning: "PMD_SHIFT" is not defined, evaluates to 0 [-Wundef]
135 | #define ARM64_MEMSTART_SHIFT PMD_SHIFT
| ^~~~~~~~~
In file included from arch/arm64/include/asm/asm-uaccess.h:8,
from arch/arm64/kernel/entry.S:29:
arch/arm64/include/asm/kernel-pgtable.h:135:41: warning: "PMD_SHIFT" is not defined, evaluates to 0 [-Wundef]
135 | #define ARM64_MEMSTART_SHIFT PMD_SHIFT
| ^~~~~~~~~---
Changes in v3:
- Suppress arm64 warnings
Changes in v2:
- Fix warnings
Makefile | 4 ++-- arch/arm/Makefile | 1 + arch/arm/mm/proc-macros.S | 1 + arch/arm64/Makefile | 4 ++++ arch/riscv/kernel/head.S | 2 +- arch/s390/boot/decompressor.c | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-)
Makefile +2 -2
@@ -559,12 +559,12 @@ LINUXINCLUDE := \ $(USERINCLUDE) KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE -KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ +KBUILD_CFLAGS := -Wall -Werror=strict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror=implicit-function-declaration -Werror=implicit-int \ -Werror=return-type -Wno-format-security \ -std=gnu11 -KBUILD_CPPFLAGS := -D__KERNEL__ +KBUILD_CPPFLAGS := -D__KERNEL__ -Wundef KBUILD_RUSTFLAGS := $(rust_common_flags) \ --target=$(objtree)/rust/target.json \ -Cpanic=abort -Cembed-bitcode=n -Clto=n \
arch/arm/Makefile +1 -0
@@ -132,6 +132,7 @@ AFLAGS_ISA :=$(CFLAGS_ISA) endif # Need -Uarm for gcc < 3.x +KBUILD_CPPFLAGS += $(filter -D%, $(arch-y)) KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
arch/arm/mm/proc-macros.S +1 -0
@@ -6,6 +6,7 @@ * VM_EXEC */ #include <asm/asm-offsets.h> +#include <asm/pgtable.h> #include <asm/thread_info.h> #ifdef CONFIG_CPU_V7M
arch/arm64/Makefile +4 -0
@@ -36,6 +36,10 @@ ifeq ($(CONFIG_BROKEN_GAS_INST),y) $(warning Detected assembler with broken .inst; disassembly will be unreliable) endif +# REVISIT +KBUILD_CPPFLAGS := $(filter-out -Wundef, $(KBUILD_CPPFLAGS)) +KBUILD_CFLAGS += -Wundef + KBUILD_CFLAGS += -mgeneral-regs-only \ $(compat_vdso) $(cc_has_k_constraint) KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
arch/riscv/kernel/head.S +1 -1
@@ -326,7 +326,7 @@ clear_bss_done: call soc_early_init tail start_kernel -#if CONFIG_RISCV_BOOT_SPINWAIT +#ifdef CONFIG_RISCV_BOOT_SPINWAIT .Lsecondary_start: /* Set trap vector to spin forever to help debug */ la a3, .Lsecondary_park
arch/s390/boot/decompressor.c +1 -1
@@ -25,7 +25,7 @@#ifdef CONFIG_KERNEL_BZIP2 #define BOOT_HEAP_SIZE 0x400000 -#elif CONFIG_KERNEL_ZSTD +#elif defined(CONFIG_KERNEL_ZSTD )#define BOOT_HEAP_SIZE 0x30000#else #define BOOT_HEAP_SIZE 0x10000
Signature · 1 line
2.34.1
Nathan Chancellor
maintainerQuoted 44 lines · Masahiro Yamada
CONFIG_WERRORturns warnings into errors, which happens only for *.c files because -Werror is added toKBUILD_CFLAGS.Adding it to
KBUILD_CPPFLAGSmakes more sense because preprocessors understand the -Werror option.For example, you can put a #warning directive in any preprocessed code.
warning: #warning "this is a warning message" [-Wcpp]
If -Werror is added, it is promoted to an error.
error: #warning "this is a warning message" [-Werror=cpp]
This commit moves -Werror to
KBUILD_CPPFLAGSso it works in the same way for *.c, *.S, *.lds.S or whatever needs preprocessing.Signed-off-by Masahiro Yamada <[email protected]>Reviewed-by Nick Desaulniers <[email protected]>---
(no changes since v1)
Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Makefile +2
-1@@ -859,7 +859,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -DwarningsSignature · 1 line
2.34.1
For what it's worth, this is going to break 32-bit ARM builds with clang plus the integrated assembler due to
https://github.com/ClangBuiltLinux/linux/issues/1315:
clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]
Ultimately, I want -Wunused-command-line-argument to be an error anyways
(https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be nice to get these cleaned up before this goes in.
Cheers,
Nathan
Quoted 5 lines · Nathan Chancellor
Quoted 3 lines · Masahiro Yamada
CONFIG_WERRORturns warnings into errors, which happens only for *.c files because -Werror is added toKBUILD_CFLAGS.
Quoted 8 lines
Quoted 3 lines
Adding it to
KBUILD_CPPFLAGSmakes more sense because preprocessors understand the -Werror option.For what it's worth, this is going to break 32-bit ARM builds with clang plus the integrated assembler due to
https://github.com/ClangBuiltLinux/linux/issues/1315:clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]
Ah, sorry, I should have finished off that series back then. I've rebased the series and sent a v4.
https://lore.kernel.org/llvm/[email protected]/
You mentioned to me on IRC
https://lore.kernel.org/linux-next/CAK7LNARg8OpqLR_71PJV3ZoLuDV8+mz9mphg=CzEeEEMY0G3rw@mail.gmail.com/
maybe will be a conflict.
Quoted 7 lines
Ultimately, I want -Wunused-command-line-argument to be an error anyways
(https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be nice to get these cleaned up before this goes in.Cheers,
Nathan
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 51 lines · Nathan Chancellor
Quoted 41 lines · Masahiro Yamada
CONFIG_WERRORturns warnings into errors, which happens only for *.c files because -Werror is added toKBUILD_CFLAGS.Adding it to
KBUILD_CPPFLAGSmakes more sense because preprocessors understand the -Werror option.For example, you can put a #warning directive in any preprocessed code.
warning: #warning "this is a warning message" [-Wcpp]
If -Werror is added, it is promoted to an error.
error: #warning "this is a warning message" [-Werror=cpp]
This commit moves -Werror to
KBUILD_CPPFLAGSso it works in the same way for *.c, *.S, *.lds.S or whatever needs preprocessing.Signed-off-by Masahiro Yamada <[email protected]>Reviewed-by Nick Desaulniers <[email protected]>---
(no changes since v1)
Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Makefile +2
-2@@ -859,7 +859,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong KBUILD_CFLAGS += $(stackp-flags-y) -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y) KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings --Quoted 3 lines
2.34.1
For what it's worth, this is going to break 32-bit ARM builds with clang plus the integrated assembler due to
https://github.com/ClangBuiltLinux/linux/issues/1315:
Quoted 8 lines
clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]
Ultimately, I want -Wunused-command-line-argument to be an error anyways
(https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be nice to get these cleaned up before this goes in.Cheers,
Nathan
OK, I will postpone this patch.
Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada