]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kbuild: compute false-positive -Wmaybe-uninitialized cases in Kconfig
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 21 Feb 2019 04:13:38 +0000 (13:13 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 May 2020 06:18:45 +0000 (08:18 +0200)
commit b303c6df80c9f8f13785aa83a0471fca7e38b24d upstream.

Since -Wmaybe-uninitialized was introduced by GCC 4.7, we have patched
various false positives:

 - commit e74fc973b6e5 ("Turn off -Wmaybe-uninitialized when building
   with -Os") turned off this option for -Os.

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

 - commit a76bcf557ef4 ("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/350
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Makefile
init/Kconfig
kernel/trace/Kconfig

index 68fa15edd662c81de3ac680823d2ed4703cadd20..a21a781b4b8d11048e21e51a8b7008d617157c11 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -657,17 +657,14 @@ KBUILD_CFLAGS     += $(call cc-disable-warning, int-in-bool-context)
 KBUILD_CFLAGS  += $(call cc-disable-warning, address-of-packed-member)
 
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-KBUILD_CFLAGS  += -Os $(call cc-disable-warning,maybe-uninitialized,)
-else
-ifdef CONFIG_PROFILE_ALL_BRANCHES
-KBUILD_CFLAGS  += -O2 $(call cc-disable-warning,maybe-uninitialized,)
+KBUILD_CFLAGS   += -Os
 else
 KBUILD_CFLAGS   += -O2
 endif
-endif
 
-KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
-                       $(call cc-disable-warning,maybe-uninitialized,))
+ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
+KBUILD_CFLAGS   += -Wno-maybe-uninitialized
+endif
 
 # Tell gcc to never replace conditional load with a non-conditional one
 KBUILD_CFLAGS  += $(call cc-option,--param=allow-store-data-races=0)
index 47035b5a46f6453bca1e447def3143a3a108949c..ed0106b8d4f341a78a729e08781913cbcf26c8b3 100644 (file)
@@ -26,6 +26,22 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
        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
        bool
        depends on !UML
@@ -1083,6 +1099,7 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
 
 config CC_OPTIMIZE_FOR_SIZE
        bool "Optimize for size"
+       imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED  # avoid false positives
        help
          Enabling this option will pass "-Os" instead of "-O2" to
          your compiler resulting in a smaller kernel.
index 5e3de28c7677396aaa4360dcf2f51fb9b365b626..0d356d4f307b0d5d41e320860886d1c9a6e2e627 100644 (file)
@@ -370,6 +370,7 @@ config PROFILE_ANNOTATED_BRANCHES
 config PROFILE_ALL_BRANCHES
        bool "Profile all if conditionals" if !FORTIFY_SOURCE
        select TRACE_BRANCH_PROFILING
+       imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED  # avoid false positives
        help
          This tracer profiles all branch conditions. Every if ()
          taken in the kernel is recorded whether it hit or miss.