|
8 | 8 | #include <sys/sysmacros.h> |
9 | 9 | #include <sys/types.h> |
10 | 10 |
|
11 | | -#define _printf_(a, b) __attribute__ ((__format__(printf, a, b))) |
| 11 | +#define _printf_(a, b) __attribute__((__format__(printf, a, b))) |
12 | 12 | #ifdef __clang__ |
13 | 13 | # define _alloc_(...) |
14 | 14 | #else |
15 | | -# define _alloc_(...) __attribute__ ((__alloc_size__(__VA_ARGS__))) |
| 15 | +# define _alloc_(...) __attribute__((__alloc_size__(__VA_ARGS__))) |
16 | 16 | #endif |
17 | | -#define _sentinel_ __attribute__ ((__sentinel__)) |
18 | | -#define _unused_ __attribute__ ((__unused__)) |
19 | | -#define _destructor_ __attribute__ ((__destructor__)) |
20 | | -#define _pure_ __attribute__ ((__pure__)) |
21 | | -#define _const_ __attribute__ ((__const__)) |
22 | | -#define _deprecated_ __attribute__ ((__deprecated__)) |
23 | | -#define _packed_ __attribute__ ((__packed__)) |
24 | | -#define _malloc_ __attribute__ ((__malloc__)) |
25 | | -#define _weak_ __attribute__ ((__weak__)) |
| 17 | +#define _sentinel_ __attribute__((__sentinel__)) |
| 18 | +#define _section_(x) __attribute__((__section__(x))) |
| 19 | +#define _used_ __attribute__((__used__)) |
| 20 | +#define _unused_ __attribute__((__unused__)) |
| 21 | +#define _destructor_ __attribute__((__destructor__)) |
| 22 | +#define _pure_ __attribute__((__pure__)) |
| 23 | +#define _const_ __attribute__((__const__)) |
| 24 | +#define _deprecated_ __attribute__((__deprecated__)) |
| 25 | +#define _packed_ __attribute__((__packed__)) |
| 26 | +#define _malloc_ __attribute__((__malloc__)) |
| 27 | +#define _weak_ __attribute__((__weak__)) |
26 | 28 | #define _likely_(x) (__builtin_expect(!!(x), 1)) |
27 | 29 | #define _unlikely_(x) (__builtin_expect(!!(x), 0)) |
28 | | -#define _public_ __attribute__ ((__visibility__("default"))) |
29 | | -#define _hidden_ __attribute__ ((__visibility__("hidden"))) |
| 30 | +#define _public_ __attribute__((__visibility__("default"))) |
| 31 | +#define _hidden_ __attribute__((__visibility__("hidden"))) |
30 | 32 | #define _weakref_(x) __attribute__((__weakref__(#x))) |
| 33 | +#define _align_(x) __attribute__((__aligned__(x))) |
31 | 34 | #define _alignas_(x) __attribute__((__aligned__(__alignof(x)))) |
| 35 | +#define _alignptr_ __attribute__((__aligned__(sizeof(void*)))) |
32 | 36 | #define _cleanup_(x) __attribute__((__cleanup__(x))) |
33 | 37 | #if __GNUC__ >= 7 |
34 | 38 | #define _fallthrough_ __attribute__((__fallthrough__)) |
|
56 | 60 | # endif |
57 | 61 | #endif |
58 | 62 |
|
| 63 | +#if !defined(HAS_FEATURE_ADDRESS_SANITIZER) |
| 64 | +# ifdef __SANITIZE_ADDRESS__ |
| 65 | +# define HAS_FEATURE_ADDRESS_SANITIZER 1 |
| 66 | +# elif defined(__has_feature) |
| 67 | +# if __has_feature(address_sanitizer) |
| 68 | +# define HAS_FEATURE_ADDRESS_SANITIZER 1 |
| 69 | +# endif |
| 70 | +# endif |
| 71 | +# if !defined(HAS_FEATURE_ADDRESS_SANITIZER) |
| 72 | +# define HAS_FEATURE_ADDRESS_SANITIZER 0 |
| 73 | +# endif |
| 74 | +#endif |
| 75 | + |
| 76 | +/* Note: on GCC "no_sanitize_address" is a function attribute only, on llvm it may also be applied to global |
| 77 | + * variables. We define a specific macro which knows this. Note that on GCC we don't need this decorator so much, since |
| 78 | + * our primary usecase for this attribute is registration structures placed in named ELF sections which shall not be |
| 79 | + * padded, but GCC doesn't pad those anyway if AddressSanitizer is enabled. */ |
| 80 | +#if HAS_FEATURE_ADDRESS_SANITIZER && defined(__clang__) |
| 81 | +#define _variable_no_sanitize_address_ __attribute__((__no_sanitize_address__)) |
| 82 | +#else |
| 83 | +#define _variable_no_sanitize_address_ |
| 84 | +#endif |
| 85 | + |
59 | 86 | /* Temporarily disable some warnings */ |
60 | 87 | #define DISABLE_WARNING_FORMAT_NONLITERAL \ |
61 | 88 | _Pragma("GCC diagnostic push"); \ |
|
0 commit comments