arm: Fix an incorrect check in ____longjmp_chk [BZ #27709]
[glibc.git] / include / features.h
blobeb97470afac67b0af43a386e564ec147d7195ad1
1 /* Copyright (C) 1991-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _FEATURES_H
19 #define _FEATURES_H 1
21 /* These are defined by the user (or the compiler)
22 to specify the desired environment:
24 __STRICT_ANSI__ ISO Standard C.
25 _ISOC99_SOURCE Extensions to ISO C89 from ISO C99.
26 _ISOC11_SOURCE Extensions to ISO C99 from ISO C11.
27 _ISOC2X_SOURCE Extensions to ISO C99 from ISO C2X.
28 __STDC_WANT_LIB_EXT2__
29 Extensions to ISO C99 from TR 27431-2:2010.
30 __STDC_WANT_IEC_60559_BFP_EXT__
31 Extensions to ISO C11 from TS 18661-1:2014.
32 __STDC_WANT_IEC_60559_FUNCS_EXT__
33 Extensions to ISO C11 from TS 18661-4:2015.
34 __STDC_WANT_IEC_60559_TYPES_EXT__
35 Extensions to ISO C11 from TS 18661-3:2015.
37 _POSIX_SOURCE IEEE Std 1003.1.
38 _POSIX_C_SOURCE If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2;
39 if >=199309L, add IEEE Std 1003.1b-1993;
40 if >=199506L, add IEEE Std 1003.1c-1995;
41 if >=200112L, all of IEEE 1003.1-2004
42 if >=200809L, all of IEEE 1003.1-2008
43 _XOPEN_SOURCE Includes POSIX and XPG things. Set to 500 if
44 Single Unix conformance is wanted, to 600 for the
45 sixth revision, to 700 for the seventh revision.
46 _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions.
47 _LARGEFILE_SOURCE Some more functions for correct standard I/O.
48 _LARGEFILE64_SOURCE Additional functionality from LFS for large files.
49 _FILE_OFFSET_BITS=N Select default filesystem interface.
50 _ATFILE_SOURCE Additional *at interfaces.
51 _SC_SIGSTKSZ_SOURCE Select correct (but non compile-time constant)
52 MINSIGSTKSZ and SIGSTKSZ.
53 _GNU_SOURCE All of the above, plus GNU extensions.
54 _DEFAULT_SOURCE The default set of features (taking precedence over
55 __STRICT_ANSI__).
57 _FORTIFY_SOURCE Add security hardening to many library functions.
58 Set to 1 or 2; 2 performs stricter checks than 1.
60 _REENTRANT, _THREAD_SAFE
61 Obsolete; equivalent to _POSIX_C_SOURCE=199506L.
63 The `-ansi' switch to the GNU C compiler, and standards conformance
64 options such as `-std=c99', define __STRICT_ANSI__. If none of
65 these are defined, or if _DEFAULT_SOURCE is defined, the default is
66 to have _POSIX_SOURCE set to one and _POSIX_C_SOURCE set to
67 200809L, as well as enabling miscellaneous functions from BSD and
68 SVID. If more than one of these are defined, they accumulate. For
69 example __STRICT_ANSI__, _POSIX_SOURCE and _POSIX_C_SOURCE together
70 give you ISO C, 1003.1, and 1003.2, but nothing else.
72 These are defined by this file and are used by the
73 header files to decide what to declare or define:
75 __GLIBC_USE (F) Define things from feature set F. This is defined
76 to 1 or 0; the subsequent macros are either defined
77 or undefined, and those tests should be moved to
78 __GLIBC_USE.
79 __USE_ISOC11 Define ISO C11 things.
80 __USE_ISOC99 Define ISO C99 things.
81 __USE_ISOC95 Define ISO C90 AMD1 (C95) things.
82 __USE_ISOCXX11 Define ISO C++11 things.
83 __USE_POSIX Define IEEE Std 1003.1 things.
84 __USE_POSIX2 Define IEEE Std 1003.2 things.
85 __USE_POSIX199309 Define IEEE Std 1003.1, and .1b things.
86 __USE_POSIX199506 Define IEEE Std 1003.1, .1b, .1c and .1i things.
87 __USE_XOPEN Define XPG things.
88 __USE_XOPEN_EXTENDED Define X/Open Unix things.
89 __USE_UNIX98 Define Single Unix V2 things.
90 __USE_XOPEN2K Define XPG6 things.
91 __USE_XOPEN2KXSI Define XPG6 XSI things.
92 __USE_XOPEN2K8 Define XPG7 things.
93 __USE_XOPEN2K8XSI Define XPG7 XSI things.
94 __USE_LARGEFILE Define correct standard I/O things.
95 __USE_LARGEFILE64 Define LFS things with separate names.
96 __USE_FILE_OFFSET64 Define 64bit interface as default.
97 __USE_MISC Define things from 4.3BSD or System V Unix.
98 __USE_ATFILE Define *at interfaces and AT_* constants for them.
99 __USE_SC_SIGSTKSZ Define correct (but non compile-time constant)
100 MINSIGSTKSZ and SIGSTKSZ.
101 __USE_GNU Define GNU extensions.
102 __USE_FORTIFY_LEVEL Additional security measures used, according to level.
104 The macros `__GNU_LIBRARY__', `__GLIBC__', and `__GLIBC_MINOR__' are
105 defined by this file unconditionally. `__GNU_LIBRARY__' is provided
106 only for compatibility. All new code should use the other symbols
107 to test for features.
109 All macros listed above as possibly being defined by this file are
110 explicitly undefined if they are not explicitly defined.
111 Feature-test macros that are not defined by the user or compiler
112 but are implied by the other feature-test macros defined (or by the
113 lack of any definitions) are defined by the file.
115 ISO C feature test macros depend on the definition of the macro
116 when an affected header is included, not when the first system
117 header is included, and so they are handled in
118 <bits/libc-header-start.h>, which does not have a multiple include
119 guard. Feature test macros that can be handled from the first
120 system header included are handled here. */
123 /* Undefine everything, so we get a clean slate. */
124 #undef __USE_ISOC11
125 #undef __USE_ISOC99
126 #undef __USE_ISOC95
127 #undef __USE_ISOCXX11
128 #undef __USE_POSIX
129 #undef __USE_POSIX2
130 #undef __USE_POSIX199309
131 #undef __USE_POSIX199506
132 #undef __USE_XOPEN
133 #undef __USE_XOPEN_EXTENDED
134 #undef __USE_UNIX98
135 #undef __USE_XOPEN2K
136 #undef __USE_XOPEN2KXSI
137 #undef __USE_XOPEN2K8
138 #undef __USE_XOPEN2K8XSI
139 #undef __USE_LARGEFILE
140 #undef __USE_LARGEFILE64
141 #undef __USE_FILE_OFFSET64
142 #undef __USE_MISC
143 #undef __USE_ATFILE
144 #undef __USE_SC_SIGSTKSZ
145 #undef __USE_GNU
146 #undef __USE_FORTIFY_LEVEL
147 #undef __KERNEL_STRICT_NAMES
148 #undef __GLIBC_USE_ISOC2X
149 #undef __GLIBC_USE_DEPRECATED_GETS
150 #undef __GLIBC_USE_DEPRECATED_SCANF
152 /* Suppress kernel-name space pollution unless user expressedly asks
153 for it. */
154 #ifndef _LOOSE_KERNEL_NAMES
155 # define __KERNEL_STRICT_NAMES
156 #endif
158 /* Convenience macro to test the version of gcc.
159 Use like this:
160 #if __GNUC_PREREQ (2,8)
161 ... code requiring gcc 2.8 or later ...
162 #endif
163 Note: only works for GCC 2.0 and later, because __GNUC_MINOR__ was
164 added in 2.0. */
165 #if defined __GNUC__ && defined __GNUC_MINOR__
166 # define __GNUC_PREREQ(maj, min) \
167 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
168 #else
169 # define __GNUC_PREREQ(maj, min) 0
170 #endif
172 /* Similarly for clang. Features added to GCC after version 4.2 may
173 or may not also be available in clang, and clang's definitions of
174 __GNUC(_MINOR)__ are fixed at 4 and 2 respectively. Not all such
175 features can be queried via __has_extension/__has_feature. */
176 #if defined __clang_major__ && defined __clang_minor__
177 # define __glibc_clang_prereq(maj, min) \
178 ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
179 #else
180 # define __glibc_clang_prereq(maj, min) 0
181 #endif
183 /* Whether to use feature set F. */
184 #define __GLIBC_USE(F) __GLIBC_USE_ ## F
186 /* _BSD_SOURCE and _SVID_SOURCE are deprecated aliases for
187 _DEFAULT_SOURCE. If _DEFAULT_SOURCE is present we do not
188 issue a warning; the expectation is that the source is being
189 transitioned to use the new macro. */
190 #if (defined _BSD_SOURCE || defined _SVID_SOURCE) \
191 && !defined _DEFAULT_SOURCE
192 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
193 # undef _DEFAULT_SOURCE
194 # define _DEFAULT_SOURCE 1
195 #endif
197 /* If _GNU_SOURCE was defined by the user, turn on all the other features. */
198 #ifdef _GNU_SOURCE
199 # undef _ISOC95_SOURCE
200 # define _ISOC95_SOURCE 1
201 # undef _ISOC99_SOURCE
202 # define _ISOC99_SOURCE 1
203 # undef _ISOC11_SOURCE
204 # define _ISOC11_SOURCE 1
205 # undef _ISOC2X_SOURCE
206 # define _ISOC2X_SOURCE 1
207 # undef _POSIX_SOURCE
208 # define _POSIX_SOURCE 1
209 # undef _POSIX_C_SOURCE
210 # define _POSIX_C_SOURCE 200809L
211 # undef _XOPEN_SOURCE
212 # define _XOPEN_SOURCE 700
213 # undef _XOPEN_SOURCE_EXTENDED
214 # define _XOPEN_SOURCE_EXTENDED 1
215 # undef _LARGEFILE64_SOURCE
216 # define _LARGEFILE64_SOURCE 1
217 # undef _DEFAULT_SOURCE
218 # define _DEFAULT_SOURCE 1
219 # undef _ATFILE_SOURCE
220 # define _ATFILE_SOURCE 1
221 # undef _SC_SIGSTKSZ_SOURCE
222 # define _SC_SIGSTKSZ_SOURCE 1
223 #endif
225 /* If nothing (other than _GNU_SOURCE and _DEFAULT_SOURCE) is defined,
226 define _DEFAULT_SOURCE. */
227 #if (defined _DEFAULT_SOURCE \
228 || (!defined __STRICT_ANSI__ \
229 && !defined _ISOC99_SOURCE && !defined _ISOC11_SOURCE \
230 && !defined _ISOC2X_SOURCE \
231 && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE \
232 && !defined _XOPEN_SOURCE))
233 # undef _DEFAULT_SOURCE
234 # define _DEFAULT_SOURCE 1
235 #endif
237 /* This is to enable the ISO C2X extension. */
238 #if (defined _ISOC2X_SOURCE \
239 || (defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L))
240 # define __GLIBC_USE_ISOC2X 1
241 #else
242 # define __GLIBC_USE_ISOC2X 0
243 #endif
245 /* This is to enable the ISO C11 extension. */
246 #if (defined _ISOC11_SOURCE || defined _ISOC2X_SOURCE \
247 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L))
248 # define __USE_ISOC11 1
249 #endif
251 /* This is to enable the ISO C99 extension. */
252 #if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
253 || defined _ISOC2X_SOURCE \
254 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
255 # define __USE_ISOC99 1
256 #endif
258 /* This is to enable the ISO C90 Amendment 1:1995 extension. */
259 #if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
260 || defined _ISOC2X_SOURCE \
261 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199409L))
262 # define __USE_ISOC95 1
263 #endif
265 #ifdef __cplusplus
266 /* This is to enable compatibility for ISO C++17. */
267 # if __cplusplus >= 201703L
268 # define __USE_ISOC11 1
269 # endif
270 /* This is to enable compatibility for ISO C++11.
271 Check the temporary macro for now, too. */
272 # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__
273 # define __USE_ISOCXX11 1
274 # define __USE_ISOC99 1
275 # endif
276 #endif
278 /* If none of the ANSI/POSIX macros are defined, or if _DEFAULT_SOURCE
279 is defined, use POSIX.1-2008 (or another version depending on
280 _XOPEN_SOURCE). */
281 #ifdef _DEFAULT_SOURCE
282 # if !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE
283 # define __USE_POSIX_IMPLICITLY 1
284 # endif
285 # undef _POSIX_SOURCE
286 # define _POSIX_SOURCE 1
287 # undef _POSIX_C_SOURCE
288 # define _POSIX_C_SOURCE 200809L
289 #endif
291 #if ((!defined __STRICT_ANSI__ \
292 || (defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 500)) \
293 && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
294 # define _POSIX_SOURCE 1
295 # if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
296 # define _POSIX_C_SOURCE 2
297 # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600
298 # define _POSIX_C_SOURCE 199506L
299 # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 700
300 # define _POSIX_C_SOURCE 200112L
301 # else
302 # define _POSIX_C_SOURCE 200809L
303 # endif
304 # define __USE_POSIX_IMPLICITLY 1
305 #endif
307 /* Some C libraries once required _REENTRANT and/or _THREAD_SAFE to be
308 defined in all multithreaded code. GNU libc has not required this
309 for many years. We now treat them as compatibility synonyms for
310 _POSIX_C_SOURCE=199506L, which is the earliest level of POSIX with
311 comprehensive support for multithreaded code. Using them never
312 lowers the selected level of POSIX conformance, only raises it. */
313 #if ((!defined _POSIX_C_SOURCE || (_POSIX_C_SOURCE - 0) < 199506L) \
314 && (defined _REENTRANT || defined _THREAD_SAFE))
315 # define _POSIX_SOURCE 1
316 # undef _POSIX_C_SOURCE
317 # define _POSIX_C_SOURCE 199506L
318 #endif
320 #if (defined _POSIX_SOURCE \
321 || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1) \
322 || defined _XOPEN_SOURCE)
323 # define __USE_POSIX 1
324 #endif
326 #if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || defined _XOPEN_SOURCE
327 # define __USE_POSIX2 1
328 #endif
330 #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L
331 # define __USE_POSIX199309 1
332 #endif
334 #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199506L
335 # define __USE_POSIX199506 1
336 #endif
338 #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200112L
339 # define __USE_XOPEN2K 1
340 # undef __USE_ISOC95
341 # define __USE_ISOC95 1
342 # undef __USE_ISOC99
343 # define __USE_ISOC99 1
344 #endif
346 #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200809L
347 # define __USE_XOPEN2K8 1
348 # undef _ATFILE_SOURCE
349 # define _ATFILE_SOURCE 1
350 #endif
352 #ifdef _XOPEN_SOURCE
353 # define __USE_XOPEN 1
354 # if (_XOPEN_SOURCE - 0) >= 500
355 # define __USE_XOPEN_EXTENDED 1
356 # define __USE_UNIX98 1
357 # undef _LARGEFILE_SOURCE
358 # define _LARGEFILE_SOURCE 1
359 # if (_XOPEN_SOURCE - 0) >= 600
360 # if (_XOPEN_SOURCE - 0) >= 700
361 # define __USE_XOPEN2K8 1
362 # define __USE_XOPEN2K8XSI 1
363 # endif
364 # define __USE_XOPEN2K 1
365 # define __USE_XOPEN2KXSI 1
366 # undef __USE_ISOC95
367 # define __USE_ISOC95 1
368 # undef __USE_ISOC99
369 # define __USE_ISOC99 1
370 # endif
371 # else
372 # ifdef _XOPEN_SOURCE_EXTENDED
373 # define __USE_XOPEN_EXTENDED 1
374 # endif
375 # endif
376 #endif
378 #ifdef _LARGEFILE_SOURCE
379 # define __USE_LARGEFILE 1
380 #endif
382 #ifdef _LARGEFILE64_SOURCE
383 # define __USE_LARGEFILE64 1
384 #endif
386 #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
387 # define __USE_FILE_OFFSET64 1
388 #endif
390 #if defined _DEFAULT_SOURCE
391 # define __USE_MISC 1
392 #endif
394 #ifdef _ATFILE_SOURCE
395 # define __USE_ATFILE 1
396 #endif
398 #ifdef _SC_SIGSTKSZ_SOURCE
399 # define __USE_SC_SIGSTKSZ 1
400 #endif
402 #ifdef _GNU_SOURCE
403 # define __USE_GNU 1
404 #endif
406 #if defined _FORTIFY_SOURCE && _FORTIFY_SOURCE > 0
407 # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
408 # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
409 # elif !__GNUC_PREREQ (4, 1)
410 # warning _FORTIFY_SOURCE requires GCC 4.1 or later
411 # elif _FORTIFY_SOURCE > 2 && __glibc_clang_prereq (9, 0)
412 # if _FORTIFY_SOURCE > 3
413 # warning _FORTIFY_SOURCE > 3 is treated like 3 on this platform
414 # endif
415 # define __USE_FORTIFY_LEVEL 3
416 # elif _FORTIFY_SOURCE > 1
417 # if _FORTIFY_SOURCE > 2
418 # warning _FORTIFY_SOURCE > 2 is treated like 2 on this platform
419 # endif
420 # define __USE_FORTIFY_LEVEL 2
421 # else
422 # define __USE_FORTIFY_LEVEL 1
423 # endif
424 #endif
425 #ifndef __USE_FORTIFY_LEVEL
426 # define __USE_FORTIFY_LEVEL 0
427 #endif
429 /* The function 'gets' existed in C89, but is impossible to use
430 safely. It has been removed from ISO C11 and ISO C++14. Note: for
431 compatibility with various implementations of <cstdio>, this test
432 must consider only the value of __cplusplus when compiling C++. */
433 #if defined __cplusplus ? __cplusplus >= 201402L : defined __USE_ISOC11
434 # define __GLIBC_USE_DEPRECATED_GETS 0
435 #else
436 # define __GLIBC_USE_DEPRECATED_GETS 1
437 #endif
439 /* GNU formerly extended the scanf functions with modified format
440 specifiers %as, %aS, and %a[...] that allocate a buffer for the
441 input using malloc. This extension conflicts with ISO C99, which
442 defines %a as a standalone format specifier that reads a floating-
443 point number; moreover, POSIX.1-2008 provides the same feature
444 using the modifier letter 'm' instead (%ms, %mS, %m[...]).
446 We now follow C99 unless GNU extensions are active and the compiler
447 is specifically in C89 or C++98 mode (strict or not). For
448 instance, with GCC, -std=gnu11 will have C99-compliant scanf with
449 or without -D_GNU_SOURCE, but -std=c89 -D_GNU_SOURCE will have the
450 old extension. */
451 #if (defined __USE_GNU \
452 && (defined __cplusplus \
453 ? (__cplusplus < 201103L && !defined __GXX_EXPERIMENTAL_CXX0X__) \
454 : (!defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L)))
455 # define __GLIBC_USE_DEPRECATED_SCANF 1
456 #else
457 # define __GLIBC_USE_DEPRECATED_SCANF 0
458 #endif
460 /* Get definitions of __STDC_* predefined macros, if the compiler has
461 not preincluded this header automatically. */
462 #include <stdc-predef.h>
464 /* This macro indicates that the installed library is the GNU C Library.
465 For historic reasons the value now is 6 and this will stay from now
466 on. The use of this variable is deprecated. Use __GLIBC__ and
467 __GLIBC_MINOR__ now (see below) when you want to test for a specific
468 GNU C library version and use the values in <gnu/lib-names.h> to get
469 the sonames of the shared libraries. */
470 #undef __GNU_LIBRARY__
471 #define __GNU_LIBRARY__ 6
473 /* Major and minor version number of the GNU C library package. Use
474 these macros to test for features in specific releases. */
475 #define __GLIBC__ 2
476 #define __GLIBC_MINOR__ 33
478 #define __GLIBC_PREREQ(maj, min) \
479 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
481 /* This is here only because every header file already includes this one. */
482 #ifndef __ASSEMBLER__
483 # ifndef _SYS_CDEFS_H
484 # include <sys/cdefs.h>
485 # endif
487 /* If we don't have __REDIRECT, prototypes will be missing if
488 __USE_FILE_OFFSET64 but not __USE_LARGEFILE[64]. */
489 # if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
490 # define __USE_LARGEFILE 1
491 # define __USE_LARGEFILE64 1
492 # endif
494 #endif /* !ASSEMBLER */
496 /* Decide whether we can define 'extern inline' functions in headers. */
497 #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
498 && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
499 && defined __extern_inline
500 # define __USE_EXTERN_INLINES 1
501 #endif
504 /* This is here only because every header file already includes this one.
505 Get the definitions of all the appropriate `__stub_FUNCTION' symbols.
506 <gnu/stubs.h> contains `#define __stub_FUNCTION' when FUNCTION is a stub
507 that will always return failure (and set errno to ENOSYS). */
508 #include <gnu/stubs.h>
511 #endif /* features.h */