blob: c2fff5051bc58b584696da404d3b310b04ba4ea6 [file] [log] [blame]
Saleem Abdulrasool675df582015-04-24 19:39:17 +00001//===----------------------------- config.h -------------------------------===//
2//
Chandler Carruthb81a9422019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Saleem Abdulrasool675df582015-04-24 19:39:17 +00006//
7//
Ed Maste17473fd2016-08-30 13:08:21 +00008// Defines macros used within libunwind project.
Saleem Abdulrasool675df582015-04-24 19:39:17 +00009//
10//===----------------------------------------------------------------------===//
11
12
13#ifndef LIBUNWIND_CONFIG_H
14#define LIBUNWIND_CONFIG_H
15
16#include <assert.h>
17#include <stdio.h>
Asiri Rathnayake122a0f82016-10-13 14:32:24 +000018#include <stdint.h>
Saleem Abdulrasool64fe3932016-04-24 21:00:59 +000019#include <stdlib.h>
Saleem Abdulrasool675df582015-04-24 19:39:17 +000020
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__
Saleem Abdulrasool675df582015-04-24 19:39:17 +000033 #if defined(FOR_DYLD)
Ranjeet Singh7d674132017-03-31 15:28:06 +000034 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND
Saleem Abdulrasool675df582015-04-24 19:39:17 +000035 #else
Ranjeet Singh7d674132017-03-31 15:28:06 +000036 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND
Saleem Abdulrasool675df582015-04-24 19:39:17 +000037 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
Saleem Abdulrasool675df582015-04-24 19:39:17 +000038 #endif
Martin Storsjocfd39882017-10-11 20:06:18 +000039#elif defined(_WIN32)
Charles Davis1f89d782018-08-30 21:29:00 +000040 #ifdef __SEH__
41 #define _LIBUNWIND_SUPPORT_SEH_UNWIND 1
42 #else
43 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
44 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000045#else
Saleem Abdulrasool3a3a5ea2016-04-20 20:54:51 +000046 #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
Saleem Abdulrasool3a3a5ea2016-04-20 20:54:51 +000047 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
48 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
Saleem Abdulrasool3a3a5ea2016-04-20 20:54:51 +000049 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000050#endif
51
Nico Weber41f982e2017-06-27 18:37:06 +000052#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
53 #define _LIBUNWIND_EXPORT
54 #define _LIBUNWIND_HIDDEN
55#else
Martin Storsjode940232017-11-29 08:21:12 +000056 #if !defined(__ELF__) && !defined(__MACH__)
57 #define _LIBUNWIND_EXPORT __declspec(dllexport)
58 #define _LIBUNWIND_HIDDEN
59 #else
60 #define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
61 #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
62 #endif
Nico Weber41f982e2017-06-27 18:37:06 +000063#endif
Saleem Abdulrasool91596d32016-04-22 17:11:05 +000064
Saleem Abdulrasool7b1a88c2016-04-26 01:11:29 +000065#if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__)
Ranjeet Singh7d674132017-03-31 15:28:06 +000066#define _LIBUNWIND_BUILD_SJLJ_APIS
Saleem Abdulrasool7b1a88c2016-04-26 01:11:29 +000067#endif
68
Martin Storsjodc25db12018-01-02 22:11:30 +000069#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)
Ranjeet Singh7d674132017-03-31 15:28:06 +000070#define _LIBUNWIND_SUPPORT_FRAME_APIS
Saleem Abdulrasool1d0f9312016-04-20 22:18:50 +000071#endif
Saleem Abdulrasool237becc2016-04-20 22:18:47 +000072
Saleem Abdulrasool20c1a032016-04-20 20:54:55 +000073#if defined(__i386__) || defined(__x86_64__) || \
Martin Storsjodc25db12018-01-02 22:11:30 +000074 defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) || \
Saleem Abdulrasool20c1a032016-04-20 20:54:55 +000075 (!defined(__APPLE__) && defined(__arm__)) || \
76 (defined(__arm64__) || defined(__aarch64__)) || \
John Baldwin375a3662017-12-12 21:43:36 +000077 defined(__mips__)
Martin Storsjo86ab2392018-01-26 06:50:07 +000078#if !defined(_LIBUNWIND_BUILD_SJLJ_APIS)
Ranjeet Singh7d674132017-03-31 15:28:06 +000079#define _LIBUNWIND_BUILD_ZERO_COST_APIS
Saleem Abdulrasool20c1a032016-04-20 20:54:55 +000080#endif
Martin Storsjo86ab2392018-01-26 06:50:07 +000081#endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000082
Martin Storsjo2b4c5e02018-01-16 20:54:10 +000083#if defined(__powerpc64__) && defined(_ARCH_PWR8)
84#define PPC64_HAS_VMX
85#endif
86
Ranjeet Singh29750f42017-02-24 16:38:05 +000087#if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)
88#define _LIBUNWIND_ABORT(msg) \
89 do { \
90 abort(); \
91 } while (0)
92#else
Saleem Abdulrasool64fe3932016-04-24 21:00:59 +000093#define _LIBUNWIND_ABORT(msg) \
94 do { \
95 fprintf(stderr, "libunwind: %s %s:%d - %s\n", __func__, __FILE__, \
96 __LINE__, msg); \
97 fflush(stderr); \
98 abort(); \
99 } while (0)
Ranjeet Singh29750f42017-02-24 16:38:05 +0000100#endif
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000101
Ranjeet Singh29750f42017-02-24 16:38:05 +0000102#if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)
whitequark642836d2017-12-25 13:27:56 +0000103#define _LIBUNWIND_LOG0(msg)
Ranjeet Singh29750f42017-02-24 16:38:05 +0000104#define _LIBUNWIND_LOG(msg, ...)
105#else
whitequark642836d2017-12-25 13:27:56 +0000106#define _LIBUNWIND_LOG0(msg) \
107 fprintf(stderr, "libunwind: " msg "\n")
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000108#define _LIBUNWIND_LOG(msg, ...) \
Saleem Abdulrasool42129c32017-01-27 02:26:52 +0000109 fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
Ranjeet Singh29750f42017-02-24 16:38:05 +0000110#endif
Saleem Abdulrasool91596d32016-04-22 17:11:05 +0000111
Martin Storsjo12339e42017-10-23 19:29:36 +0000112#if defined(NDEBUG)
113 #define _LIBUNWIND_LOG_IF_FALSE(x) x
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000114#else
Martin Storsjo12339e42017-10-23 19:29:36 +0000115 #define _LIBUNWIND_LOG_IF_FALSE(x) \
116 do { \
117 bool _ret = x; \
118 if (!_ret) \
119 _LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \
120 } while (0)
Asiri Rathnayake9feea202016-09-28 10:57:15 +0000121#endif
122
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000123// Macros that define away in non-Debug builds
124#ifdef NDEBUG
125 #define _LIBUNWIND_DEBUG_LOG(msg, ...)
126 #define _LIBUNWIND_TRACE_API(msg, ...)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000127 #define _LIBUNWIND_TRACING_UNWINDING (0)
Saleem Abdulrasool11ea06f2017-01-25 02:27:45 +0000128 #define _LIBUNWIND_TRACING_DWARF (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000129 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
Saleem Abdulrasool11ea06f2017-01-25 02:27:45 +0000130 #define _LIBUNWIND_TRACE_DWARF(...)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000131#else
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
Alex Lorenz469bacd2017-08-31 15:51:23 +0000135 extern bool logAPIs();
136 extern bool logUnwinding();
137 extern bool logDWARF();
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000138 #ifdef __cplusplus
139 }
140 #endif
141 #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__)
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000142 #define _LIBUNWIND_TRACE_API(msg, ...) \
143 do { \
144 if (logAPIs()) \
145 _LIBUNWIND_LOG(msg, __VA_ARGS__); \
146 } while (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000147 #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
Saleem Abdulrasool11ea06f2017-01-25 02:27:45 +0000148 #define _LIBUNWIND_TRACING_DWARF logDWARF()
Saleem Abdulrasool24e592c2017-01-21 16:22:53 +0000149 #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
150 do { \
151 if (logUnwinding()) \
152 _LIBUNWIND_LOG(msg, __VA_ARGS__); \
153 } while (0)
Saleem Abdulrasool11ea06f2017-01-25 02:27:45 +0000154 #define _LIBUNWIND_TRACE_DWARF(...) \
155 do { \
156 if (logDWARF()) \
157 fprintf(stderr, __VA_ARGS__); \
158 } while (0)
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000159#endif
160
Asiri Rathnayaked2d1ea92016-05-25 12:36:34 +0000161#ifdef __cplusplus
162// Used to fit UnwindCursor and Registers_xxx types against unw_context_t /
163// unw_cursor_t sized memory blocks.
164#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
165# define COMP_OP ==
166#else
Martin Storsjo89702f62018-01-02 22:11:22 +0000167# define COMP_OP <=
Asiri Rathnayaked2d1ea92016-05-25 12:36:34 +0000168#endif
169template <typename _Type, typename _Mem>
170struct check_fit {
171 template <typename T>
172 struct blk_count {
Asiri Rathnayakebe69e8b2016-05-26 21:56:04 +0000173 static const size_t count =
Asiri Rathnayaked2d1ea92016-05-25 12:36:34 +0000174 (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
175 };
176 static const bool does_fit =
177 (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);
178};
179#undef COMP_OP
180#endif // __cplusplus
Saleem Abdulrasool675df582015-04-24 19:39:17 +0000181
182#endif // LIBUNWIND_CONFIG_H