xfa.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
24 #include <inttypes.h>
25 #include "compiler_hints.h"
26 
27 /*
28  * Unfortunately, current gcc trips over accessing XFA's because of their
29  * zero-size start/end array that are used of symbol markers, with an "array
30  * index out of bounds" warning. So until a solution for that is found, we
31  * need to disable array bounds checks for files using XFAs.
32  */
33 #ifndef DOXYGEN
34 _Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
35 #endif
36 
42 #define _XFA(type, name, prio) \
43  NO_SANITIZE_ARRAY \
44  __attribute__((used, section(".xfa." #name "." #prio))) _Alignas(type) type
45 
51 #define _XFA_CONST(type, name, prio) \
52  NO_SANITIZE_ARRAY \
53  __attribute__((used, section(".roxfa." #name "." #prio))) _Alignas(type) type
54 
69 #define XFA_INIT_CONST(type, name) \
70  _Pragma("GCC diagnostic push") \
71  _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
72  _XFA_CONST(type, name, 0_) name [0] = {}; \
73  _XFA_CONST(type, name, 9_) name ## _end [0] = {}; \
74  _Pragma("GCC diagnostic pop") \
75  extern const unsigned __xfa_dummy
76 
91 #define XFA_INIT(type, name) \
92  _Pragma("GCC diagnostic push") \
93  _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
94  _XFA(type, name, 0_) name [0] = {}; \
95  _XFA(type, name, 9_) name ## _end [0] = {}; \
96  _Pragma("GCC diagnostic pop") \
97  extern const unsigned __xfa_dummy
98 
110 #define XFA_USE_CONST(type, name) \
111  XFA_USE(type, name)
112 
124 #define XFA_USE(type, name) \
125  extern type name []; \
126  extern type name ## _end []
127 
141 #define XFA(type, xfa_name, prio) _XFA(type, xfa_name, 5_ ## prio)
142 
156 #define XFA_CONST(type, xfa_name, prio) _XFA_CONST(type, xfa_name, 5_ ## prio)
157 
174 #define XFA_ADD_PTR(xfa_name, prio, name, entry) \
175  _XFA_CONST(__typeof__(entry), xfa_name, 5_ ## prio) \
176  xfa_name ## _ ## prio ## _ ## name = entry
177 
181 #define XFA_LEN(type, \
182  name) (((uintptr_t)name ## _end - (uintptr_t)name) / \
183  sizeof(type))
184 
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188 /* making externc happy */
189 #ifdef __cplusplus
190 }
191 #endif
192 
Common macros and compiler attributes/pragmas configuration.
Adds include for missing inttype definitions.