diff --git a/mdbx.h b/mdbx.h index 09143488..267b94c0 100644 --- a/mdbx.h +++ b/mdbx.h @@ -148,8 +148,8 @@ typedef pthread_t mdbx_tid_t; #else #define __dll_export #endif -#elif defined(__GNUC__) || __has_attribute(visibility) -#define __dll_export __attribute__((visibility("default"))) +#elif defined(__GNUC__) || __has_attribute(__visibility__) +#define __dll_export __attribute__((__visibility__("default"))) #else #define __dll_export #endif diff --git a/src/bits.h b/src/bits.h index e0be895b..6163f5ad 100644 --- a/src/bits.h +++ b/src/bits.h @@ -863,17 +863,9 @@ extern MDBX_debug_func *mdbx_debug_logger; extern txnid_t mdbx_debug_edge; void mdbx_debug_log(int type, const char *function, int line, const char *fmt, - ...) -#if defined(__GNUC__) || __has_attribute(format) - __attribute__((format(printf, 4, 5))) -#endif - ; + ...) __printf_args(4, 5); -void mdbx_panic(const char *fmt, ...) -#if defined(__GNUC__) || __has_attribute(format) - __attribute__((format(printf, 1, 2))) -#endif - ; +void mdbx_panic(const char *fmt, ...) __printf_args(1, 2); #if MDBX_DEBUG diff --git a/src/defs.h b/src/defs.h index 8827f95c..622f1c13 100644 --- a/src/defs.h +++ b/src/defs.h @@ -104,8 +104,8 @@ /*----------------------------------------------------------------------------*/ #ifndef __always_inline -# if defined(__GNUC__) || __has_attribute(always_inline) -# define __always_inline __inline __attribute__((always_inline)) +# if defined(__GNUC__) || __has_attribute(__always_inline__) +# define __always_inline __inline __attribute__((__always_inline__)) # elif defined(_MSC_VER) # define __always_inline __forceinline # else @@ -114,8 +114,8 @@ #endif /* __always_inline */ #ifndef __noinline -# if defined(__GNUC__) || __has_attribute(noinline) -# define __noinline __attribute__((noinline)) +# if defined(__GNUC__) || __has_attribute(__noinline__) +# define __noinline __attribute__((__noinline__)) # elif defined(_MSC_VER) # define __noinline __declspec(noinline) # elif defined(__SUNPRO_C) || defined(__sun) || defined(sun) @@ -126,16 +126,16 @@ #endif /* __noinline */ #ifndef __must_check_result -# if defined(__GNUC__) || __has_attribute(warn_unused_result) -# define __must_check_result __attribute__((warn_unused_result)) +# if defined(__GNUC__) || __has_attribute(__warn_unused_result__) +# define __must_check_result __attribute__((__warn_unused_result__)) # else # define __must_check_result # endif #endif /* __must_check_result */ #ifndef __deprecated -# if defined(__GNUC__) || __has_attribute(deprecated) -# define __deprecated __attribute__((deprecated)) +# if defined(__GNUC__) || __has_attribute(__deprecated__) +# define __deprecated __attribute__((__deprecated__)) # elif defined(_MSC_VER) # define __deprecated __declspec(deprecated) # else @@ -163,8 +163,8 @@ #endif /* __noop */ #ifndef __fallthrough -# if __GNUC_PREREQ(7, 0) || __has_attribute(fallthrough) -# define __fallthrough __attribute__((fallthrough)) +# if __GNUC_PREREQ(7, 0) || __has_attribute(__fallthrough__) +# define __fallthrough __attribute__((__fallthrough__)) # else # define __fallthrough __noop() # endif @@ -189,8 +189,8 @@ #endif /* __prefetch */ #ifndef __noreturn -# if defined(__GNUC__) || __has_attribute(noreturn) -# define __noreturn __attribute__((noreturn)) +# if defined(__GNUC__) || __has_attribute(__noreturn__) +# define __noreturn __attribute__((__noreturn__)) # elif defined(_MSC_VER) # define __noreturn __declspec(noreturn) # else @@ -199,8 +199,14 @@ #endif /* __noreturn */ #ifndef __nothrow -# if defined(__GNUC__) || __has_attribute(nothrow) -# define __nothrow __attribute__((nothrow)) +# if defined(__cplusplus) +# if __cplusplus < 201703L +# define __nothrow throw() +# else +# define __nothrow noexcept(true) +# endif /* __cplusplus */ +# elif defined(__GNUC__) || __has_attribute(__nothrow__) +# define __nothrow __attribute__((__nothrow__)) # elif defined(_MSC_VER) && defined(__cplusplus) # define __nothrow __declspec(nothrow) # else @@ -214,8 +220,8 @@ * Such a function can be subject to common subexpression elimination * and loop optimization just as an arithmetic operator would be. * These functions should be declared with the attribute pure. */ -# if defined(__GNUC__) || __has_attribute(pure) -# define __pure_function __attribute__((pure)) +# if defined(__GNUC__) || __has_attribute(__pure__) +# define __pure_function __attribute__((__pure__)) # else # define __pure_function # endif @@ -231,27 +237,27 @@ * data pointed to must not be declared const. Likewise, a function * that calls a non-const function usually must not be const. * It does not make sense for a const function to return void. */ -# if defined(__GNUC__) || __has_attribute(const) -# define __const_function __attribute__((const)) +# if defined(__GNUC__) || __has_attribute(__const__) +# define __const_function __attribute__((__const__)) # else # define __const_function # endif #endif /* __const_function */ -#ifndef __dll_hidden -# if defined(__GNUC__) || __has_attribute(visibility) -# define __dll_hidden __attribute__((visibility("hidden"))) +#ifndef __hidden +# if defined(__GNUC__) || __has_attribute(__visibility__) +# define __hidden __attribute__((__visibility__("hidden"))) # else -# define __dll_hidden +# define __hidden # endif -#endif /* __dll_hidden */ +#endif /* __hidden */ #ifndef __optimize # if defined(__OPTIMIZE__) -# if defined(__clang__) && !__has_attribute(optimize) +# if defined(__clang__) && !__has_attribute(__optimize__) # define __optimize(ops) -# elif defined(__GNUC__) || __has_attribute(optimize) -# define __optimize(ops) __attribute__((optimize(ops))) +# elif defined(__GNUC__) || __has_attribute(__optimize__) +# define __optimize(ops) __attribute__((__optimize__(ops))) # else # define __optimize(ops) # endif @@ -263,12 +269,13 @@ #ifndef __hot # if defined(__OPTIMIZE__) # if defined(__e2k__) -# define __hot __attribute__((hot)) __optimize(3) -# elif defined(__clang__) && !__has_attribute(hot) +# define __hot __attribute__((__hot__)) __optimize(3) +# elif defined(__clang__) && !__has_attribute(__hot_) \ + && __has_attribute(__section__) && (defined(__linux__) || defined(__gnu_linux__)) /* just put frequently used functions in separate section */ -# define __hot __attribute__((section("text.hot"))) __optimize("O3") -# elif defined(__GNUC__) || __has_attribute(hot) -# define __hot __attribute__((hot)) __optimize("O3") +# define __hot __attribute__((__section__("text.hot"))) __optimize("O3") +# elif defined(__GNUC__) || __has_attribute(__hot__) +# define __hot __attribute__((__hot__)) __optimize("O3") # else # define __hot __optimize("O3") # endif @@ -280,12 +287,13 @@ #ifndef __cold # if defined(__OPTIMIZE__) # if defined(__e2k__) -# define __cold __attribute__((cold)) __optimize(1) -# elif defined(__clang__) && !__has_attribute(cold) +# define __cold __attribute__((__cold__)) __optimize(1) +# elif defined(__clang__) && !__has_attribute(cold) \ + && __has_attribute(__section__) && (defined(__linux__) || defined(__gnu_linux__)) /* just put infrequently used functions in separate section */ -# define __cold __attribute__((section("text.unlikely"))) __optimize("Os") +# define __cold __attribute__((__section__("text.unlikely"))) __optimize("Os") # elif defined(__GNUC__) || __has_attribute(cold) -# define __cold __attribute__((cold)) __optimize("Os") +# define __cold __attribute__((__cold__)) __optimize("Os") # else # define __cold __optimize("Os") # endif @@ -295,8 +303,8 @@ #endif /* __cold */ #ifndef __flatten -# if defined(__OPTIMIZE__) && (defined(__GNUC__) || __has_attribute(flatten)) -# define __flatten __attribute__((flatten)) +# if defined(__OPTIMIZE__) && (defined(__GNUC__) || __has_attribute(__flatten__)) +# define __flatten __attribute__((__flatten__)) # else # define __flatten # endif @@ -338,9 +346,9 @@ typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); # define mdbx_func_ "" #endif -#if defined(__GNUC__) || __has_attribute(format) +#if defined(__GNUC__) || __has_attribute(__format__) #define __printf_args(format_index, first_arg) \ - __attribute__((format(printf, format_index, first_arg))) + __attribute__((__format__(printf, format_index, first_arg))) #else #define __printf_args(format_index, first_arg) #endif diff --git a/src/lck-linux.c b/src/lck-linux.c index 151ba325..925941b2 100644 --- a/src/lck-linux.c +++ b/src/lck-linux.c @@ -41,7 +41,8 @@ /* global constructor/destructor */ uint32_t mdbx_linux_kernel_version; -static __cold __attribute__((constructor)) void mdbx_global_constructor(void) { +static __cold __attribute__((__constructor__)) void +mdbx_global_constructor(void) { struct utsname buffer; if (uname(&buffer) == 0) { int i = 0; @@ -64,7 +65,8 @@ static __cold __attribute__((constructor)) void mdbx_global_constructor(void) { mdbx_rthc_global_init(); } -static __cold __attribute__((destructor)) void mdbx_global_destructor(void) { +static __cold __attribute__((__destructor__)) void +mdbx_global_destructor(void) { mdbx_rthc_global_dtor(); } diff --git a/src/lck-posix.c b/src/lck-posix.c index 37f4026e..016c3337 100644 --- a/src/lck-posix.c +++ b/src/lck-posix.c @@ -28,11 +28,13 @@ /*----------------------------------------------------------------------------*/ /* rthc */ -static __cold __attribute__((constructor)) void mdbx_global_constructor(void) { +static __cold __attribute__((__constructor__)) void +mdbx_global_constructor(void) { mdbx_rthc_global_init(); } -static __cold __attribute__((destructor)) void mdbx_global_destructor(void) { +static __cold __attribute__((__destructor__)) void +mdbx_global_destructor(void) { mdbx_rthc_global_dtor(); } diff --git a/src/lck-windows.c b/src/lck-windows.c index 9ad308a8..fa2d684c 100644 --- a/src/lck-windows.c +++ b/src/lck-windows.c @@ -102,7 +102,7 @@ static # ifdef _WIN64 const # endif - PIMAGE_TLS_CALLBACK mdbx_tls_anchor __attribute__((section(".CRT$XLB"), used)) = mdbx_dll_callback; + PIMAGE_TLS_CALLBACK mdbx_tls_anchor __attribute__((__section__(".CRT$XLB"), used)) = mdbx_dll_callback; #else # error FIXME #endif diff --git a/src/mdbx.c b/src/mdbx.c index d44b47b5..3d9aab2a 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -291,7 +291,7 @@ typedef struct rthc_entry_t { static CRITICAL_SECTION rthc_critical_section; #else int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_symbol) - __attribute__((weak)); + __attribute__((__weak__)); #ifdef __APPLE__ /* FIXME: Thread-Local Storage destructors & DSO-unloading */ int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_symbol) { @@ -13095,7 +13095,7 @@ MDBX_oom_func *__cold mdbx_env_get_oomfunc(MDBX_env *env) { #ifdef __SANITIZE_THREAD__ /* LY: avoid tsan-trap by me_txn, mm_last_pg and mt_next_pgno */ -__attribute__((no_sanitize_thread, noinline)) +__attribute__((__no_sanitize_thread__, __noinline__)) #endif int mdbx_txn_straggler(MDBX_txn *txn, int *percent) { @@ -14403,7 +14403,7 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data, //---------------------------------------------------------------------------- #ifdef __SANITIZE_ADDRESS__ -LIBMDBX_API __attribute__((weak)) const char *__asan_default_options() { +LIBMDBX_API __attribute__((__weak__)) const char *__asan_default_options() { return "symbolize=1:allow_addr2line=1:" #ifdef _DEBUG "debug=1:" diff --git a/src/osal.c b/src/osal.c index c61e4a2a..993d83b0 100644 --- a/src/osal.c +++ b/src/osal.c @@ -157,18 +157,44 @@ typedef struct _FILE_PROVIDER_EXTERNAL_INFO_V1 { /* workaround for avoid musl libc wrong prototype */ ( \ defined(__GLIBC__) || defined(__GNU_LIBRARY__)) /* Prototype should match libc runtime. ISO POSIX (2003) & LSB 1.x-3.x */ -__nothrow __noreturn void __assert_fail(const char *assertion, const char *file, - unsigned line, const char *function); +__extern_C void __assert_fail(const char *assertion, const char *file, + unsigned line, const char *function) +#ifdef __THROW + __THROW +#else + __nothrow +#endif /* __THROW */ + __noreturn; + #elif defined(__APPLE__) || defined(__MACH__) -__nothrow __noreturn void __assert_rtn(const char *function, const char *file, - int line, const char *assertion); +__extern_C void __assert_rtn(const char *function, const char *file, int line, + const char *assertion) /* __nothrow */ +#ifdef __dead2 + __dead2 +#else + __noreturn +#endif /* __dead2 */ +#ifdef __disable_tail_calls + __disable_tail_calls +#endif /* __disable_tail_calls */ + ; + #define __assert_fail(assertion, file, line, function) \ __assert_rtn(function, file, line, assertion) #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__BSD__) || defined(__NETBSD__) || defined(__bsdi__) || \ defined(__DragonFly__) -__nothrow __noreturn void __assert(const char *function, const char *file, - int line, const char *assertion); +__extern_C void __assert(const char *function, const char *file, int line, + const char *assertion) /* __nothrow */ +#ifdef __dead2 + __dead2 +#else + __noreturn +#endif /* __dead2 */ +#ifdef __disable_tail_calls + __disable_tail_calls +#endif /* __disable_tail_calls */ + ; #define __assert_fail(assertion, file, line, function) \ __assert(function, file, line, assertion) diff --git a/src/osal.h b/src/osal.h index 45d4cf39..ed31617a 100644 --- a/src/osal.h +++ b/src/osal.h @@ -65,8 +65,8 @@ #define alignas(N) _Alignas(N) #elif defined(_MSC_VER) #define alignas(N) __declspec(align(N)) -#elif __has_attribute(aligned) || defined(__GNUC__) -#define alignas(N) __attribute__((aligned(N))) +#elif __has_attribute(__aligned__) || defined(__GNUC__) +#define alignas(N) __attribute__((__aligned__(N))) #else #error "FIXME: Required _alignas() or equivalent." #endif diff --git a/src/tools/mdbx_chk.c b/src/tools/mdbx_chk.c index cde683cc..9ece913d 100644 --- a/src/tools/mdbx_chk.c +++ b/src/tools/mdbx_chk.c @@ -105,11 +105,7 @@ struct problem { struct problem *problems_list; uint64_t total_problems; -static void -#ifdef __GNUC__ - __attribute__((format(printf, 1, 2))) -#endif - print(const char *msg, ...) { +static void __printf_args(1, 2) print(const char *msg, ...) { if (!quiet) { va_list args; @@ -120,11 +116,7 @@ static void } } -static void -#ifdef __GNUC__ - __attribute__((format(printf, 1, 2))) -#endif - error(const char *msg, ...) { +static void __printf_args(1, 2) error(const char *msg, ...) { total_problems++; if (!quiet) { @@ -181,10 +173,8 @@ static walk_dbi_t *pagemap_lookup_dbi(const char *dbi_name, bool silent) { return last = dbi; } -static void -#ifdef __GNUC__ - __attribute__((format(printf, 4, 5))) -#endif +static void __printf_args(4, 5) + problem_add(const char *object, uint64_t entry_number, const char *msg, const char *extra, ...) { total_problems++; diff --git a/test/darwin/pthread_barrier.c b/test/darwin/pthread_barrier.c index 26e052ed..054aa007 100644 --- a/test/darwin/pthread_barrier.c +++ b/test/darwin/pthread_barrier.c @@ -31,8 +31,6 @@ #ifdef __APPLE__ -#define __unused __attribute__((unused)) - int pthread_barrierattr_init(pthread_barrierattr_t *attr) { memset(attr, 0, sizeof(pthread_barrierattr_t)); int m = pthread_mutexattr_init(&attr->mattr);