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 | // |
| 9 | // Defines macros used within libuwind project. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | |
| 14 | #ifndef LIBUNWIND_CONFIG_H |
| 15 | #define LIBUNWIND_CONFIG_H |
| 16 | |
| 17 | #include <assert.h> |
| 18 | #include <stdio.h> |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame^] | 19 | #include <stdlib.h> |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 20 | |
| 21 | // Define static_assert() unless already defined by compiler. |
| 22 | #ifndef __has_feature |
| 23 | #define __has_feature(__x) 0 |
| 24 | #endif |
| 25 | #if !(__has_feature(cxx_static_assert)) && !defined(static_assert) |
| 26 | #define static_assert(__b, __m) \ |
| 27 | extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ] \ |
| 28 | __attribute__( ( unused ) ); |
| 29 | #endif |
| 30 | |
| 31 | // Platform specific configuration defines. |
| 32 | #ifdef __APPLE__ |
| 33 | #include <Availability.h> |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 34 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 35 | #define _LIBUNWIND_BUILD_SJLJ_APIS defined(__arm__) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 36 | |
| 37 | #if defined(FOR_DYLD) |
| 38 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 39 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0 |
| 40 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 41 | #else |
| 42 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 43 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 44 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 45 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 46 | #else |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 47 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 48 | #define _LIBUNWIND_BUILD_SJLJ_APIS 0 |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 49 | |
Saleem Abdulrasool | 3a3a5ea | 2016-04-20 20:54:51 +0000 | [diff] [blame] | 50 | #if defined(__ARM_DWARF_EH__) || !defined(__arm__) |
| 51 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 |
| 52 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 53 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 |
| 54 | #else |
| 55 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 |
| 56 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0 |
| 57 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 58 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 61 | // FIXME: these macros are not correct for COFF targets |
| 62 | #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) |
| 63 | #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) |
| 64 | |
Saleem Abdulrasool | 1d0f931 | 2016-04-20 22:18:50 +0000 | [diff] [blame] | 65 | #if defined(__i386__) || defined(__x86_64__) |
| 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__) || \ |
| 72 | (!defined(__APPLE__) && defined(__arm__)) || \ |
| 73 | (defined(__arm64__) || defined(__aarch64__)) || \ |
| 74 | (defined(__APPLE__) && defined(__mips__)) |
| 75 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS 1 |
| 76 | #else |
| 77 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS 0 |
| 78 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 79 | |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame^] | 80 | #define _LIBUNWIND_ABORT(msg) \ |
| 81 | do { \ |
| 82 | fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__, \ |
| 83 | __LINE__, msg); \ |
| 84 | fflush(stderr); \ |
| 85 | abort(); \ |
| 86 | } while (0) |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 87 | #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__) |
| 88 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 89 | // Macros that define away in non-Debug builds |
| 90 | #ifdef NDEBUG |
| 91 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) |
| 92 | #define _LIBUNWIND_TRACE_API(msg, ...) |
| 93 | #define _LIBUNWIND_TRACING_UNWINDING 0 |
| 94 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) |
| 95 | #define _LIBUNWIND_LOG_NON_ZERO(x) x |
| 96 | #else |
| 97 | #ifdef __cplusplus |
| 98 | extern "C" { |
| 99 | #endif |
| 100 | extern bool logAPIs(); |
| 101 | extern bool logUnwinding(); |
| 102 | #ifdef __cplusplus |
| 103 | } |
| 104 | #endif |
| 105 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) |
| 106 | #define _LIBUNWIND_LOG_NON_ZERO(x) \ |
| 107 | do { \ |
| 108 | int _err = x; \ |
| 109 | if ( _err != 0 ) \ |
| 110 | _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \ |
| 111 | } while (0) |
| 112 | #define _LIBUNWIND_TRACE_API(msg, ...) \ |
| 113 | do { \ |
| 114 | if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 115 | } while(0) |
| 116 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ |
| 117 | do { \ |
| 118 | if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 119 | } while(0) |
| 120 | #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() |
| 121 | #endif |
| 122 | |
| 123 | |
| 124 | #endif // LIBUNWIND_CONFIG_H |