blob: fefb44e0a23f492069ec59fdc12df87c33b5f7b7 [file] [log] [blame]
Saleem Abdulrasool675df582015-04-24 19:39:17 +00001//===----------------------------- 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//
Ed Maste17473fd2016-08-30 13:08:21 +00009// Defines macros used within libunwind project.
Saleem Abdulrasool675df582015-04-24 19:39:17 +000010//
11//===----------------------------------------------------------------------===//
12
13
14#ifndef LIBUNWIND_CONFIG_H
15#define LIBUNWIND_CONFIG_H
16
17#include <assert.h>
18#include <stdio.h>
Asiri Rathnayake122a0f82016-10-13 14:32:24 +000019#include <stdint.h>
Saleem Abdulrasool64fe3932016-04-24 21:00:59 +000020#include <stdlib.h>
Saleem Abdulrasool675df582015-04-24 19:39:17 +000021
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__
Saleem Abdulrasool675df582015-04-24 19:39:17 +000034 #if defined(FOR_DYLD)
35 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
36 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
37 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
38 #else
39 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
40 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
41 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
42 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000043#else
Saleem Abdulrasool3a3a5ea2016-04-20 20:54:51 +000044 #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
45 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
46 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
47 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
48 #else
49 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
50 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
51 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
52 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000053#endif
54
Saleem Abdulrasool91596d32016-04-22 17:11:05 +000055// FIXME: these macros are not correct for COFF targets
56#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
57#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
58
Saleem Abdulrasool7b1a88c2016-04-26 01:11:29 +000059#if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__)
60#define _LIBUNWIND_BUILD_SJLJ_APIS 1
61#else
62#define _LIBUNWIND_BUILD_SJLJ_APIS 0
63#endif
64
Marshall Clow0f7ffb22016-11-02 16:39:55 +000065#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__)
Saleem Abdulrasool1d0f9312016-04-20 22:18:50 +000066#define _LIBUNWIND_SUPPORT_FRAME_APIS 1
67#else
68#define _LIBUNWIND_SUPPORT_FRAME_APIS 0
69#endif
Saleem Abdulrasool237becc2016-04-20 22:18:47 +000070
Saleem Abdulrasool20c1a032016-04-20 20:54:55 +000071#if defined(__i386__) || defined(__x86_64__) || \
Marshall Clow0f7ffb22016-11-02 16:39:55 +000072 defined(__ppc__) || defined(__ppc64__) || \
Saleem Abdulrasool20c1a032016-04-20 20:54:55 +000073 (!defined(__APPLE__) && defined(__arm__)) || \
74 (defined(__arm64__) || defined(__aarch64__)) || \
75 (defined(__APPLE__) && defined(__mips__))
76#define _LIBUNWIND_BUILD_ZERO_COST_APIS 1
77#else
78#define _LIBUNWIND_BUILD_ZERO_COST_APIS 0
79#endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000080
Saleem Abdulrasool64fe3932016-04-24 21:00:59 +000081#define _LIBUNWIND_ABORT(msg) \
82 do { \
83 fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__, \
84 __LINE__, msg); \
85 fflush(stderr); \
86 abort(); \
87 } while (0)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +000088
89#define _LIBUNWIND_LOG(msg, ...) \
Saleem Abdulrasoold8c14f52017-01-21 16:22:55 +000090 fprintf(stderr, "libunwind: " msg "\n", ##__VA_ARGS__)
Saleem Abdulrasool91596d32016-04-22 17:11:05 +000091
Asiri Rathnayake9feea202016-09-28 10:57:15 +000092#if defined(_LIBUNWIND_HAS_NO_THREADS)
93 // only used with pthread calls, not needed for the single-threaded builds
94 #define _LIBUNWIND_LOG_NON_ZERO(x)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +000095#else
96 #if defined(NDEBUG)
97 #define _LIBUNWIND_LOG_NON_ZERO(x) x
98 #else
99 #define _LIBUNWIND_LOG_NON_ZERO(x) \
100 do { \
101 int _err = x; \
102 if (_err != 0) \
103 _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
104 } while (0)
105 #endif
Asiri Rathnayake9feea202016-09-28 10:57:15 +0000106#endif
107
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000108// Macros that define away in non-Debug builds
109#ifdef NDEBUG
110 #define _LIBUNWIND_DEBUG_LOG(msg, ...)
111 #define _LIBUNWIND_TRACE_API(msg, ...)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000112 #define _LIBUNWIND_TRACING_UNWINDING (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000113 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000114#else
115 #ifdef __cplusplus
116 extern "C" {
117 #endif
118 extern bool logAPIs();
119 extern bool logUnwinding();
120 #ifdef __cplusplus
121 }
122 #endif
123 #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000124 #define _LIBUNWIND_TRACE_API(msg, ...) \
125 do { \
126 if (logAPIs()) \
127 _LIBUNWIND_LOG(msg, __VA_ARGS__); \
128 } while (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000129 #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000130 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
131 do { \
132 if (logUnwinding()) \
133 _LIBUNWIND_LOG(msg, __VA_ARGS__); \
134 } while (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000135#endif
136
Asiri Rathnayaked2d1ea92016-05-25 12:36:34 +0000137#ifdef __cplusplus
138// Used to fit UnwindCursor and Registers_xxx types against unw_context_t /
139// unw_cursor_t sized memory blocks.
140#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
141# define COMP_OP ==
142#else
143# define COMP_OP <
144#endif
145template <typename _Type, typename _Mem>
146struct check_fit {
147 template <typename T>
148 struct blk_count {
Asiri Rathnayakebe69e8b2016-05-26 21:56:04 +0000149 static const size_t count =
Asiri Rathnayaked2d1ea92016-05-25 12:36:34 +0000150 (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
151 };
152 static const bool does_fit =
153 (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);
154};
155#undef COMP_OP
156#endif // __cplusplus
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000157
158#endif // LIBUNWIND_CONFIG_H