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