summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHauke Mehrtens2025-10-26 23:16:01 +0100
committerjvoisin2025-10-28 20:09:50 +0100
commit4b6225cf322adf3e47425156e00a844b2f08e221 (patch)
tree82b4cf708aec0ca165bccac0c7dec528fd7e571d /include
parent7027b39b4de8ba361efce499472008e21ee29f86 (diff)
fortify-headers: Remove __fh_has_builtin()
GCC complains about the `defined` usage here. Just call `__has_builtin` directly. This fixes the following compile error when compiling strace: ``` In file included from /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/stdlib.h:27, from number_set.c:14: /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined] 26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x)) | ^~~~~~~~~~~~~ /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:28:7: note: in expansion of macro '__fh_has_builtin' 28 | #if ! __fh_has_builtin(__builtin_trap) | ^~~~~~~~~~~~~~~~ /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined] 26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x)) | ^~~~~~~~~~~~~ /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:73:29: note: in expansion of macro '__fh_has_builtin' 73 | #if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size) | ^~~~~~~~~~~~~~~~ /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined] 26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x)) | ^~~~~~~~~~~~~ /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:158:5: note: in expansion of macro '__fh_has_builtin' 158 | #if __fh_has_builtin (__builtin_mul_overflow_p) | ^~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h14
1 files changed, 3 insertions, 11 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index f7d8af8..7e84075 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -21,21 +21,13 @@
21#error a compiler with __has_builtin support is required 21#error a compiler with __has_builtin support is required
22#endif 22#endif
23 23
24// https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin
25// > __has_builtin should not be used to detect support for a builtin macro; use #ifdef instead.
26#define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
27
28#if ! __fh_has_builtin(__builtin_trap)
29#define __builtin_trap abort
30#endif
31
32#if _FORTIFY_SOURCE > 3 24#if _FORTIFY_SOURCE > 3
33#warning _FORTIFY_SOURCE > 3 is treated as 3 25#warning _FORTIFY_SOURCE > 3 is treated as 3
34#endif 26#endif
35 27
36#ifdef __clang__ 28#ifdef __clang__
37 29
38#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size) 30#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size)
39#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n))) 31#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n)))
40#else 32#else
41#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n))) 33#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n)))
@@ -70,7 +62,7 @@
70#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE 62#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
71 63
72/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ 64/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */
73#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size) 65#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size)
74/* 66/*
75 * See: 67 * See:
76 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html 68 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
@@ -155,7 +147,7 @@
155 * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html 147 * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
156 * - https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins 148 * - https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
157 */ 149 */
158#if __fh_has_builtin (__builtin_mul_overflow_p) 150#if __has_builtin (__builtin_mul_overflow_p)
159#define __bmo(x, y) (x != 0 && __builtin_mul_overflow_p(x, y, (__typeof__ ((x) + (y))) 0)) 151#define __bmo(x, y) (x != 0 && __builtin_mul_overflow_p(x, y, (__typeof__ ((x) + (y))) 0))
160#else /* !__builtin_mul_overflow_p */ 152#else /* !__builtin_mul_overflow_p */
161#define __bmo(x, y) (x != 0 && (x * y) / x != y) 153#define __bmo(x, y) (x != 0 && (x * y) / x != y)