]>
Commit | Line | Data |
---|---|---|
581c785b | 1 | /* Copyright (C) 1992-2022 Free Software Foundation, Inc. |
8a9a5931 | 2 | Copyright The GNU Toolchain Authors. |
54d79e99 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
54d79e99 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 9 | |
54d79e99 UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
18 | |
19 | #ifndef _SYS_CDEFS_H | |
28f540f4 | 20 | #define _SYS_CDEFS_H 1 |
5107cf1d | 21 | |
a6ff34d7 UD |
22 | /* We are almost always included from features.h. */ |
23 | #ifndef _FEATURES_H | |
7688db91 UD |
24 | # include <features.h> |
25 | #endif | |
26 | ||
27 | /* The GNU libc does not support any K&R compilers or the traditional mode | |
28 | of ISO C compilers anymore. Check for some of the combinations not | |
2ea6af74 | 29 | supported anymore. */ |
7688db91 UD |
30 | #if defined __GNUC__ && !defined __STDC__ |
31 | # error "You need a ISO C conforming compiler to use the glibc headers" | |
a6ff34d7 | 32 | #endif |
28f540f4 RM |
33 | |
34 | /* Some user header file might have defined this before. */ | |
35 | #undef __P | |
d112ae30 | 36 | #undef __PMT |
28f540f4 | 37 | |
c8ba52ab AZ |
38 | /* Compilers that lack __has_attribute may object to |
39 | #if defined __has_attribute && __has_attribute (...) | |
40 | even though they do not need to evaluate the right-hand side of the &&. | |
41 | Similarly for __has_builtin, etc. */ | |
42 | #if (defined __has_attribute \ | |
43 | && (!defined __clang_minor__ \ | |
44 | || 3 < __clang_major__ + (5 <= __clang_minor__))) | |
45 | # define __glibc_has_attribute(attr) __has_attribute (attr) | |
46 | #else | |
47 | # define __glibc_has_attribute(attr) 0 | |
48 | #endif | |
49 | #ifdef __has_builtin | |
50 | # define __glibc_has_builtin(name) __has_builtin (name) | |
51 | #else | |
52 | # define __glibc_has_builtin(name) 0 | |
53 | #endif | |
54 | #ifdef __has_extension | |
55 | # define __glibc_has_extension(ext) __has_extension (ext) | |
56 | #else | |
57 | # define __glibc_has_extension(ext) 0 | |
58 | #endif | |
59 | ||
60 | #if defined __GNUC__ || defined __clang__ | |
28f540f4 | 61 | |
3871f58f AS |
62 | /* All functions, except those with callbacks or those that |
63 | synchronize memory, are leaf functions. */ | |
aa78043a UD |
64 | # if __GNUC_PREREQ (4, 6) && !defined _LIBC |
65 | # define __LEAF , __leaf__ | |
66 | # define __LEAF_ATTR __attribute__ ((__leaf__)) | |
67 | # else | |
68 | # define __LEAF | |
69 | # define __LEAF_ATTR | |
70 | # endif | |
71 | ||
dff14448 | 72 | /* GCC can always grok prototypes. For C++ programs we add throw() |
2ea6af74 | 73 | to help it optimize the function calls. But this only works with |
c8ba52ab | 74 | gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions |
f377d022 UD |
75 | as non-throwing using a function attribute since programs can use |
76 | the -fexceptions options for C code as well. */ | |
c8ba52ab AZ |
77 | # if !defined __cplusplus \ |
78 | && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__)) | |
49a43d80 | 79 | # define __THROW __attribute__ ((__nothrow__ __LEAF)) |
3871f58f | 80 | # define __THROWNL __attribute__ ((__nothrow__)) |
49a43d80 | 81 | # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct |
7c3018f9 | 82 | # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct |
dff14448 | 83 | # else |
c8ba52ab | 84 | # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4) |
d445d9ca JW |
85 | # if __cplusplus >= 201103L |
86 | # define __THROW noexcept (true) | |
87 | # else | |
88 | # define __THROW throw () | |
89 | # endif | |
90 | # define __THROWNL __THROW | |
91 | # define __NTH(fct) __LEAF_ATTR fct __THROW | |
92 | # define __NTHNL(fct) fct __THROW | |
f377d022 UD |
93 | # else |
94 | # define __THROW | |
3871f58f | 95 | # define __THROWNL |
f377d022 | 96 | # define __NTH(fct) fct |
7c3018f9 | 97 | # define __NTHNL(fct) fct |
f377d022 | 98 | # endif |
dff14448 | 99 | # endif |
4360eafd | 100 | |
c8ba52ab | 101 | #else /* Not GCC or clang. */ |
28f540f4 | 102 | |
383e87c9 JM |
103 | # if (defined __cplusplus \ |
104 | || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) | |
105 | # define __inline inline | |
106 | # else | |
107 | # define __inline /* No inline functions. */ | |
108 | # endif | |
28f540f4 | 109 | |
9b767d19 | 110 | # define __THROW |
3871f58f | 111 | # define __THROWNL |
f377d022 | 112 | # define __NTH(fct) fct |
28f540f4 | 113 | |
c8ba52ab | 114 | #endif /* GCC || clang. */ |
cab4d74b | 115 | |
d19687d6 UD |
116 | /* These two macros are not used in glibc anymore. They are kept here |
117 | only because some other projects expect the macros to be defined. */ | |
118 | #define __P(args) args | |
119 | #define __PMT(args) args | |
120 | ||
28f540f4 RM |
121 | /* For these things, GCC behaves the ANSI way normally, |
122 | and the non-ANSI way under -traditional. */ | |
123 | ||
7f4e0e58 UD |
124 | #define __CONCAT(x,y) x ## y |
125 | #define __STRING(x) #x | |
28f540f4 RM |
126 | |
127 | /* This is not a typedef so `const __ptr_t' does the right thing. */ | |
7f4e0e58 | 128 | #define __ptr_t void * |
857fa1b8 RM |
129 | |
130 | ||
28f540f4 RM |
131 | /* C++ needs to know that types and declarations are C, not C++. */ |
132 | #ifdef __cplusplus | |
dfd2257a UD |
133 | # define __BEGIN_DECLS extern "C" { |
134 | # define __END_DECLS } | |
28f540f4 | 135 | #else |
dfd2257a UD |
136 | # define __BEGIN_DECLS |
137 | # define __END_DECLS | |
28f540f4 RM |
138 | #endif |
139 | ||
ab95290c | 140 | |
b5cc329c UD |
141 | /* Fortify support. */ |
142 | #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) | |
143 | #define __bos0(ptr) __builtin_object_size (ptr, 0) | |
144 | ||
c43c5796 | 145 | /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */ |
86bf0feb SP |
146 | #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \ |
147 | || __GNUC_PREREQ (12, 0)) | |
c43c5796 SP |
148 | # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0) |
149 | # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1) | |
150 | #else | |
151 | # define __glibc_objsize0(__o) __bos0 (__o) | |
152 | # define __glibc_objsize(__o) __bos (__o) | |
153 | #endif | |
154 | ||
a643f60c SP |
155 | /* Compile time conditions to choose between the regular, _chk and _chk_warn |
156 | variants. These conditions should get evaluated to constant and optimized | |
157 | away. */ | |
158 | ||
159 | #define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s)) | |
160 | #define __glibc_unsigned_or_positive(__l) \ | |
161 | ((__typeof (__l)) 0 < (__typeof (__l)) -1 \ | |
162 | || (__builtin_constant_p (__l) && (__l) > 0)) | |
163 | ||
164 | /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ | |
165 | condition can be folded to a constant and if it is true. The -1 check is | |
166 | redundant because since it implies that __glibc_safe_len_cond is true. */ | |
167 | #define __glibc_safe_or_unknown_len(__l, __s, __osz) \ | |
168 | (__glibc_unsigned_or_positive (__l) \ | |
169 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ | |
170 | __s, __osz)) \ | |
171 | && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) | |
172 | ||
ae23fa3e | 173 | /* Conversely, we know at compile time that the length is unsafe if the |
a643f60c SP |
174 | __L * __S <= __OBJSZ condition can be folded to a constant and if it is |
175 | false. */ | |
176 | #define __glibc_unsafe_len(__l, __s, __osz) \ | |
177 | (__glibc_unsigned_or_positive (__l) \ | |
178 | && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ | |
179 | __s, __osz)) \ | |
180 | && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) | |
181 | ||
182 | /* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be | |
183 | declared. */ | |
184 | ||
185 | #define __glibc_fortify(f, __l, __s, __osz, ...) \ | |
186 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ | |
187 | ? __ ## f ## _alias (__VA_ARGS__) \ | |
188 | : (__glibc_unsafe_len (__l, __s, __osz) \ | |
189 | ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \ | |
190 | : __ ## f ## _chk (__VA_ARGS__, __osz))) \ | |
191 | ||
192 | /* Fortify function f, where object size argument passed to f is the number of | |
193 | elements and not total size. */ | |
194 | ||
195 | #define __glibc_fortify_n(f, __l, __s, __osz, ...) \ | |
196 | (__glibc_safe_or_unknown_len (__l, __s, __osz) \ | |
197 | ? __ ## f ## _alias (__VA_ARGS__) \ | |
198 | : (__glibc_unsafe_len (__l, __s, __osz) \ | |
199 | ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \ | |
200 | : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \ | |
201 | ||
d6cd6bf4 | 202 | #if __GNUC_PREREQ (4,3) |
d6cd6bf4 UD |
203 | # define __warnattr(msg) __attribute__((__warning__ (msg))) |
204 | # define __errordecl(name, msg) \ | |
205 | extern void name (void) __attribute__((__error__ (msg))) | |
206 | #else | |
d6cd6bf4 UD |
207 | # define __warnattr(msg) |
208 | # define __errordecl(name, msg) extern void name (void) | |
209 | #endif | |
b5cc329c | 210 | |
cb765808 ZW |
211 | /* Support for flexible arrays. |
212 | Headers that should use flexible arrays only if they're "real" | |
213 | (e.g. only if they won't affect sizeof()) should test | |
214 | #if __glibc_c99_flexarr_available. */ | |
c8ba52ab | 215 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc |
a1620a4c | 216 | # define __flexarr [] |
cb765808 | 217 | # define __glibc_c99_flexarr_available 1 |
c8ba52ab AZ |
218 | #elif __GNUC_PREREQ (2,97) || defined __clang__ |
219 | /* GCC 2.97 and clang support C99 flexible array members as an extension, | |
cb765808 ZW |
220 | even when in C89 mode or compiling C++ (any version). */ |
221 | # define __flexarr [] | |
222 | # define __glibc_c99_flexarr_available 1 | |
223 | #elif defined __GNUC__ | |
224 | /* Pre-2.97 GCC did not support C99 flexible arrays but did have | |
225 | an equivalent extension with slightly different notation. */ | |
226 | # define __flexarr [0] | |
227 | # define __glibc_c99_flexarr_available 1 | |
a1620a4c | 228 | #else |
a1620a4c | 229 | /* Some other non-C99 compiler. Approximate with [1]. */ |
cb765808 ZW |
230 | # define __flexarr [1] |
231 | # define __glibc_c99_flexarr_available 0 | |
a1620a4c UD |
232 | #endif |
233 | ||
234 | ||
01cad722 UD |
235 | /* __asm__ ("xyz") is used throughout the headers to rename functions |
236 | at the assembly language level. This is wrapped by the __REDIRECT | |
237 | macro, in order to support compilers that can do this some other | |
238 | way. When compilers don't support asm-names at all, we have to do | |
239 | preprocessor tricks instead (which don't have exactly the right | |
240 | semantics, but it's the best we can do). | |
241 | ||
242 | Example: | |
fbedbe9d | 243 | int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */ |
01cad722 | 244 | |
c8ba52ab | 245 | #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4) |
01cad722 | 246 | |
5408c757 | 247 | # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias)) |
05f4d5cd UD |
248 | # ifdef __cplusplus |
249 | # define __REDIRECT_NTH(name, proto, alias) \ | |
250 | name proto __THROW __asm__ (__ASMNAME (#alias)) | |
edc5984d AS |
251 | # define __REDIRECT_NTHNL(name, proto, alias) \ |
252 | name proto __THROWNL __asm__ (__ASMNAME (#alias)) | |
05f4d5cd UD |
253 | # else |
254 | # define __REDIRECT_NTH(name, proto, alias) \ | |
f377d022 | 255 | name proto __asm__ (__ASMNAME (#alias)) __THROW |
edc5984d AS |
256 | # define __REDIRECT_NTHNL(name, proto, alias) \ |
257 | name proto __asm__ (__ASMNAME (#alias)) __THROWNL | |
05f4d5cd | 258 | # endif |
5408c757 UD |
259 | # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) |
260 | # define __ASMNAME2(prefix, cname) __STRING (prefix) cname | |
01cad722 UD |
261 | |
262 | /* | |
263 | #elif __SOME_OTHER_COMPILER__ | |
264 | ||
5408c757 UD |
265 | # define __REDIRECT(name, proto, alias) name proto; \ |
266 | _Pragma("let " #name " = " #alias) | |
01cad722 UD |
267 | */ |
268 | #endif | |
269 | ||
c8ba52ab AZ |
270 | /* GCC and clang have various useful declarations that can be made with |
271 | the '__attribute__' syntax. All of the ways we use this do fine if | |
272 | they are omitted for compilers that don't understand it. */ | |
273 | #if !(defined __GNUC__ || defined __clang__) | |
e9e9b245 | 274 | # define __attribute__(xyz) /* Ignore */ |
ae177b9c UD |
275 | #endif |
276 | ||
e9e9b245 UD |
277 | /* At some point during the gcc 2.96 development the `malloc' attribute |
278 | for functions was introduced. We don't want to use it unconditionally | |
279 | (although this would be possible) since it generates warnings. */ | |
c8ba52ab | 280 | #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__) |
ae177b9c UD |
281 | # define __attribute_malloc__ __attribute__ ((__malloc__)) |
282 | #else | |
283 | # define __attribute_malloc__ /* Ignore */ | |
01cad722 | 284 | #endif |
2f6d1f1b | 285 | |
2f62b9ee MF |
286 | /* Tell the compiler which arguments to an allocation function |
287 | indicate the size of the allocation. */ | |
288 | #if __GNUC_PREREQ (4, 3) | |
289 | # define __attribute_alloc_size__(params) \ | |
290 | __attribute__ ((__alloc_size__ params)) | |
291 | #else | |
292 | # define __attribute_alloc_size__(params) /* Ignore. */ | |
293 | #endif | |
294 | ||
8a9a5931 JW |
295 | /* Tell the compiler which argument to an allocation function |
296 | indicates the alignment of the allocation. */ | |
297 | #if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__) | |
298 | # define __attribute_alloc_align__(param) \ | |
299 | __attribute__ ((__alloc_align__ param)) | |
300 | #else | |
301 | # define __attribute_alloc_align__(param) /* Ignore. */ | |
302 | #endif | |
303 | ||
ca5a4c3c AJ |
304 | /* At some point during the gcc 2.96 development the `pure' attribute |
305 | for functions was introduced. We don't want to use it unconditionally | |
306 | (although this would be possible) since it generates warnings. */ | |
c8ba52ab | 307 | #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__) |
ca5a4c3c AJ |
308 | # define __attribute_pure__ __attribute__ ((__pure__)) |
309 | #else | |
310 | # define __attribute_pure__ /* Ignore */ | |
311 | #endif | |
312 | ||
295e904f | 313 | /* This declaration tells the compiler that the value is constant. */ |
c8ba52ab | 314 | #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__) |
295e904f MP |
315 | # define __attribute_const__ __attribute__ ((__const__)) |
316 | #else | |
317 | # define __attribute_const__ /* Ignore */ | |
318 | #endif | |
319 | ||
c8ba52ab AZ |
320 | #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__) |
321 | # define __attribute_maybe_unused__ __attribute__ ((__unused__)) | |
322 | #else | |
323 | # define __attribute_maybe_unused__ /* Ignore */ | |
324 | #endif | |
325 | ||
d3640b91 UD |
326 | /* At some point during the gcc 3.1 development the `used' attribute |
327 | for functions was introduced. We don't want to use it unconditionally | |
328 | (although this would be possible) since it generates warnings. */ | |
c8ba52ab | 329 | #if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__) |
d3640b91 | 330 | # define __attribute_used__ __attribute__ ((__used__)) |
fb23eb25 | 331 | # define __attribute_noinline__ __attribute__ ((__noinline__)) |
d3640b91 UD |
332 | #else |
333 | # define __attribute_used__ __attribute__ ((__unused__)) | |
fb23eb25 | 334 | # define __attribute_noinline__ /* Ignore */ |
d3640b91 UD |
335 | #endif |
336 | ||
cab4d74b | 337 | /* Since version 3.2, gcc allows marking deprecated functions. */ |
c8ba52ab | 338 | #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__) |
3b7ed871 UD |
339 | # define __attribute_deprecated__ __attribute__ ((__deprecated__)) |
340 | #else | |
341 | # define __attribute_deprecated__ /* Ignore */ | |
342 | #endif | |
343 | ||
cab4d74b ZW |
344 | /* Since version 4.5, gcc also allows one to specify the message printed |
345 | when a deprecated function is used. clang claims to be gcc 4.2, but | |
346 | may also support this feature. */ | |
34a5a146 | 347 | #if __GNUC_PREREQ (4,5) \ |
c8ba52ab | 348 | || __glibc_has_extension (__attribute_deprecated_with_message__) |
cab4d74b ZW |
349 | # define __attribute_deprecated_msg__(msg) \ |
350 | __attribute__ ((__deprecated__ (msg))) | |
351 | #else | |
352 | # define __attribute_deprecated_msg__(msg) __attribute_deprecated__ | |
353 | #endif | |
354 | ||
ca8d5a5f UD |
355 | /* At some point during the gcc 2.8 development the `format_arg' attribute |
356 | for functions was introduced. We don't want to use it unconditionally | |
f369623d UD |
357 | (although this would be possible) since it generates warnings. |
358 | If several `format_arg' attributes are given for the same function, in | |
359 | gcc-3.0 and older, all but the last one are ignored. In newer gccs, | |
360 | all designated arguments are considered. */ | |
c8ba52ab | 361 | #if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__) |
ca8d5a5f UD |
362 | # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))) |
363 | #else | |
364 | # define __attribute_format_arg__(x) /* Ignore */ | |
365 | #endif | |
366 | ||
66e23ba1 UD |
367 | /* At some point during the gcc 2.97 development the `strfmon' format |
368 | attribute for functions was introduced. We don't want to use it | |
369 | unconditionally (although this would be possible) since it | |
370 | generates warnings. */ | |
c8ba52ab | 371 | #if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__) |
66e23ba1 UD |
372 | # define __attribute_format_strfmon__(a,b) \ |
373 | __attribute__ ((__format__ (__strfmon__, a, b))) | |
374 | #else | |
375 | # define __attribute_format_strfmon__(a,b) /* Ignore */ | |
376 | #endif | |
377 | ||
c8ba52ab | 378 | /* The nonnull function attribute marks pointer parameters that |
0b5ca7c3 PE |
379 | must not be NULL. This has the name __nonnull in glibc, |
380 | and __attribute_nonnull__ in files shared with Gnulib to avoid | |
381 | collision with a different __nonnull in DragonFlyBSD 5.9. */ | |
382 | #ifndef __attribute_nonnull__ | |
c8ba52ab | 383 | # if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__) |
0b5ca7c3 | 384 | # define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params)) |
c8ba52ab | 385 | # else |
0b5ca7c3 | 386 | # define __attribute_nonnull__(params) |
c8ba52ab | 387 | # endif |
0b5ca7c3 PE |
388 | #endif |
389 | #ifndef __nonnull | |
390 | # define __nonnull(params) __attribute_nonnull__ (params) | |
8a1f658b UD |
391 | #endif |
392 | ||
b8e8bb32 SP |
393 | /* The returns_nonnull function attribute marks the return type of the function |
394 | as always being non-null. */ | |
395 | #ifndef __returns_nonnull | |
396 | # if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__) | |
397 | # define __returns_nonnull __attribute__ ((__returns_nonnull__)) | |
398 | # else | |
399 | # define __returns_nonnull | |
400 | # endif | |
401 | #endif | |
402 | ||
5cf53cc2 UD |
403 | /* If fortification mode, we warn about unused results of certain |
404 | function calls which can lead to problems. */ | |
c8ba52ab | 405 | #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__) |
9ee4c017 UD |
406 | # define __attribute_warn_unused_result__ \ |
407 | __attribute__ ((__warn_unused_result__)) | |
c8ba52ab | 408 | # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0 |
9ee4c017 UD |
409 | # define __wur __attribute_warn_unused_result__ |
410 | # endif | |
5cf53cc2 | 411 | #else |
9ee4c017 UD |
412 | # define __attribute_warn_unused_result__ /* empty */ |
413 | #endif | |
414 | #ifndef __wur | |
5cf53cc2 UD |
415 | # define __wur /* Ignore */ |
416 | #endif | |
417 | ||
88764ae2 | 418 | /* Forces a function to be always inlined. */ |
c8ba52ab | 419 | #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__) |
e0835a53 CD |
420 | /* The Linux kernel defines __always_inline in stddef.h (283d7573), and |
421 | it conflicts with this definition. Therefore undefine it first to | |
422 | allow either header to be included first. */ | |
423 | # undef __always_inline | |
88764ae2 UD |
424 | # define __always_inline __inline __attribute__ ((__always_inline__)) |
425 | #else | |
e0835a53 | 426 | # undef __always_inline |
88764ae2 UD |
427 | # define __always_inline __inline |
428 | #endif | |
429 | ||
5ac3ea17 MP |
430 | /* Associate error messages with the source location of the call site rather |
431 | than with the source location inside the function. */ | |
c8ba52ab | 432 | #if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__) |
5ac3ea17 MP |
433 | # define __attribute_artificial__ __attribute__ ((__artificial__)) |
434 | #else | |
435 | # define __attribute_artificial__ /* Ignore */ | |
436 | #endif | |
437 | ||
884ddc50 SP |
438 | /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 |
439 | inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__ | |
440 | or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions | |
441 | older than 4.3 may define these macros and still not guarantee GNU inlining | |
602f80ec SP |
442 | semantics. |
443 | ||
444 | clang++ identifies itself as gcc-4.2, but has support for GNU inlining | |
a1b02ae7 | 445 | semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and |
602f80ec SP |
446 | __GNUC_GNU_INLINE__ macro definitions. */ |
447 | #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \ | |
448 | || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \ | |
449 | || defined __GNUC_GNU_INLINE__))) | |
884ddc50 | 450 | # if defined __GNUC_STDC_INLINE__ || defined __cplusplus |
de1c3ebb | 451 | # define __extern_inline extern __inline __attribute__ ((__gnu_inline__)) |
5ac3ea17 | 452 | # define __extern_always_inline \ |
b037a293 | 453 | extern __always_inline __attribute__ ((__gnu_inline__)) |
de1c3ebb UD |
454 | # else |
455 | # define __extern_inline extern __inline | |
5ac3ea17 | 456 | # define __extern_always_inline extern __always_inline |
de1c3ebb | 457 | # endif |
884ddc50 SP |
458 | #endif |
459 | ||
460 | #ifdef __extern_always_inline | |
461 | # define __fortify_function __extern_always_inline __attribute_artificial__ | |
de1c3ebb UD |
462 | #endif |
463 | ||
464 | /* GCC 4.3 and above allow passing all anonymous arguments of an | |
465 | __extern_always_inline function to some other vararg function. */ | |
3dd79d63 | 466 | #if __GNUC_PREREQ (4,3) |
de1c3ebb | 467 | # define __va_arg_pack() __builtin_va_arg_pack () |
3a50811c | 468 | # define __va_arg_pack_len() __builtin_va_arg_pack_len () |
b037a293 UD |
469 | #endif |
470 | ||
8325d82c UD |
471 | /* It is possible to compile containing GCC extensions even if GCC is |
472 | run in pedantic mode if the uses are carefully marked using the | |
473 | `__extension__' keyword. But this is not generally available before | |
474 | version 2.8. */ | |
c8ba52ab | 475 | #if !(__GNUC_PREREQ (2,8) || defined __clang__) |
8325d82c | 476 | # define __extension__ /* Ignore */ |
8325d82c UD |
477 | #endif |
478 | ||
c8ba52ab AZ |
479 | /* __restrict is known in EGCS 1.2 and above, and in clang. |
480 | It works also in C++ mode (outside of arrays), but only when spelled | |
481 | as '__restrict', not 'restrict'. */ | |
482 | #if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3) | |
383e87c9 JM |
483 | # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L |
484 | # define __restrict restrict | |
485 | # else | |
486 | # define __restrict /* Ignore */ | |
487 | # endif | |
a6ff34d7 | 488 | #endif |
2f6d1f1b | 489 | |
98cbe360 UD |
490 | /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is |
491 | array_name[restrict] | |
c8ba52ab AZ |
492 | GCC 3.1 and clang support this. |
493 | This syntax is not usable in C++ mode. */ | |
494 | #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus | |
b912ca11 UD |
495 | # define __restrict_arr __restrict |
496 | #else | |
497 | # ifdef __GNUC__ | |
498 | # define __restrict_arr /* Not supported in old GCC. */ | |
499 | # else | |
500 | # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L | |
501 | # define __restrict_arr restrict | |
502 | # else | |
503 | /* Some other non-C99 compiler. */ | |
504 | # define __restrict_arr /* Not supported. */ | |
505 | # endif | |
506 | # endif | |
507 | #endif | |
98cbe360 | 508 | |
c8ba52ab | 509 | #if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect) |
4858fa2a RM |
510 | # define __glibc_unlikely(cond) __builtin_expect ((cond), 0) |
511 | # define __glibc_likely(cond) __builtin_expect ((cond), 1) | |
4af3879c | 512 | #else |
4858fa2a RM |
513 | # define __glibc_unlikely(cond) (cond) |
514 | # define __glibc_likely(cond) (cond) | |
4af3879c SP |
515 | #endif |
516 | ||
d12704c7 SP |
517 | #if (!defined _Noreturn \ |
518 | && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ | |
c8ba52ab AZ |
519 | && !(__GNUC_PREREQ (4,7) \ |
520 | || (3 < __clang_major__ + (5 <= __clang_minor__)))) | |
c4c41244 PE |
521 | # if __GNUC_PREREQ (2,8) |
522 | # define _Noreturn __attribute__ ((__noreturn__)) | |
523 | # else | |
524 | # define _Noreturn | |
525 | # endif | |
526 | #endif | |
527 | ||
7532837d MS |
528 | #if __GNUC_PREREQ (8, 0) |
529 | /* Describes a char array whose address can safely be passed as the first | |
530 | argument to strncpy and strncat, as the char array is not necessarily | |
531 | a NUL-terminated string. */ | |
532 | # define __attribute_nonstring__ __attribute__ ((__nonstring__)) | |
533 | #else | |
534 | # define __attribute_nonstring__ | |
535 | #endif | |
536 | ||
1626a1cf MS |
537 | /* Undefine (also defined in libc-symbols.h). */ |
538 | #undef __attribute_copy__ | |
539 | #if __GNUC_PREREQ (9, 0) | |
540 | /* Copies attributes from the declaration or type referenced by | |
541 | the argument. */ | |
542 | # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg))) | |
543 | #else | |
544 | # define __attribute_copy__(arg) | |
545 | #endif | |
546 | ||
3999d26e PE |
547 | #if (!defined _Static_assert && !defined __cplusplus \ |
548 | && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ | |
c8ba52ab AZ |
549 | && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \ |
550 | || defined __STRICT_ANSI__)) | |
3999d26e PE |
551 | # define _Static_assert(expr, diagnostic) \ |
552 | extern int (*__Static_assert_function (void)) \ | |
553 | [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })] | |
554 | #endif | |
555 | ||
0b5ca7c3 PE |
556 | /* Gnulib avoids including these, as they don't work on non-glibc or |
557 | older glibc platforms. */ | |
558 | #ifndef __GNULIB_CDEFS | |
c8ba52ab AZ |
559 | # include <bits/wordsize.h> |
560 | # include <bits/long-double.h> | |
561 | #endif | |
c6251f03 | 562 | |
e2239af3 | 563 | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
e4a39992 GG |
564 | # ifdef __REDIRECT |
565 | ||
566 | /* Alias name defined automatically. */ | |
567 | # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir | |
568 | # define __LDBL_REDIR_DECL(name) \ | |
569 | extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128")); | |
570 | ||
571 | /* Alias name defined automatically, with leading underscores. */ | |
572 | # define __LDBL_REDIR2_DECL(name) \ | |
573 | extern __typeof (__##name) __##name \ | |
574 | __asm (__ASMNAME ("__" #name "ieee128")); | |
575 | ||
576 | /* Alias name defined manually. */ | |
577 | # define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1 | |
578 | # define __LDBL_REDIR1_DECL(name, alias) \ | |
579 | extern __typeof (name) name __asm (__ASMNAME (#alias)); | |
580 | ||
581 | # define __LDBL_REDIR1_NTH(name, proto, alias) \ | |
582 | __REDIRECT_NTH (name, proto, alias) | |
583 | # define __REDIRECT_NTH_LDBL(name, proto, alias) \ | |
584 | __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128) | |
585 | ||
586 | /* Unused. */ | |
587 | # define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl | |
588 | # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth | |
589 | ||
590 | # else | |
591 | _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform"); | |
592 | # endif | |
593 | #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH | |
c6251f03 RM |
594 | # define __LDBL_COMPAT 1 |
595 | # ifdef __REDIRECT | |
596 | # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias) | |
597 | # define __LDBL_REDIR(name, proto) \ | |
598 | __LDBL_REDIR1 (name, proto, __nldbl_##name) | |
599 | # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias) | |
600 | # define __LDBL_REDIR_NTH(name, proto) \ | |
601 | __LDBL_REDIR1_NTH (name, proto, __nldbl_##name) | |
e4a39992 GG |
602 | # define __LDBL_REDIR2_DECL(name) \ |
603 | extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name)); | |
54e98f69 RM |
604 | # define __LDBL_REDIR1_DECL(name, alias) \ |
605 | extern __typeof (name) name __asm (__ASMNAME (#alias)); | |
c6251f03 | 606 | # define __LDBL_REDIR_DECL(name) \ |
54e98f69 | 607 | extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name)); |
ac97dec1 UD |
608 | # define __REDIRECT_LDBL(name, proto, alias) \ |
609 | __LDBL_REDIR1 (name, proto, __nldbl_##alias) | |
610 | # define __REDIRECT_NTH_LDBL(name, proto, alias) \ | |
611 | __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias) | |
c6251f03 RM |
612 | # endif |
613 | #endif | |
e2239af3 | 614 | #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \ |
e4a39992 | 615 | || !defined __REDIRECT |
c6251f03 RM |
616 | # define __LDBL_REDIR1(name, proto, alias) name proto |
617 | # define __LDBL_REDIR(name, proto) name proto | |
618 | # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW | |
619 | # define __LDBL_REDIR_NTH(name, proto) name proto __THROW | |
e4a39992 | 620 | # define __LDBL_REDIR2_DECL(name) |
c6251f03 | 621 | # define __LDBL_REDIR_DECL(name) |
ac97dec1 UD |
622 | # ifdef __REDIRECT |
623 | # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias) | |
624 | # define __REDIRECT_NTH_LDBL(name, proto, alias) \ | |
625 | __REDIRECT_NTH (name, proto, alias) | |
626 | # endif | |
c6251f03 RM |
627 | #endif |
628 | ||
bfbd1de1 | 629 | /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is |
809b72df ZW |
630 | intended for use in preprocessor macros. |
631 | ||
632 | Note: MESSAGE must be a _single_ string; concatenation of string | |
633 | literals is not supported. */ | |
634 | #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5) | |
bfbd1de1 FW |
635 | # define __glibc_macro_warning1(message) _Pragma (#message) |
636 | # define __glibc_macro_warning(message) \ | |
637 | __glibc_macro_warning1 (GCC warning message) | |
638 | #else | |
639 | # define __glibc_macro_warning(msg) | |
640 | #endif | |
641 | ||
6913ad65 GG |
642 | /* Generic selection (ISO C11) is a C-only feature, available in GCC |
643 | since version 4.9. Previous versions do not provide generic | |
644 | selection, even though they might set __STDC_VERSION__ to 201112L, | |
645 | when in -std=c11 mode. Thus, we must check for !defined __GNUC__ | |
646 | when testing __STDC_VERSION__ for generic selection support. | |
477bf19a GG |
647 | On the other hand, Clang also defines __GNUC__, so a clang-specific |
648 | check is required to enable the use of generic selection. */ | |
6913ad65 GG |
649 | #if !defined __cplusplus \ |
650 | && (__GNUC_PREREQ (4, 9) \ | |
c8ba52ab | 651 | || __glibc_has_extension (c_generic_selections) \ |
6913ad65 GG |
652 | || (!defined __GNUC__ && defined __STDC_VERSION__ \ |
653 | && __STDC_VERSION__ >= 201112L)) | |
477bf19a GG |
654 | # define __HAVE_GENERIC_SELECTION 1 |
655 | #else | |
656 | # define __HAVE_GENERIC_SELECTION 0 | |
657 | #endif | |
658 | ||
06febd8c MS |
659 | #if __GNUC_PREREQ (10, 0) |
660 | /* Designates a 1-based positional argument ref-index of pointer type | |
661 | that can be used to access size-index elements of the pointed-to | |
662 | array according to access mode, or at least one element when | |
663 | size-index is not provided: | |
664 | access (access-mode, <ref-index> [, <size-index>]) */ | |
a1561c3b | 665 | # define __attr_access(x) __attribute__ ((__access__ x)) |
e938c027 SP |
666 | /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may |
667 | use the access attribute to get object sizes from function definition | |
668 | arguments, so we can't use them on functions we fortify. Drop the object | |
669 | size hints for such functions. */ | |
670 | # if __USE_FORTIFY_LEVEL == 3 | |
671 | # define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o))) | |
672 | # else | |
673 | # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s)) | |
674 | # endif | |
a1561c3b MS |
675 | # if __GNUC_PREREQ (11, 0) |
676 | # define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno))) | |
677 | # else | |
678 | # define __attr_access_none(argno) | |
679 | # endif | |
06febd8c | 680 | #else |
e938c027 | 681 | # define __fortified_attr_access(a, o, s) |
06febd8c | 682 | # define __attr_access(x) |
a1561c3b | 683 | # define __attr_access_none(argno) |
06febd8c MS |
684 | #endif |
685 | ||
c1760eaf MS |
686 | #if __GNUC_PREREQ (11, 0) |
687 | /* Designates dealloc as a function to call to deallocate objects | |
688 | allocated by the declared function. */ | |
689 | # define __attr_dealloc(dealloc, argno) \ | |
690 | __attribute__ ((__malloc__ (dealloc, argno))) | |
691 | # define __attr_dealloc_free __attr_dealloc (__builtin_free, 1) | |
692 | #else | |
693 | # define __attr_dealloc(dealloc, argno) | |
694 | # define __attr_dealloc_free | |
695 | #endif | |
696 | ||
548f467f JM |
697 | /* Specify that a function such as setjmp or vfork may return |
698 | twice. */ | |
699 | #if __GNUC_PREREQ (4, 1) | |
700 | # define __attribute_returns_twice__ __attribute__ ((__returns_twice__)) | |
701 | #else | |
702 | # define __attribute_returns_twice__ /* Ignore. */ | |
703 | #endif | |
704 | ||
28f540f4 | 705 | #endif /* sys/cdefs.h */ |