libunwind: update to upstream snapshot r272680
[freebsd.git] / contrib / llvm / projects / libunwind / src / config.h
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 #include <stdlib.h>
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   #if defined(FOR_DYLD)
34     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
35     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   0
36     #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
37   #else
38     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
39     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   1
40     #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
41   #endif
42 #else
43   #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
44     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
45     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
46     #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
47   #else
48     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
49     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
50     #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
51   #endif
52 #endif
53
54 // FIXME: these macros are not correct for COFF targets
55 #define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
56 #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
57
58 #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__)
59 #define _LIBUNWIND_BUILD_SJLJ_APIS 1
60 #else
61 #define _LIBUNWIND_BUILD_SJLJ_APIS 0
62 #endif
63
64 #if defined(__i386__) || defined(__x86_64__)
65 #define _LIBUNWIND_SUPPORT_FRAME_APIS 1
66 #else
67 #define _LIBUNWIND_SUPPORT_FRAME_APIS 0
68 #endif
69
70 #if defined(__i386__) || defined(__x86_64__) ||                                \
71     (!defined(__APPLE__) && defined(__arm__)) ||                               \
72     (defined(__arm64__) || defined(__aarch64__)) ||                            \
73     (defined(__APPLE__) && defined(__mips__)) ||                               \
74     defined(__riscv__)
75 #define _LIBUNWIND_BUILD_ZERO_COST_APIS 1
76 #else
77 #define _LIBUNWIND_BUILD_ZERO_COST_APIS 0
78 #endif
79
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)
87 #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
88
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 #ifdef __cplusplus
124 // Used to fit UnwindCursor and Registers_xxx types against unw_context_t /
125 // unw_cursor_t sized memory blocks.
126 #if defined(_LIBUNWIND_IS_NATIVE_ONLY)
127 # define COMP_OP ==
128 #else
129 # define COMP_OP <
130 #endif
131 template <typename _Type, typename _Mem>
132 struct check_fit {
133   template <typename T>
134   struct blk_count {
135     static const size_t count =
136       (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
137   };
138   static const bool does_fit =
139     (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);
140 };
141 #undef COMP_OP
142 #endif // __cplusplus
143
144 #endif // LIBUNWIND_CONFIG_H