From bc50ed6c3de76c11b2dde92d0f28dd45941fc327 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 20 Aug 2023 19:02:03 +0200 Subject: Fix clang build - s/CLFAGS/CFLAGS/ - provide paths to local includes - sprinkle more __pass_object_size__ - remove a problematic test --- include/fortify-headers.h | 8 ++++++-- include/stdio.h | 13 +++++++------ include/stdlib.h | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/fortify-headers.h b/include/fortify-headers.h index dde19a2..18d302b 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h @@ -25,7 +25,7 @@ #ifdef __clang__ /* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */ -#define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n))) +#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n))) /* we can't use extern inline with overloads without making them external */ #define _FORTIFY_INLINE static __inline__ \ __attribute__((__always_inline__,__artificial__,__overloadable__)) @@ -38,6 +38,7 @@ #endif /* __clang__ */ +/* https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html */ #define _FORTIFY_POS0 _FORTIFY_POSN(0) #define _FORTIFY_POS1 _FORTIFY_POSN(1) #define _FORTIFY_POS2 _FORTIFY_POSN(2) @@ -47,7 +48,6 @@ #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 && __has_builtin (__builtin_dynamic_object_size) /* @@ -73,7 +73,11 @@ #endif #if __has_attribute (malloc) +#ifdef __clang__ +#define __malloc(...) __attribute__ ((malloc)) +#else #define __malloc(...) __attribute__ ((malloc, __VA_ARGS__)) +#endif /* __clang__ */ #else #define __malloc(...) #endif diff --git a/include/stdio.h b/include/stdio.h index 8cdd826..b31299b 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -36,15 +36,13 @@ extern "C" { #undef fread #undef fwrite #undef popen -#undef tmpfile #undef snprintf #undef sprintf #undef vsnprintf #undef vsprintf __access(read_only, 2) -__malloc(malloc (fclose, 1)) -_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* __m) +_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) { return __orig_fdopen(__f, __m); } @@ -60,7 +58,7 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) } __malloc(malloc (fclose, 1)) -_FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m) +_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) { return __orig_fmemopen(__b, __s, __m); } @@ -68,7 +66,7 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m) __access(read_only, 1) __access(read_only, 2) __malloc(malloc (fclose, 1)) -_FORTIFY_FN(fopen) FILE *fopen(const char* __p, const char* __m) +_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) { return __orig_fopen(__p, __m); } @@ -100,16 +98,19 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, } __malloc(malloc (pclose, 1)) -_FORTIFY_FN(popen) FILE *popen(const char* __c, const char* __t) +_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) { return __orig_popen(__c, __t); } +#ifndef __clang__ /* FIXME */ +#undef tmpfile __malloc(malloc (fclose, 1)) _FORTIFY_FN(tmpfile) FILE *tmpfile(void) { return __orig_tmpfile(); } +#endif __access(read_write, 1, 2) _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, diff --git a/include/stdlib.h b/include/stdlib.h index 6914f02..3f3c3ba 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -38,6 +38,7 @@ extern "C" { #undef malloc #undef realloc +#undef calloc __malloc(malloc (free, 1)) __alloc_size(1) -- cgit v1.3