diff options
| author | jvoisin | 2023-07-10 23:13:42 +0200 |
|---|---|---|
| committer | jvoisin | 2023-07-10 23:13:42 +0200 |
| commit | 106785b6bba515566637a028a602061fdef1e184 (patch) | |
| tree | f7ed7bf1d69b44aa034fc16edfdaf68a4f22db32 /include | |
| parent | e7c10a1b27be94a09bb03bf31b4b66233e3d1bdc (diff) | |
Clean up a bit the macro hell
Diffstat (limited to 'include')
| -rw-r--r-- | include/fortify-headers.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index 42a283f..2f81fc0 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -17,6 +17,11 @@ | |||
| 17 | #ifndef _FORTIFY_HEADERS_H | 17 | #ifndef _FORTIFY_HEADERS_H |
| 18 | #define _FORTIFY_HEADERS_H | 18 | #define _FORTIFY_HEADERS_H |
| 19 | 19 | ||
| 20 | #if !defined __has_builtin | ||
| 21 | #error a compiler with __has_builtin support is required | ||
| 22 | #endif | ||
| 23 | |||
| 24 | |||
| 20 | #ifdef __clang__ | 25 | #ifdef __clang__ |
| 21 | 26 | ||
| 22 | /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ | 27 | /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ |
| @@ -44,7 +49,7 @@ | |||
| 44 | 49 | ||
| 45 | 50 | ||
| 46 | /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ | 51 | /* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ |
| 47 | #if _FORTIFY_SOURCE > 2 && defined __has_builtin && __has_builtin (__builtin_dynamic_object_size) | 52 | #if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) |
| 48 | /* | 53 | /* |
| 49 | * See: | 54 | * See: |
| 50 | * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html | 55 | * - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html |
| @@ -54,28 +59,30 @@ | |||
| 54 | #define __bos(ptr, type) __builtin_object_size (ptr, type) | 59 | #define __bos(ptr, type) __builtin_object_size (ptr, type) |
| 55 | #endif | 60 | #endif |
| 56 | 61 | ||
| 57 | #if defined __has_attribute && __has_attribute (access) | 62 | #if defined __has_attribute |
| 63 | #if __has_attribute (access) | ||
| 58 | #define __access(...) __attribute__ ((access (__VA_ARGS__))) | 64 | #define __access(...) __attribute__ ((access (__VA_ARGS__))) |
| 59 | #else | 65 | #else |
| 60 | #define __access(...) | 66 | #define __access(...) |
| 61 | #endif | 67 | #endif |
| 62 | 68 | ||
| 63 | #if defined __has_attribute && __has_attribute (format) | 69 | #if __has_attribute (format) |
| 64 | #define __format(...) __attribute__ ((format (__VA_ARGS__))) | 70 | #define __format(...) __attribute__ ((format (__VA_ARGS__))) |
| 65 | #else | 71 | #else |
| 66 | #define __format(...) | 72 | #define __format(...) |
| 67 | #endif | 73 | #endif |
| 68 | 74 | ||
| 69 | #if defined __has_attribute && __has_attribute (malloc) | 75 | #if __has_attribute (malloc) |
| 70 | #define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) | 76 | #define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) |
| 71 | #else | 77 | #else |
| 72 | #define __malloc(...) | 78 | #define __malloc(...) |
| 73 | #endif | 79 | #endif |
| 74 | 80 | ||
| 81 | #endif /* __has_attribute */ | ||
| 82 | |||
| 75 | 83 | ||
| 76 | /* TODO(jvoisin) Figure a nice way to make use of __builtin_mul_overflow while ignoring the result. */ | 84 | /* TODO(jvoisin) Figure a nice way to make use of __builtin_mul_overflow while ignoring the result. */ |
| 77 | /* TODO(jvoisin) Make use of C23's stdckdint header: https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint */ | 85 | /* TODO(jvoisin) Make use of C23's stdckdint header: https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint */ |
| 78 | #if _FORTIFY_SOURCE > 2 && defined __has_builtin | ||
| 79 | /* | 86 | /* |
| 80 | * See: | 87 | * See: |
| 81 | * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html | 88 | * - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html |
| @@ -87,6 +94,4 @@ | |||
| 87 | #define __bmo(x, y) (x != 0 && (x * y) / x != y) | 94 | #define __bmo(x, y) (x != 0 && (x * y) / x != y) |
| 88 | #endif /* __builtin_mul_overflow_p */ | 95 | #endif /* __builtin_mul_overflow_p */ |
| 89 | 96 | ||
| 90 | #endif /* __has_builtin */ | ||
| 91 | |||
| 92 | #endif /* _FORTIFY_HEADERS_H */ | 97 | #endif /* _FORTIFY_HEADERS_H */ |
