Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 1 | //===----------------------------- config.h -------------------------------===// |
| 2 | // |
Chandler Carruth | b81a942 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // 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 Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 6 | // |
| 7 | // |
Ed Maste | 17473fd | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 8 | // Defines macros used within libunwind project. |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 9 | // |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | |
| 13 | #ifndef LIBUNWIND_CONFIG_H |
| 14 | #define LIBUNWIND_CONFIG_H |
| 15 | |
| 16 | #include <assert.h> |
| 17 | #include <stdio.h> |
Asiri Rathnayake | 122a0f8 | 2016-10-13 14:32:24 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame] | 19 | #include <stdlib.h> |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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__ |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 33 | #if defined(FOR_DYLD) |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 34 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 35 | #else |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 36 | #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 37 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 38 | #endif |
Martin Storsjo | cfd3988 | 2017-10-11 20:06:18 +0000 | [diff] [blame] | 39 | #elif defined(_WIN32) |
Charles Davis | 1f89d78 | 2018-08-30 21:29:00 +0000 | [diff] [blame] | 40 | #ifdef __SEH__ |
| 41 | #define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 |
| 42 | #else |
| 43 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 44 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 45 | #else |
Saleem Abdulrasool | 3a3a5ea | 2016-04-20 20:54:51 +0000 | [diff] [blame] | 46 | #if defined(__ARM_DWARF_EH__) || !defined(__arm__) |
Saleem Abdulrasool | 3a3a5ea | 2016-04-20 20:54:51 +0000 | [diff] [blame] | 47 | #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 |
| 48 | #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1 |
Saleem Abdulrasool | 3a3a5ea | 2016-04-20 20:54:51 +0000 | [diff] [blame] | 49 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Nico Weber | 41f982e | 2017-06-27 18:37:06 +0000 | [diff] [blame] | 52 | #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) |
| 53 | #define _LIBUNWIND_EXPORT |
| 54 | #define _LIBUNWIND_HIDDEN |
| 55 | #else |
Martin Storsjo | de94023 | 2017-11-29 08:21:12 +0000 | [diff] [blame] | 56 | #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 Weber | 41f982e | 2017-06-27 18:37:06 +0000 | [diff] [blame] | 63 | #endif |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 64 | |
Saleem Abdulrasool | 7b1a88c | 2016-04-26 01:11:29 +0000 | [diff] [blame] | 65 | #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 66 | #define _LIBUNWIND_BUILD_SJLJ_APIS |
Saleem Abdulrasool | 7b1a88c | 2016-04-26 01:11:29 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
Martin Storsjo | dc25db1 | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 69 | #if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 70 | #define _LIBUNWIND_SUPPORT_FRAME_APIS |
Saleem Abdulrasool | 1d0f931 | 2016-04-20 22:18:50 +0000 | [diff] [blame] | 71 | #endif |
Saleem Abdulrasool | 237becc | 2016-04-20 22:18:47 +0000 | [diff] [blame] | 72 | |
Saleem Abdulrasool | 20c1a03 | 2016-04-20 20:54:55 +0000 | [diff] [blame] | 73 | #if defined(__i386__) || defined(__x86_64__) || \ |
Martin Storsjo | dc25db1 | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 74 | defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) || \ |
Saleem Abdulrasool | 20c1a03 | 2016-04-20 20:54:55 +0000 | [diff] [blame] | 75 | (!defined(__APPLE__) && defined(__arm__)) || \ |
| 76 | (defined(__arm64__) || defined(__aarch64__)) || \ |
John Baldwin | 375a366 | 2017-12-12 21:43:36 +0000 | [diff] [blame] | 77 | defined(__mips__) |
Martin Storsjo | 86ab239 | 2018-01-26 06:50:07 +0000 | [diff] [blame] | 78 | #if !defined(_LIBUNWIND_BUILD_SJLJ_APIS) |
Ranjeet Singh | 7d67413 | 2017-03-31 15:28:06 +0000 | [diff] [blame] | 79 | #define _LIBUNWIND_BUILD_ZERO_COST_APIS |
Saleem Abdulrasool | 20c1a03 | 2016-04-20 20:54:55 +0000 | [diff] [blame] | 80 | #endif |
Martin Storsjo | 86ab239 | 2018-01-26 06:50:07 +0000 | [diff] [blame] | 81 | #endif |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 82 | |
Martin Storsjo | 2b4c5e0 | 2018-01-16 20:54:10 +0000 | [diff] [blame] | 83 | #if defined(__powerpc64__) && defined(_ARCH_PWR8) |
| 84 | #define PPC64_HAS_VMX |
| 85 | #endif |
| 86 | |
Ranjeet Singh | 29750f4 | 2017-02-24 16:38:05 +0000 | [diff] [blame] | 87 | #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL) |
| 88 | #define _LIBUNWIND_ABORT(msg) \ |
| 89 | do { \ |
| 90 | abort(); \ |
| 91 | } while (0) |
| 92 | #else |
Saleem Abdulrasool | 64fe393 | 2016-04-24 21:00:59 +0000 | [diff] [blame] | 93 | #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 Singh | 29750f4 | 2017-02-24 16:38:05 +0000 | [diff] [blame] | 100 | #endif |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 101 | |
Ranjeet Singh | 29750f4 | 2017-02-24 16:38:05 +0000 | [diff] [blame] | 102 | #if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL) |
whitequark | 642836d | 2017-12-25 13:27:56 +0000 | [diff] [blame] | 103 | #define _LIBUNWIND_LOG0(msg) |
Ranjeet Singh | 29750f4 | 2017-02-24 16:38:05 +0000 | [diff] [blame] | 104 | #define _LIBUNWIND_LOG(msg, ...) |
| 105 | #else |
whitequark | 642836d | 2017-12-25 13:27:56 +0000 | [diff] [blame] | 106 | #define _LIBUNWIND_LOG0(msg) \ |
| 107 | fprintf(stderr, "libunwind: " msg "\n") |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 108 | #define _LIBUNWIND_LOG(msg, ...) \ |
Saleem Abdulrasool | 42129c3 | 2017-01-27 02:26:52 +0000 | [diff] [blame] | 109 | fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__) |
Ranjeet Singh | 29750f4 | 2017-02-24 16:38:05 +0000 | [diff] [blame] | 110 | #endif |
Saleem Abdulrasool | 91596d3 | 2016-04-22 17:11:05 +0000 | [diff] [blame] | 111 | |
Martin Storsjo | 12339e4 | 2017-10-23 19:29:36 +0000 | [diff] [blame] | 112 | #if defined(NDEBUG) |
| 113 | #define _LIBUNWIND_LOG_IF_FALSE(x) x |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 114 | #else |
Martin Storsjo | 12339e4 | 2017-10-23 19:29:36 +0000 | [diff] [blame] | 115 | #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 Rathnayake | 9feea20 | 2016-09-28 10:57:15 +0000 | [diff] [blame] | 121 | #endif |
| 122 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 123 | // Macros that define away in non-Debug builds |
| 124 | #ifdef NDEBUG |
| 125 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) |
| 126 | #define _LIBUNWIND_TRACE_API(msg, ...) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 127 | #define _LIBUNWIND_TRACING_UNWINDING (0) |
Saleem Abdulrasool | 11ea06f | 2017-01-25 02:27:45 +0000 | [diff] [blame] | 128 | #define _LIBUNWIND_TRACING_DWARF (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 129 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) |
Saleem Abdulrasool | 11ea06f | 2017-01-25 02:27:45 +0000 | [diff] [blame] | 130 | #define _LIBUNWIND_TRACE_DWARF(...) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 131 | #else |
| 132 | #ifdef __cplusplus |
| 133 | extern "C" { |
| 134 | #endif |
Alex Lorenz | 469bacd | 2017-08-31 15:51:23 +0000 | [diff] [blame] | 135 | extern bool logAPIs(); |
| 136 | extern bool logUnwinding(); |
| 137 | extern bool logDWARF(); |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 138 | #ifdef __cplusplus |
| 139 | } |
| 140 | #endif |
| 141 | #define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__) |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 142 | #define _LIBUNWIND_TRACE_API(msg, ...) \ |
| 143 | do { \ |
| 144 | if (logAPIs()) \ |
| 145 | _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 146 | } while (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 147 | #define _LIBUNWIND_TRACING_UNWINDING logUnwinding() |
Saleem Abdulrasool | 11ea06f | 2017-01-25 02:27:45 +0000 | [diff] [blame] | 148 | #define _LIBUNWIND_TRACING_DWARF logDWARF() |
Saleem Abdulrasool | 24e592c | 2017-01-21 16:22:53 +0000 | [diff] [blame] | 149 | #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \ |
| 150 | do { \ |
| 151 | if (logUnwinding()) \ |
| 152 | _LIBUNWIND_LOG(msg, __VA_ARGS__); \ |
| 153 | } while (0) |
Saleem Abdulrasool | 11ea06f | 2017-01-25 02:27:45 +0000 | [diff] [blame] | 154 | #define _LIBUNWIND_TRACE_DWARF(...) \ |
| 155 | do { \ |
| 156 | if (logDWARF()) \ |
| 157 | fprintf(stderr, __VA_ARGS__); \ |
| 158 | } while (0) |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 159 | #endif |
| 160 | |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 161 | #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 Storsjo | 89702f6 | 2018-01-02 22:11:22 +0000 | [diff] [blame] | 167 | # define COMP_OP <= |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 168 | #endif |
| 169 | template <typename _Type, typename _Mem> |
| 170 | struct check_fit { |
| 171 | template <typename T> |
| 172 | struct blk_count { |
Asiri Rathnayake | be69e8b | 2016-05-26 21:56:04 +0000 | [diff] [blame] | 173 | static const size_t count = |
Asiri Rathnayake | d2d1ea9 | 2016-05-25 12:36:34 +0000 | [diff] [blame] | 174 | (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 Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 181 | |
| 182 | #endif // LIBUNWIND_CONFIG_H |