1From 7233abcc2902766760f9dd26217df159d4e6340a Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Tue, 2 Jul 2019 23:54:25 -0700
4Subject: [PATCH] Use _Alignof when built as C11
5
6---
7 libelf/libelf_align.c | 21 +++++++++++++++++----
8 1 file changed, 17 insertions(+), 4 deletions(-)
9
10diff --git a/libelf/libelf_align.c b/libelf/libelf_align.c
11index c0cdce97..2150fea7 100644
12--- a/libelf/libelf_align.c
13+++ b/libelf/libelf_align.c
14@@ -39,25 +39,38 @@ struct align {
15 unsigned int a64;
16 };
17
18-#ifdef __GNUC__
19+#if __STDC_VERSION__ >= 201112L
20+#define MALIGN(N) { \
21+ .a32 = _Alignof(Elf32_##N), \
22+ .a64 = _Alignof(Elf64_##N) \
23+ }
24+#define MALIGN64(V) { \
25+ .a32 = 0, \
26+ .a64 = _Alignof(Elf64_##V) \
27+ }
28+#define MALIGN_WORD() { \
29+ .a32 = _Alignof(int32_t), \
30+ .a64 = _Alignof(int64_t) \
31+ }
32+#elif defined(__GNUC__)
33 #define MALIGN(N) { \
34 .a32 = __alignof__(Elf32_##N), \
35 .a64 = __alignof__(Elf64_##N) \
36 }
37-#define MALIGN64(V) { \
38+#define MALIGN64(V) { \
39 .a32 = 0, \
40 .a64 = __alignof__(Elf64_##V) \
41 }
42 #define MALIGN_WORD() { \
43 .a32 = __alignof__(int32_t), \
44 .a64 = __alignof__(int64_t) \
45- }
46+ }
47 #elif defined(__lint__)
48 #define MALIGN(N) { .a32 = 0, .a64 = 0 }
49 #define MALIGN64(N) { .a32 = 0, .a64 = 0 }
50 #define MALIGN_WORD(N) { .a32 = 0, .a64 = 0 }
51 #else
52-#error Need the __alignof__ builtin.
53+#error Need C11 _Alignof, or the __alignof__ builtin.
54 #endif
55 #define UNSUPPORTED() { \
56 .a32 = 0, \
57--
582.31.1
59