From 249492e08adbf034976770ab3b021ba093a2ab18 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 18 Mar 2023 14:01:02 +0100 Subject: Make use of __builtin_dynamic_object_size GCC and Clang provide __builtin_dynamic_object_size (see documentation: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html), so we should make use of it when its available. --- include/fortify-headers.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/fortify-headers.h') diff --git a/include/fortify-headers.h b/include/fortify-headers.h index 4de5bef..a37cd4a 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h @@ -21,4 +21,12 @@ #define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \ extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) + +/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ +#if _FORTIFY_SOURCE > 2 && defined __has_builtin && __has_builtin (__builtin_dynamic_object_size) +#define __bos(ptr, type) __builtin_dynamic_object_size (ptr, type) +#else +#define __bos(ptr, type) __builtin_object_size (ptr, type) +#endif + #endif -- cgit v1.3