Skip to content

Commit a76bcf5

Browse files
arndbtorvalds
authored andcommittedNov 11, 2016
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 e74fc97 ("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 877417e ("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 6e8d666 ("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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 27bcd37 commit a76bcf5

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed
 

‎Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ LDFLAGS_MODULE =
370370
CFLAGS_KERNEL =
371371
AFLAGS_KERNEL =
372372
LDFLAGS_vmlinux =
373-
CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im
373+
CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized
374374
CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
375375

376376

@@ -620,7 +620,6 @@ ARCH_CFLAGS :=
620620
include arch/$(SRCARCH)/Makefile
621621

622622
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
623-
KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
624623
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
625624

626625
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
@@ -629,15 +628,18 @@ KBUILD_CFLAGS += $(call cc-option,-fdata-sections,)
629628
endif
630629

631630
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
632-
KBUILD_CFLAGS += -Os
631+
KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,)
633632
else
634633
ifdef CONFIG_PROFILE_ALL_BRANCHES
635-
KBUILD_CFLAGS += -O2
634+
KBUILD_CFLAGS += -O2 $(call cc-disable-warning,maybe-uninitialized,)
636635
else
637636
KBUILD_CFLAGS += -O2
638637
endif
639638
endif
640639

640+
KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
641+
$(call cc-disable-warning,maybe-uninitialized,))
642+
641643
# Tell gcc to never replace conditional load with a non-conditional one
642644
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
643645

‎arch/arc/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ cflags-$(CONFIG_ARC_DW2_UNWIND) += -fasynchronous-unwind-tables $(cfi)
6868
ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE
6969
# Generic build system uses -O2, we want -O3
7070
# Note: No need to add to cflags-y as that happens anyways
71-
ARCH_CFLAGS += -O3
71+
#
72+
# Disable the false maybe-uninitialized warings gcc spits out at -O3
73+
ARCH_CFLAGS += -O3 $(call cc-disable-warning,maybe-uninitialized,)
7274
endif
7375

7476
# small data is default for elf32 tool-chain. If not usable, disable it

‎scripts/Makefile.extrawarn

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ warning-2 += -Wshadow
3636
warning-2 += $(call cc-option, -Wlogical-op)
3737
warning-2 += $(call cc-option, -Wmissing-field-initializers)
3838
warning-2 += $(call cc-option, -Wsign-compare)
39+
warning-2 += $(call cc-option, -Wmaybe-uninitialized)
3940

4041
warning-3 := -Wbad-function-cast
4142
warning-3 += -Wcast-qual
@@ -59,6 +60,8 @@ endif
5960
KBUILD_CFLAGS += $(warning)
6061
else
6162

63+
KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
64+
6265
ifeq ($(cc-name),clang)
6366
KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
6467
KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)

‎scripts/Makefile.ubsan

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ endif
1717
ifdef CONFIG_UBSAN_NULL
1818
CFLAGS_UBSAN += $(call cc-option, -fsanitize=null)
1919
endif
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)
2024
endif

0 commit comments

Comments
 (0)
Please sign in to comment.