Home | History | Annotate | Download | only in Unwind
      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 libuwind project.
     10 //
     11 //===----------------------------------------------------------------------===//
     12 
     13 
     14 #ifndef LIBUNWIND_CONFIG_H
     15 #define LIBUNWIND_CONFIG_H
     16 
     17 #ifndef NDEBUG
     18 #include <stdio.h> // for logging
     19 #endif
     20 
     21 #include <assert.h>
     22 #include <stdio.h>
     23 #include <stdlib.h>
     24 
     25 // Define static_assert() unless already defined by compiler.
     26 #ifndef __has_feature
     27   #define __has_feature(__x) 0
     28 #endif
     29 #if !(__has_feature(cxx_static_assert)) && !defined(static_assert)
     30 // TODO(ajwong): This caused some compile failures on gcc.
     31 //  #define static_assert(__b, __m) \
     32 //      extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ]  \
     33 //                                                  __attribute__( ( unused ) );
     34 #endif
     35 
     36 // Platform specific configuration defines.
     37 #if __APPLE__
     38   #include <Availability.h>
     39   #ifdef __cplusplus
     40     extern "C" {
     41   #endif
     42     void __assert_rtn(const char *, const char *, int, const char *)
     43                                                       __attribute__((noreturn));
     44   #ifdef __cplusplus
     45     }
     46   #endif
     47 
     48   #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__)
     49   #define _LIBUNWIND_BUILD_SJLJ_APIS      (__arm__)
     50   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
     51   #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
     52   #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
     53   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
     54   #define _LIBUNWIND_ABORT(msg) __assert_rtn(__func__, __FILE__, __LINE__, msg)
     55 
     56   #if FOR_DYLD
     57     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND   1
     58     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND     0
     59     #define _LIBUNWIND_SUPPORT_DWARF_INDEX      0
     60     #define _LIBUNWIND_IS_BAREMETAL             0
     61   #else
     62     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND   1
     63     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND     1
     64     #define _LIBUNWIND_SUPPORT_DWARF_INDEX      0
     65     #define _LIBUNWIND_IS_BAREMETAL             0
     66   #endif
     67 
     68 #else
     69   static inline void assert_rtn(const char* func, const char* file, int line, const char* msg)  __attribute__ ((noreturn));
     70   static inline void assert_rtn(const char* func, const char* file, int line, const char* msg) {
     71     fprintf(stderr, "libunwind: %s %s:%d - %s\n",  func, file, line, msg);
     72     assert(false);
     73     abort();
     74   }
     75   #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__ || __arm__ || __mips__)
     76   #define _LIBUNWIND_BUILD_SJLJ_APIS      0
     77   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
     78   #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
     79   #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
     80   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
     81   #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg)
     82 
     83   #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND   0
     84   #define _LIBUNWIND_SUPPORT_DWARF_UNWIND     defined(__mips__)
     85   #define _LIBUNWIND_SUPPORT_DWARF_INDEX      0
     86   #define _LIBUNWIND_IS_BAREMETAL             0
     87 #endif
     88 
     89 
     90 // Macros that define away in non-Debug builds
     91 #ifdef NDEBUG
     92   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
     93   #define _LIBUNWIND_TRACE_API(msg, ...)
     94   #define _LIBUNWIND_TRACING_UNWINDING 0
     95   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
     96   #define _LIBUNWIND_LOG_NON_ZERO(x) x
     97 #else
     98   #ifdef __cplusplus
     99     extern "C" {
    100   #endif
    101     extern  bool logAPIs();
    102     extern  bool logUnwinding();
    103   #ifdef __cplusplus
    104     }
    105   #endif
    106   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
    107   #define _LIBUNWIND_LOG_NON_ZERO(x) \
    108             do { \
    109               int _err = x; \
    110               if ( _err != 0 ) \
    111                 _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
    112              } while (0)
    113   #define _LIBUNWIND_TRACE_API(msg, ...) \
    114             do { \
    115               if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
    116             } while(0)
    117   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
    118             do { \
    119               if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
    120             } while(0)
    121   #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
    122 #endif
    123 
    124 
    125 #endif // LIBUNWIND_CONFIG_H
    126