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
25#ifndef XFA_H
26#define XFA_H
27
28#include <inttypes.h>
29#include "compiler_hints.h"
30
31/*
32 * Unfortunately, current gcc trips over accessing XFA's because of their
33 * zero-size start/end array that are used of symbol markers, with an "array
34 * index out of bounds" warning. So until a solution for that is found, we
35 * need to disable array bounds checks for files using XFAs.
36 */
37#ifndef DOXYGEN
38_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
39#endif
40
46#define _XFA(name, prio) \
47 NO_SANITIZE_ARRAY \
48 __attribute__((used, section(".xfa." #name "." #prio)))
49
55#define _XFA_CONST(name, prio) \
56 NO_SANITIZE_ARRAY \
57 __attribute__((used, section(".roxfa." #name "." #prio)))
58
73#define XFA_INIT_CONST(type, name) \
74 _Pragma("GCC diagnostic push") \
75 _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
76 _XFA_CONST(name, 0_) type name [0] = {}; \
77 _XFA_CONST(name, 9_) type name ## _end [0] = {}; \
78 _Pragma("GCC diagnostic pop") \
79 extern const unsigned __xfa_dummy
80
95#define XFA_INIT(type, name) \
96 _Pragma("GCC diagnostic push") \
97 _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
98 _XFA(name, 0_) type name [0] = {}; \
99 _XFA(name, 9_) type name ## _end [0] = {}; \
100 _Pragma("GCC diagnostic pop") \
101 extern const unsigned __xfa_dummy
102
114#define XFA_USE_CONST(type, name) \
115 XFA_USE(type, name)
116
128#define XFA_USE(type, name) \
129 extern type name []; \
130 extern type name ## _end []
131
144#define XFA(xfa_name, prio) _XFA(xfa_name, 5_ ## prio)
145
158#define XFA_CONST(xfa_name, prio) _XFA_CONST(xfa_name, 5_ ## prio)
159
176#define XFA_ADD_PTR(xfa_name, prio, name, entry) \
177 _XFA_CONST(xfa_name, 5_ ## prio) \
178 __typeof__(entry) xfa_name ## _ ## prio ## _ ## name = entry
179
183#define XFA_LEN(type, \
184 name) (((uintptr_t)name ## _end - (uintptr_t)name) / \
185 sizeof(type))
186
187#ifdef __cplusplus
188extern "C" {
189#endif
190/* making externc happy */
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* XFA_H */
Common macros and compiler attributes/pragmas configuration.
Adds include for missing inttype definitions.