Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Enable '-Werror' by default for all kernel builds

... but make it a config option so that broken environments can disable
it when required.

We really should always have a clean build, and will disable specific
over-eager warnings as required, if we can't fix them. But while I
fairly religiously enforce that in my own tree, it doesn't get enforced
by various build robots that don't necessarily report warnings.

So this just makes '-Werror' a default compiler flag, but allows people
to disable it for their configuration if they have some particular
issues.

Occasionally, new compiler versions end up enabling new warnings, and it
can take a while before we have them fixed (or the warnings disabled if
that is what it takes), so the config option allows for that situation.

Hopefully this will mean that I get fewer pull requests that have new
warnings that were not noticed by various automation we have in place.

Knock wood.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+17
+3
Makefile
··· 785 785 786 786 KBUILD_CFLAGS += $(stackp-flags-y) 787 787 788 + KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror 789 + KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) 790 + 788 791 ifdef CONFIG_CC_IS_CLANG 789 792 KBUILD_CPPFLAGS += -Qunused-arguments 790 793 # The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
+14
init/Kconfig
··· 137 137 here. If you are a user/distributor, say N here to exclude useless 138 138 drivers to be distributed. 139 139 140 + config WERROR 141 + bool "Compile the kernel with warnings as errors" 142 + default y 143 + help 144 + A kernel build should not cause any compiler warnings, and this 145 + enables the '-Werror' flag to enforce that rule by default. 146 + 147 + However, if you have a new (or very old) compiler with odd and 148 + unusual warnings, or you have some architecture with problems, 149 + you may need to disable this config option in order to 150 + successfully build the kernel. 151 + 152 + If in doubt, say Y. 153 + 140 154 config UAPI_HEADER_TEST 141 155 bool "Compile test UAPI headers" 142 156 depends on HEADERS_INSTALL && CC_CAN_LINK