summaryrefslogtreecommitdiff
path: root/include/fortify-headers.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/fortify-headers.h')
-rw-r--r--include/fortify-headers.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index d75ff43..ea2e430 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -21,7 +21,11 @@
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#if ! __has_builtin(__builtin_trap) 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)
25#define __builtin_trap abort 29#define __builtin_trap abort
26#endif 30#endif
27 31
@@ -31,7 +35,7 @@
31 35
32#ifdef __clang__ 36#ifdef __clang__
33 37
34#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size) 38#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size)
35#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n))) 39#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n)))
36#else 40#else
37#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n))) 41#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n)))
@@ -66,7 +70,7 @@
66#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE 70#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
67 71
68/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ 72/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */
69#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) 73#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size)
70/* 74/*
71 * See: 75 * See:
72 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html 76 * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
@@ -151,7 +155,7 @@
151 * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html 155 * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
152 * - https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins 156 * - https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
153 */ 157 */
154#if __has_builtin (__builtin_mul_overflow_p) 158#if __fh_has_builtin (__builtin_mul_overflow_p)
155#define __bmo(x, y) (x != 0 && __builtin_mul_overflow_p(x, y, (__typeof__ ((x) + (y))) 0)) 159#define __bmo(x, y) (x != 0 && __builtin_mul_overflow_p(x, y, (__typeof__ ((x) + (y))) 0))
156#else /* !__builtin_mul_overflow_p */ 160#else /* !__builtin_mul_overflow_p */
157#define __bmo(x, y) (x != 0 && (x * y) / x != y) 161#define __bmo(x, y) (x != 0 && (x * y) / x != y)