From 9e40646cf3a7d0817b2298f915399a128fcb4d27 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 3 Feb 2021 21:01:24 +0100 Subject: Fix noinline for older compiler versions (e.g. Visual Studio 6.0) Visual Studio 6.0 does not support __declspec(noinline) and throw error. Add checks for compilers which support noinline to prevent compile errors. --- src/dlfcn.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dlfcn.c b/src/dlfcn.c index c4f410d..86f24df 100644 --- a/src/dlfcn.c +++ b/src/dlfcn.c @@ -61,6 +61,16 @@ typedef ULONG ULONG_PTR; #endif #include "dlfcn.h" +#if defined( _MSC_VER ) && _MSC_VER >= 1300 +/* https://docs.microsoft.com/en-us/cpp/cpp/noinline */ +#define DLFCN_NOINLINE __declspec( noinline ) +#elif defined( __GNUC__ ) && ( ( __GNUC__ > 3 ) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) ) +/* https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html */ +#define DLFCN_NOINLINE __attribute__(( noinline )) +#else +#define DLFCN_NOINLINE +#endif + /* Note: * MSDN says these functions are not thread-safe. We make no efforts to have * any kind of thread safety. @@ -418,7 +428,7 @@ int dlclose( void *handle ) return (int) ret; } -__declspec(noinline) /* Needed for _ReturnAddress() */ +DLFCN_NOINLINE /* Needed for _ReturnAddress() */ DLFCN_EXPORT void *dlsym( void *handle, const char *name ) { -- cgit v1.2.3-55-g6feb