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));
assert_rtn(const char * func,const char * file,int line,const char * msg)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                                            defined(__aarch64__))
77   #define _LIBUNWIND_BUILD_SJLJ_APIS      0
78   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
79                                            defined(__x86_64__))
80   #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
81   #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
82   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
83   #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg)
84 
85   #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
86   #define _LIBUNWIND_SUPPORT_DWARF_UNWIND !defined(__arm__) || \
87                                           defined(__ARM_DWARF_EH__)
88   #define _LIBUNWIND_SUPPORT_DWARF_INDEX _LIBUNWIND_SUPPORT_DWARF_UNWIND
89 #endif
90 
91 
92 // Macros that define away in non-Debug builds
93 #ifdef NDEBUG
94   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
95   #define _LIBUNWIND_TRACE_API(msg, ...)
96   #define _LIBUNWIND_TRACING_UNWINDING 0
97   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
98   #define _LIBUNWIND_LOG_NON_ZERO(x) x
99 #else
100   #ifdef __cplusplus
101     extern "C" {
102   #endif
103     extern  bool logAPIs();
104     extern  bool logUnwinding();
105   #ifdef __cplusplus
106     }
107   #endif
108   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
109   #define _LIBUNWIND_LOG_NON_ZERO(x) \
110             do { \
111               int _err = x; \
112               if ( _err != 0 ) \
113                 _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
114              } while (0)
115   #define _LIBUNWIND_TRACE_API(msg, ...) \
116             do { \
117               if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
118             } while(0)
119   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
120             do { \
121               if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
122             } while(0)
123   #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
124 #endif
125 
126 
127 #endif // LIBUNWIND_CONFIG_H
128