xfa.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
27 #include <inttypes.h>
28 #include "compiler_hints.h"
29 
30 /*
31  * Unfortunately, current gcc trips over accessing XFA's because of their
32  * zero-size start/end array that are used of symbol markers, with an "array
33  * index out of bounds" warning. So until a solution for that is found, we
34  * need to disable array bounds checks for files using XFAs.
35  */
36 #ifndef DOXYGEN
37 _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
38 #endif
39 
45 #define _XFA(type, name, prio) \
46  NO_SANITIZE_ARRAY \
47  __attribute__((used, section(".xfa." #name "." #prio))) _Alignas(type) type
48 
54 #define _XFA_CONST(type, name, prio) \
55  NO_SANITIZE_ARRAY \
56  __attribute__((used, section(".roxfa." #name "." #prio))) _Alignas(type) type
57 
72 #define XFA_INIT_CONST(type, name) \
73  _Pragma("GCC diagnostic push") \
74  _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
75  _XFA_CONST(type, name, 0_) name [0] = {}; \
76  _XFA_CONST(type, name, 9_) name ## _end [0] = {}; \
77  _Pragma("GCC diagnostic pop") \
78  extern const unsigned __xfa_dummy
79 
94 #define XFA_INIT(type, name) \
95  _Pragma("GCC diagnostic push") \
96  _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
97  _XFA(type, name, 0_) name [0] = {}; \
98  _XFA(type, name, 9_) name ## _end [0] = {}; \
99  _Pragma("GCC diagnostic pop") \
100  extern const unsigned __xfa_dummy
101 
113 #define XFA_USE_CONST(type, name) \
114  XFA_USE(type, name)
115 
127 #define XFA_USE(type, name) \
128  extern type name []; \
129  extern type name ## _end []
130 
144 #define XFA(type, xfa_name, prio) _XFA(type, xfa_name, 5_ ## prio)
145 
159 #define XFA_CONST(type, xfa_name, prio) _XFA_CONST(type, xfa_name, 5_ ## prio)
160 
177 #define XFA_ADD_PTR(xfa_name, prio, name, entry) \
178  _XFA_CONST(__typeof__(entry), xfa_name, 5_ ## prio) \
179  xfa_name ## _ ## prio ## _ ## name = entry
180 
184 #define XFA_LEN(type, \
185  name) (((uintptr_t)name ## _end - (uintptr_t)name) / \
186  sizeof(type))
187 
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 /* making externc happy */
192 #ifdef __cplusplus
193 }
194 #endif
195 
Common macros and compiler attributes/pragmas configuration.
Adds include for missing inttype definitions.