Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 | // |
Ed Maste | 17473fd | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 9 | // Defines macros used within libunwind project. |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | |
| 14 | #ifndef LIBUNWIND_CONFIG_H |
| 15 | #define LIBUNWIND_CONFIG_H |
| 16 | |
| 17 | #include <assert.h> |
| 18 | #include <stdio.h> |
Asiri Rathnayake | 122a0f8 | 2016-10-13 14:32:24 +0000 | [diff] [blame] | 19 | #include <stdint.h> |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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__ |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 34 | #if defined(FOR_DYLD) |
| 35 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 36 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0 |
| 37 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 38 | #else |
| 39 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 40 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 41 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 42 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 43 | #else |
Saleem Abdulrasool | 3a3a5ea | 2016-04-20 20:54:51 +0000 | [diff] [blame] | 44 | #if defined(__ARM_DWARF_EH__) || !defined(__arm__) |
| 45 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 |
| 46 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 47 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 |
| 48 | #else |
| 49 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 |
| 50 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0 |
| 51 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 52 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 55 | // FIXME: these macros are not correct for COFF targets |
| 56 | #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) |
| 57 | #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) |
| 58 | |
Saleem Abdulrasool | 7b1a88c | 2016-04-26 01:11:29 +0000 | [diff] [blame] | 59 | #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) |
| 60 | #define _LIBUNWIND_BUILD_SJLJ_APIS 1 |
| 61 | #else |
| 62 | #define _LIBUNWIND_BUILD_SJLJ_APIS 0 |
| 63 | #endif |
| 64 | |
Marshall Clow | 0f7ffb2 | 2016-11-02 16:39:55 +0000 | [diff] [blame] | 65 | #if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) |
Saleem Abdulrasool | 1d0f931 | 2016-04-20 22:18:50 +0000 | [diff] [blame] | 66 | #define _LIBUNWIND_SUPPORT_FRAME_APIS 1 |
| 67 | #else |
| 68 | #define _LIBUNWIND_SUPPORT_FRAME_APIS 0 |
| 69 | #endif |
Saleem Abdulrasool | 237becc | 2016-04-20 22:18:47 +0000 | [diff] [blame] | 70 | |
Saleem Abdulrasool | 20c1a03 | 2016-04-20 20:54:55 +0000 | [diff] [blame] | 71 | #if defined(__i386__) || defined(__x86_64__) || \ |
Marshall Clow | 0f7ffb2 | 2016-11-02 16:39:55 +0000 | [diff] [blame] | 72 | defined(__ppc__) || defined(__ppc64__) || \ |
Saleem Abdulrasool | 20c1a03 | 2016-04-20 20:54:55 +0000 | [diff] [blame] | 73 | (!defined(__APPLE__) && defined(__arm__)) || \ |
| 74 | (defined(__arm64__) || defined(__aarch64__)) || \ |
| 75 | (defined(__APPLE__) && defined(__mips__)) |
| 76 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS 1 |
| 77 | #else |
| 78 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS 0 |
| 79 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 80 | |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame] | 81 | #define _LIBUNWIND_ABORT(msg) \ |
| 82 | do { \ |
| 83 | fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__, \ |
| 84 | __LINE__, msg); \ |
| 85 | fflush(stderr); \ |
| 86 | abort(); \ |
| 87 | } while (0) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 88 | |
| 89 | #define _LIBUNWIND_LOG(msg, ...) \ |
Saleem Abdulrasool | d8c14f5 | 2017-01-21 16:22:55 +0000 | [diff] [blame^] | 90 | fprintf(stderr, "libunwind: " msg "\n", ##__VA_ARGS__) |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 91 | |
Asiri Rathnayake | 9feea20 | 2016-09-28 10:57:15 +0000 | [diff] [blame] | 92 | #if defined(_LIBUNWIND_HAS_NO_THREADS) |
| 93 | // only used with pthread calls, not needed for the single-threaded builds |
| 94 | #define _LIBUNWIND_LOG_NON_ZERO(x) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 95 | #else |
| 96 | #if defined(NDEBUG) |
| 97 | #define _LIBUNWIND_LOG_NON_ZERO(x) x |
| 98 | #else |
| 99 | #define _LIBUNWIND_LOG_NON_ZERO(x) \ |
| 100 | do { \ |
| 101 | int _err = x; \ |
| 102 | if (_err != 0) \ |
| 103 | _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \ |
| 104 | } while (0) |
| 105 | #endif |
Asiri Rathnayake | 9feea20 | 2016-09-28 10:57:15 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 108 | // Macros that define away in non-Debug builds |
| 109 | #ifdef NDEBUG |
| 110 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) |
| 111 | #define _LIBUNWIND_TRACE_API(msg, ...) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 112 | #define _LIBUNWIND_TRACING_UNWINDING (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 113 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 114 | #else |
| 115 | #ifdef __cplusplus |
| 116 | extern "C" { |
| 117 | #endif |
| 118 | extern bool logAPIs(); |
| 119 | extern bool logUnwinding(); |
| 120 | #ifdef __cplusplus |
| 121 | } |
| 122 | #endif |
| 123 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 124 | #define _LIBUNWIND_TRACE_API(msg, ...) \ |
| 125 | do { \ |
| 126 | if (logAPIs()) \ |
| 127 | _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 128 | } while (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 129 | #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 130 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ |
| 131 | do { \ |
| 132 | if (logUnwinding()) \ |
| 133 | _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 134 | } while (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 135 | #endif |
| 136 | |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 137 | #ifdef __cplusplus |
| 138 | // Used to fit UnwindCursor and Registers_xxx types against unw_context_t / |
| 139 | // unw_cursor_t sized memory blocks. |
| 140 | #if defined(_LIBUNWIND_IS_NATIVE_ONLY) |
| 141 | # define COMP_OP == |
| 142 | #else |
| 143 | # define COMP_OP < |
| 144 | #endif |
| 145 | template <typename _Type, typename _Mem> |
| 146 | struct check_fit { |
| 147 | template <typename T> |
| 148 | struct blk_count { |
Asiri Rathnayake | be69e8b | 2016-05-26 21:56:04 +0000 | [diff] [blame] | 149 | static const size_t count = |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 150 | (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t); |
| 151 | }; |
| 152 | static const bool does_fit = |
| 153 | (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count); |
| 154 | }; |
| 155 | #undef COMP_OP |
| 156 | #endif // __cplusplus |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 157 | |
| 158 | #endif // LIBUNWIND_CONFIG_H |