blob: ef6f41c2c967a386399e8271f4bac8113dbfbfba [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//
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>
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__
33 #include <Availability.h>
Saleem Abdulrasool675df582015-04-24 19:39:17 +000034
Saleem Abdulrasool675df582015-04-24 19:39:17 +000035 #define _LIBUNWIND_BUILD_SJLJ_APIS defined(__arm__)
Saleem Abdulrasool675df582015-04-24 19:39:17 +000036
37 #if defined(FOR_DYLD)
38 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
39 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
40 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
41 #else
42 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
43 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
44 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
45 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000046#else
Saleem Abdulrasool675df582015-04-24 19:39:17 +000047
Saleem Abdulrasool675df582015-04-24 19:39:17 +000048 #define _LIBUNWIND_BUILD_SJLJ_APIS 0
Saleem Abdulrasool675df582015-04-24 19:39:17 +000049
Saleem Abdulrasool3a3a5ea2016-04-20 20:54:51 +000050 #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
51 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
52 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
53 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
54 #else
55 #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
56 #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
57 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
58 #endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000059#endif
60
Saleem Abdulrasool91596d32016-04-22 17:11:05 +000061// FIXME: these macros are not correct for COFF targets
62#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
63#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
64
Saleem Abdulrasool1d0f9312016-04-20 22:18:50 +000065#if defined(__i386__) || defined(__x86_64__)
66#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__) || \
72 (!defined(__APPLE__) && defined(__arm__)) || \
73 (defined(__arm64__) || defined(__aarch64__)) || \
74 (defined(__APPLE__) && defined(__mips__))
75#define _LIBUNWIND_BUILD_ZERO_COST_APIS 1
76#else
77#define _LIBUNWIND_BUILD_ZERO_COST_APIS 0
78#endif
Saleem Abdulrasool675df582015-04-24 19:39:17 +000079
Saleem Abdulrasool64fe3932016-04-24 21:00:59 +000080#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)
Saleem Abdulrasool91596d32016-04-22 17:11:05 +000087#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
88
Saleem Abdulrasool675df582015-04-24 19:39:17 +000089// 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
124#endif // LIBUNWIND_CONFIG_H