From f46714c2f9eb13c12c8218f1b7c045182041fdc9 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 26 Oct 2022 00:30:00 +0200 Subject: add initial clang support Co-Authored-By: jvoisin --- include/fortify-headers.h | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'include/fortify-headers.h') 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 @@ /* * Copyright (C) 2015-2016 Dimitris Papastamos + * Copyright (C) 2022 q66 * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -16,14 +17,38 @@ #ifndef _FORTIFY_HEADERS_H #define _FORTIFY_HEADERS_H +#ifdef __clang__ + +#if _FORTIFY_SOURCE > 2 && defined __has_attribute && __has_attribute(pass_dynamic_object_size) +#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n))) +#else +/* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ +#define _FORTIFY_POSN(n) const __attribute__((pass_object_size__(n))) +#endif + +/* we can't use extern inline with overloads without making them external */ +#define _FORTIFY_INLINE static __inline__ \ + __attribute__((__always_inline__,__artificial__,__overloadable__)) + +#else /* !__clang__ */ + +#define _FORTIFY_POSN(n) +#define _FORTIFY_INLINE extern __inline__ \ + __attribute__((__always_inline__,__gnu_inline__,__artificial__)) + +#endif /* __clang__ */ + +#define _FORTIFY_POS0 _FORTIFY_POSN(0) +#define _FORTIFY_POS1 _FORTIFY_POSN(1) +#define _FORTIFY_POS2 _FORTIFY_POSN(2) + #define _FORTIFY_STR(s) #s #define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn) -#define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \ - extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__)) +#define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn) +#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE -/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */ -#if _FORTIFY_SOURCE > 2 && defined __has_builtin && __has_builtin (__builtin_dynamic_object_size) +#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) -- cgit v1.3