compiler: Add __designated_init annotation
authorKees Cook <keescook@chromium.org>
Wed, 5 Apr 2017 16:49:19 +0000 (09:49 -0700)
committerKees Cook <keescook@chromium.org>
Sun, 28 May 2017 17:23:03 +0000 (10:23 -0700)
This allows structure annotations for requiring designated initialization
in GCC 5.1.0 and later:
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

The structure randomization layout plugin will be using this to help
identify structures that need this form of initialization.

Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/compiler-gcc.h
include/linux/compiler.h

index 0efef9cf014fb1c9467ee293eb22f130912e4f8f..386caf6771ed58ba168700e1568d798d8ec96044 100644 (file)
 #define __no_sanitize_address __attribute__((no_sanitize_address))
 #endif
 
+#if GCC_VERSION >= 50100
+/*
+ * Mark structures as requiring designated initializers.
+ * https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
+ */
+#define __designated_init __attribute__((designated_init))
+#endif
+
 #endif /* gcc version >= 40000 specific checks */
 
 #if !defined(__noclone)
index f8110051188f475c8574aa04787fb04dc9e42e05..80a1dea36cbe060303a00468fd168d2bd7da10b4 100644 (file)
@@ -440,6 +440,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 # define __attribute_const__   /* unimplemented */
 #endif
 
+#ifndef __designated_init
+# define __designated_init
+#endif
+
 #ifndef __latent_entropy
 # define __latent_entropy
 #endif