summaryrefslogtreecommitdiff
path: root/pkg/elftoolchain/patch/0002-Use-_Alignof-when-built-as-C11.patch
blob: 3ba220b66c7c5291e2bfef53cf790067918d67fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From 7233abcc2902766760f9dd26217df159d4e6340a Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Tue, 2 Jul 2019 23:54:25 -0700
Subject: [PATCH] Use _Alignof when built as C11

---
 libelf/libelf_align.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/libelf/libelf_align.c b/libelf/libelf_align.c
index c0cdce97..2150fea7 100644
--- a/libelf/libelf_align.c
+++ b/libelf/libelf_align.c
@@ -39,25 +39,38 @@ struct align {
 	unsigned int a64;
 };
 
-#ifdef	__GNUC__
+#if	__STDC_VERSION__ >= 201112L
+#define	MALIGN(N)	{					\
+		.a32 = _Alignof(Elf32_##N),			\
+		.a64 = _Alignof(Elf64_##N)			\
+	}
+#define	MALIGN64(V)	{					\
+		.a32 = 0,					\
+		.a64 = _Alignof(Elf64_##V)			\
+	}
+#define	MALIGN_WORD()	{					\
+		.a32 = _Alignof(int32_t),			\
+		.a64 = _Alignof(int64_t)			\
+	}
+#elif	defined(__GNUC__)
 #define	MALIGN(N)	{					\
 		.a32 = __alignof__(Elf32_##N),			\
 		.a64 = __alignof__(Elf64_##N)			\
 	}
-#define	MALIGN64(V)	  {					\
+#define	MALIGN64(V)	{					\
 		.a32 = 0,					\
 		.a64 = __alignof__(Elf64_##V)			\
 	}
 #define	MALIGN_WORD()	{					\
 		.a32 = __alignof__(int32_t),			\
 		.a64 = __alignof__(int64_t)			\
-	    }
+	}
 #elif defined(__lint__)
 #define MALIGN(N)	{ .a32 = 0, .a64 = 0 }
 #define MALIGN64(N)	{ .a32 = 0, .a64 = 0 }
 #define MALIGN_WORD(N)	{ .a32 = 0, .a64 = 0 }
 #else
-#error	Need the __alignof__ builtin.
+#error	Need C11 _Alignof, or the __alignof__ builtin.
 #endif
 #define	UNSUPPORTED()	{					\
 		.a32 = 0,					\
-- 
2.31.1