Skip to content

Commit e88ca24

Browse files
arndbmasahir0y
authored andcommitted
kbuild: consolidate warning flags in scripts/Makefile.extrawarn
Warning options are enabled and disabled in inconsistent ways and inconsistent locations. Start rearranging those by moving all options into Makefile.extrawarn. This should not change any behavior, but makes sure we can group them in a way that ensures that each warning that got temporarily disabled is turned back on at an appropriate W=1 level later on. Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 077af78 commit e88ca24

File tree

2 files changed

+90
-88
lines changed

2 files changed

+90
-88
lines changed

Makefile

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,6 @@ KBUILD_CFLAGS += -funsigned-char
563563
KBUILD_CFLAGS += -fno-common
564564
KBUILD_CFLAGS += -fno-PIE
565565
KBUILD_CFLAGS += -fno-strict-aliasing
566-
KBUILD_CFLAGS += -Wall
567-
KBUILD_CFLAGS += -Wundef
568-
KBUILD_CFLAGS += -Werror=implicit-function-declaration
569-
KBUILD_CFLAGS += -Werror=implicit-int
570-
KBUILD_CFLAGS += -Werror=return-type
571-
KBUILD_CFLAGS += -Werror=strict-prototypes
572-
KBUILD_CFLAGS += -Wno-format-security
573-
KBUILD_CFLAGS += -Wno-trigraphs
574566

575567
KBUILD_CPPFLAGS := -D__KERNEL__
576568
KBUILD_RUSTFLAGS := $(rust_common_flags) \
@@ -823,10 +815,6 @@ endif # may-sync-config
823815
endif # need-config
824816

825817
KBUILD_CFLAGS += -fno-delete-null-pointer-checks
826-
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
827-
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
828-
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
829-
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
830818

831819
ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
832820
KBUILD_CFLAGS += -O2
@@ -857,40 +845,15 @@ ifdef CONFIG_READABLE_ASM
857845
KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
858846
endif
859847

860-
ifneq ($(CONFIG_FRAME_WARN),0)
861-
KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
862-
endif
863-
864848
stackp-flags-y := -fno-stack-protector
865849
stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
866850
stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
867851

868852
KBUILD_CFLAGS += $(stackp-flags-y)
869853

870-
KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
871-
KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
872-
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
873-
874854
KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
875855
KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
876856

877-
ifdef CONFIG_CC_IS_CLANG
878-
# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
879-
KBUILD_CFLAGS += -Wno-gnu
880-
else
881-
882-
# gcc inanely warns about local variables called 'main'
883-
KBUILD_CFLAGS += -Wno-main
884-
endif
885-
886-
# These warnings generated too much noise in a regular build.
887-
# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
888-
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
889-
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
890-
891-
# These result in bogus false positives
892-
KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
893-
894857
ifdef CONFIG_FRAME_POINTER
895858
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
896859
KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
@@ -1025,51 +988,12 @@ endif
1025988
# arch Makefile may override CC so keep this after arch Makefile is included
1026989
NOSTDINC_FLAGS += -nostdinc
1027990

1028-
# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
1029-
KBUILD_CFLAGS += -Wvla
1030-
1031-
# disable pointer signed / unsigned warnings in gcc 4.0
1032-
KBUILD_CFLAGS += -Wno-pointer-sign
1033-
1034-
# In order to make sure new function cast mismatches are not introduced
1035-
# in the kernel (to avoid tripping CFI checking), the kernel should be
1036-
# globally built with -Wcast-function-type.
1037-
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
1038-
1039991
# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
1040992
# the kernel uses only C99 flexible arrays for dynamically sized trailing
1041993
# arrays. Enforce this for everything that may examine structure sizes and
1042994
# perform bounds checking.
1043995
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
1044996

1045-
# disable stringop warnings in gcc 8+
1046-
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
1047-
1048-
# We'll want to enable this eventually, but it's not going away for 5.7 at least
1049-
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
1050-
1051-
# Another good warning that we'll want to enable eventually
1052-
KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
1053-
1054-
# Enabled with W=2, disabled by default as noisy
1055-
ifdef CONFIG_CC_IS_GCC
1056-
KBUILD_CFLAGS += -Wno-maybe-uninitialized
1057-
endif
1058-
1059-
# The allocators already balk at large sizes, so silence the compiler
1060-
# warnings for bounds checks involving those possible values. While
1061-
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
1062-
# of gcc (<9.1) weirdly don't handle the option correctly when _other_
1063-
# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX
1064-
# doesn't work (as it is documented to), silently resolving to "0" prior to
1065-
# version 9.1 (and producing an error more recently). Numeric values larger
1066-
# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently
1067-
# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
1068-
# choice, we must perform a versioned check to disable this warning.
1069-
# https://lore.kernel.org/lkml/[email protected]
1070-
KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
1071-
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
1072-
1073997
# disable invalid "can't wrap" optimizations for signed / pointers
1074998
KBUILD_CFLAGS += -fno-strict-overflow
1075999

@@ -1081,18 +1005,6 @@ ifdef CONFIG_CC_IS_GCC
10811005
KBUILD_CFLAGS += -fconserve-stack
10821006
endif
10831007

1084-
# Prohibit date/time macros, which would make the build non-deterministic
1085-
KBUILD_CFLAGS += -Werror=date-time
1086-
1087-
# enforce correct pointer usage
1088-
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
1089-
1090-
# Require designated initializers for all marked structures
1091-
KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
1092-
1093-
# Warn if there is an enum types mismatch
1094-
KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
1095-
10961008
# change __FILE__ to the relative path from the srctree
10971009
KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
10981010

scripts/Makefile.extrawarn

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,96 @@
66
# They are independent, and can be combined like W=12 or W=123e.
77
# ==========================================================================
88

9+
# Default set of warnings, always enabled
10+
KBUILD_CFLAGS += -Wall
11+
KBUILD_CFLAGS += -Wundef
12+
KBUILD_CFLAGS += -Werror=implicit-function-declaration
13+
KBUILD_CFLAGS += -Werror=implicit-int
14+
KBUILD_CFLAGS += -Werror=return-type
15+
KBUILD_CFLAGS += -Werror=strict-prototypes
16+
KBUILD_CFLAGS += -Wno-format-security
17+
KBUILD_CFLAGS += -Wno-trigraphs
18+
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
19+
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
20+
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
21+
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
22+
23+
ifneq ($(CONFIG_FRAME_WARN),0)
24+
KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
25+
endif
26+
27+
KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
28+
KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
29+
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
30+
31+
ifdef CONFIG_CC_IS_CLANG
32+
# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
33+
KBUILD_CFLAGS += -Wno-gnu
34+
else
35+
36+
# gcc inanely warns about local variables called 'main'
37+
KBUILD_CFLAGS += -Wno-main
38+
endif
39+
40+
# These warnings generated too much noise in a regular build.
41+
# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
42+
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
43+
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
44+
45+
# These result in bogus false positives
46+
KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
47+
48+
# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
49+
KBUILD_CFLAGS += -Wvla
50+
51+
# disable pointer signed / unsigned warnings in gcc 4.0
52+
KBUILD_CFLAGS += -Wno-pointer-sign
53+
54+
# In order to make sure new function cast mismatches are not introduced
55+
# in the kernel (to avoid tripping CFI checking), the kernel should be
56+
# globally built with -Wcast-function-type.
57+
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
58+
59+
# disable stringop warnings in gcc 8+
60+
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
61+
62+
# We'll want to enable this eventually, but it's not going away for 5.7 at least
63+
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
64+
65+
# Another good warning that we'll want to enable eventually
66+
KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
67+
68+
# Enabled with W=2, disabled by default as noisy
69+
ifdef CONFIG_CC_IS_GCC
70+
KBUILD_CFLAGS += -Wno-maybe-uninitialized
71+
endif
72+
73+
# The allocators already balk at large sizes, so silence the compiler
74+
# warnings for bounds checks involving those possible values. While
75+
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
76+
# of gcc (<9.1) weirdly don't handle the option correctly when _other_
77+
# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX
78+
# doesn't work (as it is documented to), silently resolving to "0" prior to
79+
# version 9.1 (and producing an error more recently). Numeric values larger
80+
# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently
81+
# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
82+
# choice, we must perform a versioned check to disable this warning.
83+
# https://lore.kernel.org/lkml/[email protected]
84+
KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
85+
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
86+
87+
# Prohibit date/time macros, which would make the build non-deterministic
88+
KBUILD_CFLAGS += -Werror=date-time
89+
90+
# enforce correct pointer usage
91+
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
92+
93+
# Require designated initializers for all marked structures
94+
KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
95+
96+
# Warn if there is an enum types mismatch
97+
KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
98+
999
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
10100

11101
# backward compatibility

0 commit comments

Comments
 (0)