diff --git a/libunwind/src/config.h b/libunwind/src/config.h --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -22,51 +22,51 @@ // Platform specific configuration defines. #ifdef __APPLE__ - #if defined(FOR_DYLD) - #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 - #else - #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 - #endif +#if defined(FOR_DYLD) +#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 +#else +#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +#endif #elif defined(_WIN32) - #ifdef __SEH__ - #define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 - #else - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 - #endif +#ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 +#else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +#endif #elif defined(_LIBUNWIND_IS_BAREMETAL) - #if !defined(_LIBUNWIND_ARM_EHABI) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 - #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 - #endif +#if !defined(_LIBUNWIND_ARM_EHABI) +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +#define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 +#endif #elif defined(__BIONIC__) && defined(_LIBUNWIND_ARM_EHABI) - // For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After - // API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster. - #define _LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX 1 +// For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After +// API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster. +#define _LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX 1 #elif defined(_AIX) // The traceback table at the end of each function is used for unwinding. #define _LIBUNWIND_SUPPORT_TBTAB_UNWIND 1 #else - // Assume an ELF system with a dl_iterate_phdr function. - #define _LIBUNWIND_USE_DL_ITERATE_PHDR 1 - #if !defined(_LIBUNWIND_ARM_EHABI) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 - #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 - #endif +// Assume an ELF system with a dl_iterate_phdr function. +#define _LIBUNWIND_USE_DL_ITERATE_PHDR 1 +#if !defined(_LIBUNWIND_ARM_EHABI) +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +#define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 +#endif #endif #if defined(_LIBUNWIND_HIDE_SYMBOLS) - // The CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility. - #define _LIBUNWIND_EXPORT - #define _LIBUNWIND_HIDDEN +// The CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility. +#define _LIBUNWIND_EXPORT +#define _LIBUNWIND_HIDDEN #else - #if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) - #define _LIBUNWIND_EXPORT __declspec(dllexport) - #define _LIBUNWIND_HIDDEN - #else - #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) - #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) - #endif +#if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX) +#define _LIBUNWIND_EXPORT __declspec(dllexport) +#define _LIBUNWIND_HIDDEN +#else +#define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) +#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) +#endif #endif #define STR(a) #a @@ -121,10 +121,32 @@ #endif #endif +#if defined(__has_builtin) +#define _LIBUNWIND_HAS_BUILTIN(x) __has_builtin(x) +#else +#define _LIBUNWIND_HAS_BUILTIN(x) 0 +#endif + +#if defined(__has_include) +#define _LIBUNWIND_HAS_INCLUDE(x) __has_include(x) +#else +#define _LIBUNWIND_HAS_INCLUDE(x) 0 +#endif + #ifndef _LIBUNWIND_REMEMBER_HEAP_ALLOC -#if defined(_LIBUNWIND_REMEMBER_STACK_ALLOC) || defined(__APPLE__) || \ - defined(__linux__) || defined(__ANDROID__) || defined(__MINGW32__) || \ - defined(_LIBUNWIND_IS_BAREMETAL) + +#if _LIBUNWIND_HAS_BUILTIN(__builtin_alloca) +#define _LIBUNWIND_REMEMBER_ALLOC(_size) __builtin_alloca(_size) +#define _LIBUNWIND_REMEMBER_FREE(_ptr) \ + do { \ + } while (0) +#elif defined(alloca) +#define _LIBUNWIND_REMEMBER_ALLOC(_size) alloca(_size) +#define _LIBUNWIND_REMEMBER_FREE(_ptr) \ + do { \ + } while (0) +#elif _LIBUNWIND_HAS_INCLUDE() +#include #define _LIBUNWIND_REMEMBER_ALLOC(_size) alloca(_size) #define _LIBUNWIND_REMEMBER_FREE(_ptr) \ do { \ @@ -173,52 +195,52 @@ #endif #if defined(NDEBUG) - #define _LIBUNWIND_LOG_IF_FALSE(x) x +#define _LIBUNWIND_LOG_IF_FALSE(x) x #else #define _LIBUNWIND_LOG_IF_FALSE(x) \ do { \ bool _ret = x; \ if (!_ret) \ _LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \ - } while (0) + } while (0) #endif // Macros that define away in non-Debug builds #ifdef NDEBUG - #define _LIBUNWIND_DEBUG_LOG(msg, ...) - #define _LIBUNWIND_TRACE_API(msg, ...) - #define _LIBUNWIND_TRACING_UNWINDING (0) - #define _LIBUNWIND_TRACING_DWARF (0) - #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) - #define _LIBUNWIND_TRACE_DWARF(...) -#else - #ifdef __cplusplus - extern "C" { - #endif +#define _LIBUNWIND_DEBUG_LOG(msg, ...) +#define _LIBUNWIND_TRACE_API(msg, ...) +#define _LIBUNWIND_TRACING_UNWINDING (0) +#define _LIBUNWIND_TRACING_DWARF (0) +#define _LIBUNWIND_TRACE_UNWINDING(msg, ...) +#define _LIBUNWIND_TRACE_DWARF(...) +#else +#ifdef __cplusplus +extern "C" { +#endif extern bool logAPIs(void); extern bool logUnwinding(void); extern bool logDWARF(void); - #ifdef __cplusplus - } - #endif +#ifdef __cplusplus +} +#endif #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) #define _LIBUNWIND_TRACE_API(msg, ...) \ do { \ if (logAPIs()) \ _LIBUNWIND_LOG(msg, __VA_ARGS__); \ - } while (0) - #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() - #define _LIBUNWIND_TRACING_DWARF logDWARF() + } while (0) +#define _LIBUNWIND_TRACING_UNWINDING logUnwinding() +#define _LIBUNWIND_TRACING_DWARF logDWARF() #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ do { \ if (logUnwinding()) \ _LIBUNWIND_LOG(msg, __VA_ARGS__); \ - } while (0) + } while (0) #define _LIBUNWIND_TRACE_DWARF(...) \ do { \ if (logDWARF()) \ fprintf(stderr, __VA_ARGS__); \ - } while (0) + } while (0) #endif #ifdef __cplusplus @@ -234,10 +256,10 @@ template struct blk_count { static const size_t count = - (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t); + (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t); }; static const bool does_fit = - (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count); + (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count); }; #undef COMP_OP #endif // __cplusplus