Commit b303c6df authored by Masahiro Yamada's avatar Masahiro Yamada

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 e74fc973 ("Turn off -Wmaybe-uninitialized when building
   with -Os") turned off this option for -Os.

 - commit 815eb71e ("Kbuild: disable 'maybe-uninitialized' warning
   for CONFIG_PROFILE_ALL_BRANCHES") turned off this option for
   CONFIG_PROFILE_ALL_BRANCHES

 - commit a76bcf55 ("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: https://github.com/ClangBuiltLinux/linux/issues/350Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent bd55f96f
...@@ -660,17 +660,13 @@ KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context) ...@@ -660,17 +660,13 @@ KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += $(call cc-option,-Oz,-Os) KBUILD_CFLAGS += $(call cc-option,-Oz,-Os)
KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
else
ifdef CONFIG_PROFILE_ALL_BRANCHES
KBUILD_CFLAGS += -O2 $(call cc-disable-warning,maybe-uninitialized,)
else else
KBUILD_CFLAGS += -O2 KBUILD_CFLAGS += -O2
endif endif
endif
KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \ ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
$(call cc-disable-warning,maybe-uninitialized,)) KBUILD_CFLAGS += -Wno-maybe-uninitialized
endif
# Tell gcc to never replace conditional load with a non-conditional one # Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
......
...@@ -26,6 +26,22 @@ config CLANG_VERSION ...@@ -26,6 +26,22 @@ config CLANG_VERSION
config CC_HAS_ASM_GOTO config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC)) def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
config CC_HAS_WARN_MAYBE_UNINITIALIZED
def_bool $(cc-option,-Wmaybe-uninitialized)
help
GCC >= 4.7 supports this option.
config CC_DISABLE_WARN_MAYBE_UNINITIALIZED
bool
depends on CC_HAS_WARN_MAYBE_UNINITIALIZED
default CC_IS_GCC && GCC_VERSION < 40900 # unreliable for GCC < 4.9
help
GCC's -Wmaybe-uninitialized is not reliable by definition.
Lots of false positive warnings are produced in some cases.
If this option is enabled, -Wno-maybe-uninitialzed is passed
to the compiler to suppress maybe-uninitialized warnings.
config CONSTRUCTORS config CONSTRUCTORS
bool bool
depends on !UML depends on !UML
...@@ -1102,6 +1118,7 @@ config CC_OPTIMIZE_FOR_PERFORMANCE ...@@ -1102,6 +1118,7 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
config CC_OPTIMIZE_FOR_SIZE config CC_OPTIMIZE_FOR_SIZE
bool "Optimize for size" bool "Optimize for size"
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
help help
Enabling this option will pass "-Os" instead of "-O2" to Enabling this option will pass "-Os" instead of "-O2" to
your compiler resulting in a smaller kernel. your compiler resulting in a smaller kernel.
......
...@@ -370,6 +370,7 @@ config PROFILE_ANNOTATED_BRANCHES ...@@ -370,6 +370,7 @@ config PROFILE_ANNOTATED_BRANCHES
config PROFILE_ALL_BRANCHES config PROFILE_ALL_BRANCHES
bool "Profile all if conditionals" if !FORTIFY_SOURCE bool "Profile all if conditionals" if !FORTIFY_SOURCE
select TRACE_BRANCH_PROFILING select TRACE_BRANCH_PROFILING
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
help help
This tracer profiles all branch conditions. Every if () This tracer profiles all branch conditions. Every if ()
taken in the kernel is recorded whether it hit or miss. taken in the kernel is recorded whether it hit or miss.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment