diff options
author | Tom Tromey <tromey@adacore.com> | 2022-04-18 09:44:18 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-04-18 10:14:04 -0600 |
commit | dc6c21dabfbd242616b9e6266b459eded2d0762b (patch) | |
tree | b2fbadbdbcd20dfa3f9dfe179db1c348e2aa5901 /gnulib/import/cdefs.h | |
parent | 2390419d1cb72882110538e01e5586372df19657 (diff) | |
download | binutils-gdb-dc6c21dabfbd242616b9e6266b459eded2d0762b.tar.gz |
Update gnulib
This updates gnulib to a relatively recent commit. Most of this was
done by the gnulib import script; the only change I made was to
update-gnulib.sh.
Tested on x86-64 Fedora 34. I also did a mingw cross build.
Diffstat (limited to 'gnulib/import/cdefs.h')
-rw-r--r-- | gnulib/import/cdefs.h | 206 |
1 files changed, 151 insertions, 55 deletions
diff --git a/gnulib/import/cdefs.h b/gnulib/import/cdefs.h index 03e26d47dcb..cb2514504f1 100644 --- a/gnulib/import/cdefs.h +++ b/gnulib/import/cdefs.h @@ -1,17 +1,18 @@ -/* Copyright (C) 1992-2021 Free Software Foundation, Inc. +/* Copyright (C) 1992-2022 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public + modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. + version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public + You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ @@ -34,31 +35,28 @@ #undef __P #undef __PMT -/* Compilers that are not clang may object to - #if defined __clang__ && __has_attribute(...) - even though they do not need to evaluate the right-hand side of the &&. */ -#if defined __clang__ && defined __has_attribute -# define __glibc_clang_has_attribute(name) __has_attribute (name) +/* Compilers that lack __has_attribute may object to + #if defined __has_attribute && __has_attribute (...) + even though they do not need to evaluate the right-hand side of the &&. + Similarly for __has_builtin, etc. */ +#if (defined __has_attribute \ + && (!defined __clang_minor__ \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))) +# define __glibc_has_attribute(attr) __has_attribute (attr) #else -# define __glibc_clang_has_attribute(name) 0 +# define __glibc_has_attribute(attr) 0 #endif - -/* Compilers that are not clang may object to - #if defined __clang__ && __has_builtin(...) - even though they do not need to evaluate the right-hand side of the &&. */ -#if defined __clang__ && defined __has_builtin -# define __glibc_clang_has_builtin(name) __has_builtin (name) +#ifdef __has_builtin +# define __glibc_has_builtin(name) __has_builtin (name) #else -# define __glibc_clang_has_builtin(name) 0 +# define __glibc_has_builtin(name) 0 #endif - -/* Compilers that are not clang may object to - #if defined __clang__ && __has_extension(...) - even though they do not need to evaluate the right-hand side of the &&. */ -#if defined __clang__ && defined __has_extension -# define __glibc_clang_has_extension(ext) __has_extension (ext) +#ifdef __has_extension +# define __glibc_has_extension(ext) __has_extension (ext) #else -# define __glibc_clang_has_extension(ext) 0 +# define __glibc_has_extension(ext) 0 #endif #if defined __GNUC__ || defined __clang__ @@ -79,7 +77,7 @@ as non-throwing using a function attribute since programs can use the -fexceptions options for C code as well. */ # if !defined __cplusplus \ - && (__GNUC_PREREQ (3, 4) || __glibc_clang_has_attribute (__nothrow__)) + && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__)) # define __THROW __attribute__ ((__nothrow__ __LEAF)) # define __THROWNL __attribute__ ((__nothrow__)) # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct @@ -147,7 +145,8 @@ #define __bos0(ptr) __builtin_object_size (ptr, 0) /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */ -#if __USE_FORTIFY_LEVEL == 3 && __glibc_clang_prereq (9, 0) +#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \ + || __GNUC_PREREQ (12, 0)) # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0) # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1) #else @@ -155,6 +154,53 @@ # define __glibc_objsize(__o) __bos (__o) #endif +/* Compile time conditions to choose between the regular, _chk and _chk_warn + variants. These conditions should get evaluated to constant and optimized + away. */ + +#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s)) +#define __glibc_unsigned_or_positive(__l) \ + ((__typeof (__l)) 0 < (__typeof (__l)) -1 \ + || (__builtin_constant_p (__l) && (__l) > 0)) + +/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ + condition can be folded to a constant and if it is true. The -1 check is + redundant because since it implies that __glibc_safe_len_cond is true. */ +#define __glibc_safe_or_unknown_len(__l, __s, __osz) \ + (__glibc_unsigned_or_positive (__l) \ + && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ + __s, __osz)) \ + && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) + +/* Conversely, we know at compile time that the length is unsafe if the + __L * __S <= __OBJSZ condition can be folded to a constant and if it is + false. */ +#define __glibc_unsafe_len(__l, __s, __osz) \ + (__glibc_unsigned_or_positive (__l) \ + && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \ + __s, __osz)) \ + && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz)) + +/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be + declared. */ + +#define __glibc_fortify(f, __l, __s, __osz, ...) \ + (__glibc_safe_or_unknown_len (__l, __s, __osz) \ + ? __ ## f ## _alias (__VA_ARGS__) \ + : (__glibc_unsafe_len (__l, __s, __osz) \ + ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \ + : __ ## f ## _chk (__VA_ARGS__, __osz))) \ + +/* Fortify function f, where object size argument passed to f is the number of + elements and not total size. */ + +#define __glibc_fortify_n(f, __l, __s, __osz, ...) \ + (__glibc_safe_or_unknown_len (__l, __s, __osz) \ + ? __ ## f ## _alias (__VA_ARGS__) \ + : (__glibc_unsafe_len (__l, __s, __osz) \ + ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \ + : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \ + #if __GNUC_PREREQ (4,3) # define __warnattr(msg) __attribute__((__warning__ (msg))) # define __errordecl(name, msg) \ @@ -233,7 +279,7 @@ /* At some point during the gcc 2.96 development the `malloc' attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__malloc__) +#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__) # define __attribute_malloc__ __attribute__ ((__malloc__)) #else # define __attribute_malloc__ /* Ignore */ @@ -248,26 +294,41 @@ # define __attribute_alloc_size__(params) /* Ignore. */ #endif +/* Tell the compiler which argument to an allocation function + indicates the alignment of the allocation. */ +#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__) +# define __attribute_alloc_align__(param) \ + __attribute__ ((__alloc_align__ param)) +#else +# define __attribute_alloc_align__(param) /* Ignore. */ +#endif + /* At some point during the gcc 2.96 development the `pure' attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,96) || __glibc_clang_has_attribute (__pure__) +#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__) # define __attribute_pure__ __attribute__ ((__pure__)) #else # define __attribute_pure__ /* Ignore */ #endif /* This declaration tells the compiler that the value is constant. */ -#if __GNUC_PREREQ (2,5) || __glibc_clang_has_attribute (__const__) +#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__) # define __attribute_const__ __attribute__ ((__const__)) #else # define __attribute_const__ /* Ignore */ #endif +#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__) +# define __attribute_maybe_unused__ __attribute__ ((__unused__)) +#else +# define __attribute_maybe_unused__ /* Ignore */ +#endif + /* At some point during the gcc 3.1 development the `used' attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (3,1) || __glibc_clang_has_attribute (__used__) +#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__) # define __attribute_used__ __attribute__ ((__used__)) # define __attribute_noinline__ __attribute__ ((__noinline__)) #else @@ -276,7 +337,7 @@ #endif /* Since version 3.2, gcc allows marking deprecated functions. */ -#if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__deprecated__) +#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__) # define __attribute_deprecated__ __attribute__ ((__deprecated__)) #else # define __attribute_deprecated__ /* Ignore */ @@ -286,7 +347,7 @@ when a deprecated function is used. clang claims to be gcc 4.2, but may also support this feature. */ #if __GNUC_PREREQ (4,5) \ - || __glibc_clang_has_extension (__attribute_deprecated_with_message__) + || __glibc_has_extension (__attribute_deprecated_with_message__) # define __attribute_deprecated_msg__(msg) \ __attribute__ ((__deprecated__ (msg))) #else @@ -299,7 +360,7 @@ If several `format_arg' attributes are given for the same function, in gcc-3.0 and older, all but the last one are ignored. In newer gccs, all designated arguments are considered. */ -#if __GNUC_PREREQ (2,8) || __glibc_clang_has_attribute (__format_arg__) +#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__) # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))) #else # define __attribute_format_arg__(x) /* Ignore */ @@ -309,7 +370,7 @@ attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. */ -#if __GNUC_PREREQ (2,97) || __glibc_clang_has_attribute (__format__) +#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__) # define __attribute_format_strfmon__(a,b) \ __attribute__ ((__format__ (__strfmon__, a, b))) #else @@ -317,19 +378,33 @@ #endif /* The nonnull function attribute marks pointer parameters that - must not be NULL. Do not define __nonnull if it is already defined, - for portability when this file is used in Gnulib. */ + must not be NULL. This has the name __nonnull in glibc, + and __attribute_nonnull__ in files shared with Gnulib to avoid + collision with a different __nonnull in DragonFlyBSD 5.9. */ +#ifndef __attribute_nonnull__ +# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__) +# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params)) +# else +# define __attribute_nonnull__(params) +# endif +#endif #ifndef __nonnull -# if __GNUC_PREREQ (3,3) || __glibc_clang_has_attribute (__nonnull__) -# define __nonnull(params) __attribute__ ((__nonnull__ params)) +# define __nonnull(params) __attribute_nonnull__ (params) +#endif + +/* The returns_nonnull function attribute marks the return type of the function + as always being non-null. */ +#ifndef __returns_nonnull +# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__) +# define __returns_nonnull __attribute__ ((__returns_nonnull__)) # else -# define __nonnull(params) +# define __returns_nonnull # endif #endif /* If fortification mode, we warn about unused results of certain function calls which can lead to problems. */ -#if __GNUC_PREREQ (3,4) || __glibc_clang_has_attribute (__warn_unused_result__) +#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__) # define __attribute_warn_unused_result__ \ __attribute__ ((__warn_unused_result__)) # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0 @@ -343,7 +418,7 @@ #endif /* Forces a function to be always inlined. */ -#if __GNUC_PREREQ (3,2) || __glibc_clang_has_attribute (__always_inline__) +#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__) /* The Linux kernel defines __always_inline in stddef.h (283d7573), and it conflicts with this definition. Therefore undefine it first to allow either header to be included first. */ @@ -356,7 +431,7 @@ /* Associate error messages with the source location of the call site rather than with the source location inside the function. */ -#if __GNUC_PREREQ (4,3) || __glibc_clang_has_attribute (__artificial__) +#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__) # define __attribute_artificial__ __attribute__ ((__artificial__)) #else # define __attribute_artificial__ /* Ignore */ @@ -433,7 +508,7 @@ # endif #endif -#if (__GNUC__ >= 3) || __glibc_clang_has_builtin (__builtin_expect) +#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect) # define __glibc_unlikely(cond) __builtin_expect ((cond), 0) # define __glibc_likely(cond) __builtin_expect ((cond), 1) #else @@ -441,12 +516,6 @@ # define __glibc_likely(cond) (cond) #endif -#ifdef __has_attribute -# define __glibc_has_attribute(attr) __has_attribute (attr) -#else -# define __glibc_has_attribute(attr) 0 -#endif - #if (!defined _Noreturn \ && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ && !(__GNUC_PREREQ (4,7) \ @@ -486,9 +555,9 @@ [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })] #endif -/* The #ifndef lets Gnulib avoid including these on non-glibc - platforms, where the includes typically do not exist. */ -#ifndef __WORDSIZE +/* Gnulib avoids including these, as they don't work on non-glibc or + older glibc platforms. */ +#ifndef __GNULIB_CDEFS # include <bits/wordsize.h> # include <bits/long-double.h> #endif @@ -581,7 +650,7 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf check is required to enable the use of generic selection. */ #if !defined __cplusplus \ && (__GNUC_PREREQ (4, 9) \ - || __glibc_clang_has_extension (c_generic_selections) \ + || __glibc_has_extension (c_generic_selections) \ || (!defined __GNUC__ && defined __STDC_VERSION__ \ && __STDC_VERSION__ >= 201112L)) # define __HAVE_GENERIC_SELECTION 1 @@ -595,9 +664,36 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf array according to access mode, or at least one element when size-index is not provided: access (access-mode, <ref-index> [, <size-index>]) */ -#define __attr_access(x) __attribute__ ((__access__ x)) +# define __attr_access(x) __attribute__ ((__access__ x)) +/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may + use the access attribute to get object sizes from function definition + arguments, so we can't use them on functions we fortify. Drop the object + size hints for such functions. */ +# if __USE_FORTIFY_LEVEL == 3 +# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o))) +# else +# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s)) +# endif +# if __GNUC_PREREQ (11, 0) +# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno))) +# else +# define __attr_access_none(argno) +# endif #else +# define __fortified_attr_access(a, o, s) # define __attr_access(x) +# define __attr_access_none(argno) +#endif + +#if __GNUC_PREREQ (11, 0) +/* Designates dealloc as a function to call to deallocate objects + allocated by the declared function. */ +# define __attr_dealloc(dealloc, argno) \ + __attribute__ ((__malloc__ (dealloc, argno))) +# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1) +#else +# define __attr_dealloc(dealloc, argno) +# define __attr_dealloc_free #endif /* Specify that a function such as setjmp or vfork may return |