]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libunwind/src/config.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / 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 libunwind 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 <stdint.h>
20 #include <stdlib.h>
21
22 // Define static_assert() unless already defined by compiler.
23 #ifndef __has_feature
24   #define __has_feature(__x) 0
25 #endif
26 #if !(__has_feature(cxx_static_assert)) && !defined(static_assert)
27   #define static_assert(__b, __m) \
28       extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ]  \
29                                                   __attribute__( ( unused ) );
30 #endif
31
32 // Platform specific configuration defines.
33 #ifdef __APPLE__
34   #if defined(FOR_DYLD)
35     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND
36   #else
37     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND
38     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   1
39   #endif
40 #elif defined(_WIN32)
41   #ifdef __SEH__
42     #define _LIBUNWIND_SUPPORT_SEH_UNWIND 1
43   #else
44     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
45   #endif
46 #else
47   #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
48     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
49     #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
50   #endif
51 #endif
52
53 #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
54   #define _LIBUNWIND_EXPORT
55   #define _LIBUNWIND_HIDDEN
56 #else
57   #if !defined(__ELF__) && !defined(__MACH__)
58     #define _LIBUNWIND_EXPORT __declspec(dllexport)
59     #define _LIBUNWIND_HIDDEN
60   #else
61     #define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
62     #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
63   #endif
64 #endif
65
66 #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__)
67 #define _LIBUNWIND_BUILD_SJLJ_APIS
68 #endif
69
70 #if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)
71 #define _LIBUNWIND_SUPPORT_FRAME_APIS
72 #endif
73
74 #if defined(__i386__) || defined(__x86_64__) ||                                \
75     defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) ||        \
76     (!defined(__APPLE__) && defined(__arm__)) ||                               \
77     (defined(__arm64__) || defined(__aarch64__)) ||                            \
78     defined(__mips__) ||                                                       \
79     defined(__riscv)
80 #if !defined(_LIBUNWIND_BUILD_SJLJ_APIS)
81 #define _LIBUNWIND_BUILD_ZERO_COST_APIS
82 #endif
83 #endif
84
85 #if defined(__powerpc64__) && defined(_ARCH_PWR8)
86 #define PPC64_HAS_VMX
87 #endif
88
89 #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)
90 #define _LIBUNWIND_ABORT(msg)                                                  \
91   do {                                                                         \
92     abort();                                                                   \
93   } while (0)
94 #else
95 #define _LIBUNWIND_ABORT(msg)                                                  \
96   do {                                                                         \
97     fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__,          \
98             __LINE__, msg);                                                    \
99     fflush(stderr);                                                            \
100     abort();                                                                   \
101   } while (0)
102 #endif
103
104 #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)
105 #define _LIBUNWIND_LOG0(msg)
106 #define _LIBUNWIND_LOG(msg, ...)
107 #else
108 #define _LIBUNWIND_LOG0(msg)                                               \
109   fprintf(stderr, "libunwind: " msg "\n")
110 #define _LIBUNWIND_LOG(msg, ...)                                               \
111   fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
112 #endif
113
114 #if defined(NDEBUG)
115   #define _LIBUNWIND_LOG_IF_FALSE(x) x
116 #else
117   #define _LIBUNWIND_LOG_IF_FALSE(x)                                           \
118     do {                                                                       \
119       bool _ret = x;                                                           \
120       if (!_ret)                                                               \
121         _LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__);                   \
122     } while (0)
123 #endif
124
125 // Macros that define away in non-Debug builds
126 #ifdef NDEBUG
127   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
128   #define _LIBUNWIND_TRACE_API(msg, ...)
129   #define _LIBUNWIND_TRACING_UNWINDING (0)
130   #define _LIBUNWIND_TRACING_DWARF (0)
131   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
132   #define _LIBUNWIND_TRACE_DWARF(...)
133 #else
134   #ifdef __cplusplus
135     extern "C" {
136   #endif
137     extern  bool logAPIs();
138     extern  bool logUnwinding();
139     extern  bool logDWARF();
140   #ifdef __cplusplus
141     }
142   #endif
143   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
144   #define _LIBUNWIND_TRACE_API(msg, ...)                                       \
145     do {                                                                       \
146       if (logAPIs())                                                           \
147         _LIBUNWIND_LOG(msg, __VA_ARGS__);                                      \
148     } while (0)
149   #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
150   #define _LIBUNWIND_TRACING_DWARF logDWARF()
151   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)                                 \
152     do {                                                                       \
153       if (logUnwinding())                                                      \
154         _LIBUNWIND_LOG(msg, __VA_ARGS__);                                      \
155     } while (0)
156   #define _LIBUNWIND_TRACE_DWARF(...)                                          \
157     do {                                                                       \
158       if (logDWARF())                                                          \
159         fprintf(stderr, __VA_ARGS__);                                          \
160     } while (0)
161 #endif
162
163 #ifdef __cplusplus
164 // Used to fit UnwindCursor and Registers_xxx types against unw_context_t /
165 // unw_cursor_t sized memory blocks.
166 #if defined(_LIBUNWIND_IS_NATIVE_ONLY)
167 # define COMP_OP ==
168 #else
169 # define COMP_OP <=
170 #endif
171 template <typename _Type, typename _Mem>
172 struct check_fit {
173   template <typename T>
174   struct blk_count {
175     static const size_t count =
176       (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
177   };
178   static const bool does_fit =
179     (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);
180 };
181 #undef COMP_OP
182 #endif // __cplusplus
183
184 #endif // LIBUNWIND_CONFIG_H