Saleem Abdulrasool | b1b1911 | 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> |
| 19 | |
| 20 | // Define static_assert() unless already defined by compiler. |
| 21 | #ifndef __has_feature |
| 22 | #define __has_feature(__x) 0 |
| 23 | #endif |
| 24 | #if !(__has_feature(cxx_static_assert)) && !defined(static_assert) |
| 25 | #define static_assert(__b, __m) \ |
| 26 | extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ] \ |
| 27 | __attribute__( ( unused ) ); |
| 28 | #endif |
| 29 | |
| 30 | // Platform specific configuration defines. |
| 31 | #ifdef __APPLE__ |
| 32 | #include <Availability.h> |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | void __assert_rtn(const char *, const char *, int, const char *) |
| 37 | __attribute__((noreturn)); |
| 38 | #ifdef __cplusplus |
| 39 | } |
| 40 | #endif |
| 41 | |
| 42 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS (defined(__i386__) || \ |
| 43 | defined(__x86_64__) || \ |
| 44 | defined(__arm64__)) |
| 45 | #define _LIBUNWIND_BUILD_SJLJ_APIS defined(__arm__) |
| 46 | #define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) || \ |
| 47 | defined(__x86_64__)) |
| 48 | #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) |
| 49 | #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) |
| 50 | #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__) |
| 51 | #define _LIBUNWIND_ABORT(msg) __assert_rtn(__func__, __FILE__, __LINE__, msg) |
| 52 | |
| 53 | #if defined(FOR_DYLD) |
| 54 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 55 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0 |
| 56 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 57 | #else |
| 58 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 |
| 59 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 60 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 |
| 61 | #endif |
| 62 | |
| 63 | #else |
| 64 | #include <stdlib.h> |
| 65 | |
| 66 | static inline void assert_rtn(const char* func, const char* file, int line, const char* msg) __attribute__ ((noreturn)); |
| 67 | static inline void assert_rtn(const char* func, const char* file, int line, const char* msg) { |
| 68 | fprintf(stderr, "libunwind: %s %s:%d - %s\n", func, file, line, msg); |
| 69 | assert(false); |
| 70 | abort(); |
| 71 | } |
| 72 | |
| 73 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS (defined(__i386__) || \ |
| 74 | defined(__x86_64__) || \ |
| 75 | defined(__arm__)) |
| 76 | #define _LIBUNWIND_BUILD_SJLJ_APIS 0 |
| 77 | #define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) || \ |
| 78 | defined(__x86_64__)) |
| 79 | #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) |
| 80 | #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) |
| 81 | #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__) |
| 82 | #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg) |
| 83 | |
| 84 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 |
| 85 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND !defined(__arm__) || \ |
| 86 | defined(__ARM_DWARF_EH__) |
| 87 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX _LIBUNWIND_SUPPORT_DWARF_UNWIND |
| 88 | #endif |
| 89 | |
| 90 | |
| 91 | // Macros that define away in non-Debug builds |
| 92 | #ifdef NDEBUG |
| 93 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) |
| 94 | #define _LIBUNWIND_TRACE_API(msg, ...) |
| 95 | #define _LIBUNWIND_TRACING_UNWINDING 0 |
| 96 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) |
| 97 | #define _LIBUNWIND_LOG_NON_ZERO(x) x |
| 98 | #else |
| 99 | #ifdef __cplusplus |
| 100 | extern "C" { |
| 101 | #endif |
| 102 | extern bool logAPIs(); |
| 103 | extern bool logUnwinding(); |
| 104 | #ifdef __cplusplus |
| 105 | } |
| 106 | #endif |
| 107 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) |
| 108 | #define _LIBUNWIND_LOG_NON_ZERO(x) \ |
| 109 | do { \ |
| 110 | int _err = x; \ |
| 111 | if ( _err != 0 ) \ |
| 112 | _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \ |
| 113 | } while (0) |
| 114 | #define _LIBUNWIND_TRACE_API(msg, ...) \ |
| 115 | do { \ |
| 116 | if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 117 | } while(0) |
| 118 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ |
| 119 | do { \ |
| 120 | if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 121 | } while(0) |
| 122 | #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() |
| 123 | #endif |
| 124 | |
| 125 | |
| 126 | #endif // LIBUNWIND_CONFIG_H |