Skip to content

Commit b303c6d

Browse files
committed
kbuild: compute false-positive -Wmaybe-uninitialized cases in Kconfig
Since -Wmaybe-uninitialized was introduced by GCC 4.7, we have patched various false positives: - commit e74fc97 ("Turn off -Wmaybe-uninitialized when building with -Os") turned off this option for -Os. - commit 815eb71 ("Kbuild: disable 'maybe-uninitialized' warning for CONFIG_PROFILE_ALL_BRANCHES") turned off this option for CONFIG_PROFILE_ALL_BRANCHES - commit a76bcf5 ("Kbuild: enable -Wmaybe-uninitialized warning for "make W=1"") turned off this option for GCC < 4.9 Arnd provided more explanation in https://lkml.org/lkml/2017/3/14/903 I think this looks better by shifting the logic from Makefile to Kconfig. Link: ClangBuiltLinux#350 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent bd55f96 commit b303c6d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,13 @@ KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
660660

661661
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
662662
KBUILD_CFLAGS += $(call cc-option,-Oz,-Os)
663-
KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
664-
else
665-
ifdef CONFIG_PROFILE_ALL_BRANCHES
666-
KBUILD_CFLAGS += -O2 $(call cc-disable-warning,maybe-uninitialized,)
667663
else
668664
KBUILD_CFLAGS += -O2
669665
endif
670-
endif
671666

672-
KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
673-
$(call cc-disable-warning,maybe-uninitialized,))
667+
ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
668+
KBUILD_CFLAGS += -Wno-maybe-uninitialized
669+
endif
674670

675671
# Tell gcc to never replace conditional load with a non-conditional one
676672
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)

init/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ config CLANG_VERSION
2626
config CC_HAS_ASM_GOTO
2727
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
2828

29+
config CC_HAS_WARN_MAYBE_UNINITIALIZED
30+
def_bool $(cc-option,-Wmaybe-uninitialized)
31+
help
32+
GCC >= 4.7 supports this option.
33+
34+
config CC_DISABLE_WARN_MAYBE_UNINITIALIZED
35+
bool
36+
depends on CC_HAS_WARN_MAYBE_UNINITIALIZED
37+
default CC_IS_GCC && GCC_VERSION < 40900 # unreliable for GCC < 4.9
38+
help
39+
GCC's -Wmaybe-uninitialized is not reliable by definition.
40+
Lots of false positive warnings are produced in some cases.
41+
42+
If this option is enabled, -Wno-maybe-uninitialzed is passed
43+
to the compiler to suppress maybe-uninitialized warnings.
44+
2945
config CONSTRUCTORS
3046
bool
3147
depends on !UML
@@ -1102,6 +1118,7 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
11021118

11031119
config CC_OPTIMIZE_FOR_SIZE
11041120
bool "Optimize for size"
1121+
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
11051122
help
11061123
Enabling this option will pass "-Os" instead of "-O2" to
11071124
your compiler resulting in a smaller kernel.

kernel/trace/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ config PROFILE_ANNOTATED_BRANCHES
370370
config PROFILE_ALL_BRANCHES
371371
bool "Profile all if conditionals" if !FORTIFY_SOURCE
372372
select TRACE_BRANCH_PROFILING
373+
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
373374
help
374375
This tracer profiles all branch conditions. Every if ()
375376
taken in the kernel is recorded whether it hit or miss.

0 commit comments

Comments
 (0)