diff options
Diffstat (limited to 'include/fortify-headers.h')
| -rw-r--r-- | include/fortify-headers.h | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index a37cd4a..b116290 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> | 2 | * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> |
| 3 | * Copyright (C) 2022 q66 <q66@chimera-linux.org> | ||
| 3 | * | 4 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted. | 6 | * purpose with or without fee is hereby granted. |
| @@ -16,14 +17,38 @@ | |||
| 16 | #ifndef _FORTIFY_HEADERS_H | 17 | #ifndef _FORTIFY_HEADERS_H |
| 17 | #define _FORTIFY_HEADERS_H | 18 | #define _FORTIFY_HEADERS_H |
| 18 | 19 | ||
| 20 | #ifdef __clang__ | ||
| 21 | |||
| 22 | #if _FORTIFY_SOURCE > 2 && defined __has_attribute && __has_attribute(pass_dynamic_object_size) | ||
| 23 | #define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n))) | ||
| 24 | #else | ||
| 25 | /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ | ||
| 26 | #define _FORTIFY_POSN(n) const __attribute__((pass_object_size__(n))) | ||
| 27 | #endif | ||
| 28 | |||
| 29 | /* we can't use extern inline with overloads without making them external */ | ||
| 30 | #define _FORTIFY_INLINE static __inline__ \ | ||
| 31 | __attribute__((__always_inline__,__artificial__,__overloadable__)) | ||
| 32 | |||
| 33 | #else /* !__clang__ */ | ||
| 34 | |||
| 35 | #define _FORTIFY_POSN(n) | ||
| 36 | #define _FORTIFY_INLINE extern __inline__ \ | ||
| 37 | __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 38 | |||
| 39 | #endif /* __clang__ */ | ||
| 40 | |||
| 41 | #define _FORTIFY_POS0 _FORTIFY_POSN(0) | ||
| 42 | #define _FORTIFY_POS1 _FORTIFY_POSN(1) | ||
| 43 | #define _FORTIFY_POS2 _FORTIFY_POSN(2) | ||
| 44 | |||
| 19 | #define _FORTIFY_STR(s) #s | 45 | #define _FORTIFY_STR(s) #s |
| 20 | #define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn) | 46 | #define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn) |
| 21 | #define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \ | 47 | #define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn) |
| 22 | extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | 48 | #define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE |
| 23 | 49 | ||
| 24 | 50 | ||
| 25 | /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ | 51 | #if _FORTIFY_SOURCE > 2 && defined __has_builtin && __has_builtin (__builtin_dynamic_object_size) |
| 26 | #if _FORTIFY_SOURCE > 2 && defined __has_builtin && __has_builtin (__builtin_dynamic_object_size) | ||
| 27 | #define __bos(ptr, type) __builtin_dynamic_object_size (ptr, type) | 52 | #define __bos(ptr, type) __builtin_dynamic_object_size (ptr, type) |
| 28 | #else | 53 | #else |
| 29 | #define __bos(ptr, type) __builtin_object_size (ptr, type) | 54 | #define __bos(ptr, type) __builtin_object_size (ptr, type) |
