Skip to content

Commit 0aa5e49

Browse files
committed
compiler: Add __designated_init annotation
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 <[email protected]>
1 parent 1132e1e commit 0aa5e49

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/linux/compiler-gcc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@
294294
#define __no_sanitize_address __attribute__((no_sanitize_address))
295295
#endif
296296

297+
#if GCC_VERSION >= 50100
298+
/*
299+
* Mark structures as requiring designated initializers.
300+
* https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
301+
*/
302+
#define __designated_init __attribute__((designated_init))
303+
#endif
304+
297305
#endif /* gcc version >= 40000 specific checks */
298306

299307
#if !defined(__noclone)

include/linux/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
440440
# define __attribute_const__ /* unimplemented */
441441
#endif
442442

443+
#ifndef __designated_init
444+
# define __designated_init
445+
#endif
446+
443447
#ifndef __latent_entropy
444448
# define __latent_entropy
445449
#endif

0 commit comments

Comments
 (0)