1 //===----------------------------- config.h -------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 // 9 // Defines macros used within libunwind project. 10 // 11 //===----------------------------------------------------------------------===// 12 13 14 #ifndef LIBUNWIND_CONFIG_H 15 #define LIBUNWIND_CONFIG_H 16 17 #include <assert.h> 18 #include <stdio.h> 19 #include <stdint.h> 20 #include <stdlib.h> 21 22 // Define static_assert() unless already defined by compiler. 23 #ifndef __has_feature 24 #define __has_feature(__x) 0 25 #endif 26 #if !(__has_feature(cxx_static_assert)) && !defined(static_assert) 27 #define static_assert(__b, __m) \ 28 extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ] \ 29 __attribute__( ( unused ) ); 30 #endif 31 32 // Platform specific configuration defines. 33 #ifdef __APPLE__ 34 #if defined(FOR_DYLD) 35 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 36 #else 37 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 38 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 39 #endif 40 #elif defined(_WIN32) 41 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 42 #else 43 #if defined(__ARM_DWARF_EH__) || !defined(__arm__) 44 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 45 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 46 #endif 47 #endif 48 49 #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) 50 #define _LIBUNWIND_EXPORT 51 #define _LIBUNWIND_HIDDEN 52 #else 53 #if !defined(__ELF__) && !defined(__MACH__) 54 #define _LIBUNWIND_EXPORT __declspec(dllexport) 55 #define _LIBUNWIND_HIDDEN 56 #else 57 #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) 58 #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) 59 #endif 60 #endif 61 62 #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) 63 #define _LIBUNWIND_BUILD_SJLJ_APIS 64 #endif 65 66 #if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) 67 #define _LIBUNWIND_SUPPORT_FRAME_APIS 68 #endif 69 70 #if defined(__i386__) || defined(__x86_64__) || \ 71 defined(__ppc__) || defined(__ppc64__) || \ 72 (!defined(__APPLE__) && defined(__arm__)) || \ 73 (defined(__arm64__) || defined(__aarch64__)) || \ 74 defined(__mips__) 75 #define _LIBUNWIND_BUILD_ZERO_COST_APIS 76 #endif 77 78 #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL) 79 #define _LIBUNWIND_ABORT(msg) \ 80 do { \ 81 abort(); \ 82 } while (0) 83 #else 84 #define _LIBUNWIND_ABORT(msg) \ 85 do { \ 86 fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__, \ 87 __LINE__, msg); \ 88 fflush(stderr); \ 89 abort(); \ 90 } while (0) 91 #endif 92 93 #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL) 94 #define _LIBUNWIND_LOG(msg, ...) 95 #else 96 #define _LIBUNWIND_LOG(msg, ...) \ 97 fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__) 98 #endif 99 100 #if defined(NDEBUG) 101 #define _LIBUNWIND_LOG_IF_FALSE(x) x 102 #else 103 #define _LIBUNWIND_LOG_IF_FALSE(x) \ 104 do { \ 105 bool _ret = x; \ 106 if (!_ret) \ 107 _LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \ 108 } while (0) 109 #endif 110 111 // Macros that define away in non-Debug builds 112 #ifdef NDEBUG 113 #define _LIBUNWIND_DEBUG_LOG(msg, ...) 114 #define _LIBUNWIND_TRACE_API(msg, ...) 115 #define _LIBUNWIND_TRACING_UNWINDING (0) 116 #define _LIBUNWIND_TRACING_DWARF (0) 117 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) 118 #define _LIBUNWIND_TRACE_DWARF(...) 119 #else 120 #ifdef __cplusplus 121 extern "C" { 122 #endif 123 extern bool logAPIs(); 124 extern bool logUnwinding(); 125 extern bool logDWARF(); 126 #ifdef __cplusplus 127 } 128 #endif 129 #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) 130 #define _LIBUNWIND_TRACE_API(msg, ...) \ 131 do { \ 132 if (logAPIs()) \ 133 _LIBUNWIND_LOG(msg, __VA_ARGS__); \ 134 } while (0) 135 #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() 136 #define _LIBUNWIND_TRACING_DWARF logDWARF() 137 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ 138 do { \ 139 if (logUnwinding()) \ 140 _LIBUNWIND_LOG(msg, __VA_ARGS__); \ 141 } while (0) 142 #define _LIBUNWIND_TRACE_DWARF(...) \ 143 do { \ 144 if (logDWARF()) \ 145 fprintf(stderr, __VA_ARGS__); \ 146 } while (0) 147 #endif 148 149 #ifdef __cplusplus 150 // Used to fit UnwindCursor and Registers_xxx types against unw_context_t / 151 // unw_cursor_t sized memory blocks. 152 #if defined(_LIBUNWIND_IS_NATIVE_ONLY) 153 # define COMP_OP == 154 #else 155 # define COMP_OP < 156 #endif 157 template <typename _Type, typename _Mem> 158 struct check_fit { 159 template <typename T> 160 struct blk_count { 161 static const size_t count = 162 (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t); 163 }; 164 static const bool does_fit = 165 (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count); 166 }; 167 #undef COMP_OP 168 #endif // __cplusplus 169 170 #endif // LIBUNWIND_CONFIG_H 171