Kbuild: make designated_init attribute fatal
authorKees Cook <keescook@chromium.org>
Tue, 21 Mar 2017 00:14:11 +0000 (17:14 -0700)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Tue, 21 Mar 2017 17:50:25 +0000 (02:50 +0900)
If a structure is marked with __attribute__((designated_init)) from
GCC or Sparse, it needs to have all static initializers using designated
initialization. Fail the build for any missing cases. This attribute will
be used by the randstruct plugin to make sure randomized structures are
being correctly initialized.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Makefile

index 515aeea7e70293d6e0050ded4d30e7873e9c35d3..ae49fef98ca3365200b40cf7f190d552df0c148c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -795,6 +795,9 @@ KBUILD_CFLAGS   += $(call cc-option,-Werror=date-time)
 # enforce correct pointer usage
 KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
 
+# Require designated initializers for all marked structures
+KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
+
 # use the deterministic mode of AR if available
 KBUILD_ARFLAGS := $(call ar-option,D)