Skip to contentSkip to conversation

Kbuild: support designated_init attribute

PATCH In review Kees Cook 2 participants 2 messages Feb 1, 2017 – Mar 14, 2017 Kbuild

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 Kbuild: support designated_init attribute

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.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 96b27a888285..d4e0550e7abd 100644
@@ -793,6 +793,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)
 
Signature · 6 lines
2.7.4


-- 
Kees Cook
Pixel Security
#1 lore raw

Hi Kees,

2017-02-02 8:04 GMT+09:00 Kees Cook <[email protected]>:

Quoted 16 lines

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.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +0 -0
index 96b27a888285..d4e0550e7abd 100644

Makefile KBUILD_CFLAGS += $(call cc-option,-Werror=date-time) · line 801

Quoted 9 lines
Makefile +3 -0
@@ -793,6 +793,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)
 

The code looks OK to me.

As far as I understood, this patch changes
designated-init warnings into errors. Correct?

If so, I think the commit subject "Kbuild: support designated_init attribute" does not directly describe what this patch does.

Signature · 2 lines
Best Regards
Masahiro Yamada