aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2016-11-10 11:44:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-11-11 11:45:08 -0500
commita76bcf557ef408b368cf26f52a60865bfc27b632 (patch)
treef2d04bc5bbe5d2723dacb470c4701bf90375ca7b
parent27bcd37e0240bbe33f0efe244b5aad52104115b3 (diff)
Kbuild: enable -Wmaybe-uninitialized warning for "make W=1"
Traditionally, we have always had warnings about uninitialized variables enabled, as this is part of -Wall, and generally a good idea [1], but it also always produced false positives, mainly because this is a variation of the halting problem and provably impossible to get right in all cases [2]. Various people have identified cases that are particularly bad for false positives, and in commit e74fc973b6e5 ("Turn off -Wmaybe-uninitialized when building with -Os"), I turned off the warning for any build that was done with CC_OPTIMIZE_FOR_SIZE. This drastically reduced the number of false positive warnings in the default build but unfortunately had the side effect of turning the warning off completely in 'allmodconfig' builds, which in turn led to a lot of warnings (both actual bugs, and remaining false positives) to go in unnoticed. With commit 877417e6ffb9 ("Kbuild: change CC_OPTIMIZE_FOR_SIZE definition") enabled the warning again for allmodconfig builds in v4.7 and in v4.8-rc1, I had finally managed to address all warnings I get in an ARM allmodconfig build and most other maybe-uninitialized warnings for ARM randconfig builds. However, commit 6e8d666e9253 ("Disable "maybe-uninitialized" warning globally") was merged at the same time and disabled it completely for all configurations, because of false-positive warnings on x86 that I had not addressed until then. This caused a lot of actual bugs to get merged into mainline, and I sent several dozen patches for these during the v4.9 development cycle. Most of these are actual bugs, some are for correct code that is safe because it is only called under external constraints that make it impossible to run into the case that gcc sees, and in a few cases gcc is just stupid and finds something that can obviously never happen. I have now done a few thousand randconfig builds on x86 and collected all patches that I needed to address every single warning I got (I can provide the combined patch for the other warnings if anyone is interested), so I hope we can get the warning back and let people catch the actual bugs earlier. This reverts the change to disable the warning completely and for now brings it back at the "make W=1" level, so we can get it merged into mainline without introducing false positives. A follow-up patch enables it on all levels unless some configuration option turns it off because of false-positives. Link: https://rusty.ozlabs.org/?p=232 [1] Link: https://gcc.gnu.org/wiki/Better_Uninitialized_Warnings [2] Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Makefile10
-rw-r--r--arch/arc/Makefile4
-rw-r--r--scripts/Makefile.extrawarn3
-rw-r--r--scripts/Makefile.ubsan4
4 files changed, 16 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index f97f786de58d..06e2b73978e8 100644
--- a/Makefile
+++ b/Makefile
@@ -370,7 +370,7 @@ LDFLAGS_MODULE =
370CFLAGS_KERNEL = 370CFLAGS_KERNEL =
371AFLAGS_KERNEL = 371AFLAGS_KERNEL =
372LDFLAGS_vmlinux = 372LDFLAGS_vmlinux =
373CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im 373CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized
374CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) 374CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
375 375
376 376
@@ -620,7 +620,6 @@ ARCH_CFLAGS :=
620include arch/$(SRCARCH)/Makefile 620include arch/$(SRCARCH)/Makefile
621 621
622KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) 622KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
623KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
624KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) 623KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
625 624
626ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 625ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
@@ -629,15 +628,18 @@ KBUILD_CFLAGS += $(call cc-option,-fdata-sections,)
629endif 628endif
630 629
631ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 630ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
632KBUILD_CFLAGS += -Os 631KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,)
633else 632else
634ifdef CONFIG_PROFILE_ALL_BRANCHES 633ifdef CONFIG_PROFILE_ALL_BRANCHES
635KBUILD_CFLAGS += -O2 634KBUILD_CFLAGS += -O2 $(call cc-disable-warning,maybe-uninitialized,)
636else 635else
637KBUILD_CFLAGS += -O2 636KBUILD_CFLAGS += -O2
638endif 637endif
639endif 638endif
640 639
640KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
641 $(call cc-disable-warning,maybe-uninitialized,))
642
641# Tell gcc to never replace conditional load with a non-conditional one 643# Tell gcc to never replace conditional load with a non-conditional one
642KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 644KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
643 645
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index 864adad52280..25f81a1db9f9 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -68,7 +68,9 @@ cflags-$(CONFIG_ARC_DW2_UNWIND) += -fasynchronous-unwind-tables $(cfi)
68ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE 68ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE
69# Generic build system uses -O2, we want -O3 69# Generic build system uses -O2, we want -O3
70# Note: No need to add to cflags-y as that happens anyways 70# Note: No need to add to cflags-y as that happens anyways
71ARCH_CFLAGS += -O3 71#
72# Disable the false maybe-uninitialized warings gcc spits out at -O3
73ARCH_CFLAGS += -O3 $(call cc-disable-warning,maybe-uninitialized,)
72endif 74endif
73 75
74# small data is default for elf32 tool-chain. If not usable, disable it 76# small data is default for elf32 tool-chain. If not usable, disable it
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 53449a6ff6aa..7fc2c5a3dbbe 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -36,6 +36,7 @@ warning-2 += -Wshadow
36warning-2 += $(call cc-option, -Wlogical-op) 36warning-2 += $(call cc-option, -Wlogical-op)
37warning-2 += $(call cc-option, -Wmissing-field-initializers) 37warning-2 += $(call cc-option, -Wmissing-field-initializers)
38warning-2 += $(call cc-option, -Wsign-compare) 38warning-2 += $(call cc-option, -Wsign-compare)
39warning-2 += $(call cc-option, -Wmaybe-uninitialized)
39 40
40warning-3 := -Wbad-function-cast 41warning-3 := -Wbad-function-cast
41warning-3 += -Wcast-qual 42warning-3 += -Wcast-qual
@@ -59,6 +60,8 @@ endif
59KBUILD_CFLAGS += $(warning) 60KBUILD_CFLAGS += $(warning)
60else 61else
61 62
63KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
64
62ifeq ($(cc-name),clang) 65ifeq ($(cc-name),clang)
63KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides) 66KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
64KBUILD_CFLAGS += $(call cc-disable-warning, unused-value) 67KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan
index dd779c40c8e6..3b1b13818d59 100644
--- a/scripts/Makefile.ubsan
+++ b/scripts/Makefile.ubsan
@@ -17,4 +17,8 @@ endif
17ifdef CONFIG_UBSAN_NULL 17ifdef CONFIG_UBSAN_NULL
18 CFLAGS_UBSAN += $(call cc-option, -fsanitize=null) 18 CFLAGS_UBSAN += $(call cc-option, -fsanitize=null)
19endif 19endif
20
21 # -fsanitize=* options makes GCC less smart than usual and
22 # increase number of 'maybe-uninitialized false-positives
23 CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized)
20endif 24endif