Path: blob/main/contrib/llvm-project/libunwind/src/config.h
35148 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//7// Defines macros used within libunwind project.8//9//===----------------------------------------------------------------------===//101112#ifndef LIBUNWIND_CONFIG_H13#define LIBUNWIND_CONFIG_H1415#include <assert.h>16#include <stdio.h>17#include <stdint.h>18#include <stdlib.h>1920#include <__libunwind_config.h>2122// Platform specific configuration defines.23#ifdef __APPLE__24#if defined(FOR_DYLD)25#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 126#else27#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 128#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 129#endif30#elif defined(_WIN32)31#ifdef __SEH__32#define _LIBUNWIND_SUPPORT_SEH_UNWIND 133#else34#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 135#endif36#elif defined(_LIBUNWIND_IS_BAREMETAL)37#if !defined(_LIBUNWIND_ARM_EHABI)38#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 139#define _LIBUNWIND_SUPPORT_DWARF_INDEX 140#endif41#elif defined(__BIONIC__) && defined(_LIBUNWIND_ARM_EHABI)42// For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After43// API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster.44#define _LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX 145#elif defined(_AIX)46// The traceback table at the end of each function is used for unwinding.47#define _LIBUNWIND_SUPPORT_TBTAB_UNWIND 148#elif defined(__HAIKU__)49#if defined(_LIBUNWIND_USE_HAIKU_BSD_LIB)50#define _LIBUNWIND_USE_DL_ITERATE_PHDR 151#endif52#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 153#define _LIBUNWIND_SUPPORT_DWARF_INDEX 154#else55// Assume an ELF system with a dl_iterate_phdr function.56#define _LIBUNWIND_USE_DL_ITERATE_PHDR 157#if !defined(_LIBUNWIND_ARM_EHABI)58#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 159#define _LIBUNWIND_SUPPORT_DWARF_INDEX 160#endif61#endif6263#if defined(_LIBUNWIND_HIDE_SYMBOLS)64// The CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility.65#define _LIBUNWIND_EXPORT66#define _LIBUNWIND_HIDDEN67#else68#if !defined(__ELF__) && !defined(__MACH__) && !defined(_AIX)69#define _LIBUNWIND_EXPORT __declspec(dllexport)70#define _LIBUNWIND_HIDDEN71#else72#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))73#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))74#endif75#endif7677#define STR(a) #a78#define XSTR(a) STR(a)79#define SYMBOL_NAME(name) XSTR(__USER_LABEL_PREFIX__) #name8081#if defined(__APPLE__)82#if defined(_LIBUNWIND_HIDE_SYMBOLS)83#define _LIBUNWIND_ALIAS_VISIBILITY(name) __asm__(".private_extern " name);84#else85#define _LIBUNWIND_ALIAS_VISIBILITY(name)86#endif87#define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \88__asm__(".globl " SYMBOL_NAME(aliasname)); \89__asm__(SYMBOL_NAME(aliasname) " = " SYMBOL_NAME(name)); \90_LIBUNWIND_ALIAS_VISIBILITY(SYMBOL_NAME(aliasname))91#elif defined(__ELF__) || defined(_AIX) || defined(__wasm__)92#define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \93extern "C" _LIBUNWIND_EXPORT __typeof(name) aliasname \94__attribute__((weak, alias(#name)));95#elif defined(_WIN32)96#if defined(__MINGW32__)97#define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \98extern "C" _LIBUNWIND_EXPORT __typeof(name) aliasname \99__attribute__((alias(#name)));100#else101#define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \102__pragma(comment(linker, "/alternatename:" SYMBOL_NAME(aliasname) "=" \103SYMBOL_NAME(name))) \104extern "C" _LIBUNWIND_EXPORT __typeof(name) aliasname;105#endif106#else107#error Unsupported target108#endif109110// Apple/armv7k defaults to DWARF/Compact unwinding, but its libunwind also111// needs to include the SJLJ APIs.112#if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__)113#define _LIBUNWIND_BUILD_SJLJ_APIS114#endif115116#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || \117(!defined(__APPLE__) && defined(__arm__)) || defined(__aarch64__) || \118defined(__mips__) || defined(__riscv) || defined(__hexagon__) || \119defined(__sparc__) || defined(__s390x__) || defined(__loongarch__)120#if !defined(_LIBUNWIND_BUILD_SJLJ_APIS)121#define _LIBUNWIND_BUILD_ZERO_COST_APIS122#endif123#endif124125#ifndef _LIBUNWIND_REMEMBER_HEAP_ALLOC126#if defined(_LIBUNWIND_REMEMBER_STACK_ALLOC) || defined(__APPLE__) || \127defined(__linux__) || defined(__ANDROID__) || defined(__MINGW32__) || \128defined(_LIBUNWIND_IS_BAREMETAL)129#define _LIBUNWIND_REMEMBER_ALLOC(_size) __builtin_alloca(_size)130#define _LIBUNWIND_REMEMBER_FREE(_ptr) \131do { \132} while (0)133#elif defined(_WIN32)134#define _LIBUNWIND_REMEMBER_ALLOC(_size) _malloca(_size)135#define _LIBUNWIND_REMEMBER_FREE(_ptr) _freea(_ptr)136#define _LIBUNWIND_REMEMBER_CLEANUP_NEEDED137#else138#define _LIBUNWIND_REMEMBER_ALLOC(_size) malloc(_size)139#define _LIBUNWIND_REMEMBER_FREE(_ptr) free(_ptr)140#define _LIBUNWIND_REMEMBER_CLEANUP_NEEDED141#endif142#else /* _LIBUNWIND_REMEMBER_HEAP_ALLOC */143#define _LIBUNWIND_REMEMBER_ALLOC(_size) malloc(_size)144#define _LIBUNWIND_REMEMBER_FREE(_ptr) free(_ptr)145#define _LIBUNWIND_REMEMBER_CLEANUP_NEEDED146#endif147148#if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)149#define _LIBUNWIND_ABORT(msg) \150do { \151abort(); \152} while (0)153#else154#define _LIBUNWIND_ABORT(msg) \155do { \156fprintf(stderr, "libunwind: %s - %s\n", __func__, msg); \157fflush(stderr); \158abort(); \159} while (0)160#endif161162#if defined(NDEBUG) && defined(_LIBUNWIND_IS_BAREMETAL)163#define _LIBUNWIND_LOG0(msg)164#define _LIBUNWIND_LOG(msg, ...)165#else166#define _LIBUNWIND_LOG0(msg) do { \167fprintf(stderr, "libunwind: " msg "\n"); \168fflush(stderr); \169} while (0)170#define _LIBUNWIND_LOG(msg, ...) do { \171fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__); \172fflush(stderr); \173} while (0)174#endif175176#if defined(NDEBUG)177#define _LIBUNWIND_LOG_IF_FALSE(x) x178#else179#define _LIBUNWIND_LOG_IF_FALSE(x) \180do { \181bool _ret = x; \182if (!_ret) \183_LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \184} while (0)185#endif186187// Macros that define away in non-Debug builds188#ifdef NDEBUG189#define _LIBUNWIND_DEBUG_LOG(msg, ...)190#define _LIBUNWIND_TRACE_API(msg, ...)191#define _LIBUNWIND_TRACING_UNWINDING (0)192#define _LIBUNWIND_TRACING_DWARF (0)193#define _LIBUNWIND_TRACE_UNWINDING(msg, ...)194#define _LIBUNWIND_TRACE_DWARF(...)195#else196#ifdef __cplusplus197extern "C" {198#endif199extern bool logAPIs(void);200extern bool logUnwinding(void);201extern bool logDWARF(void);202#ifdef __cplusplus203}204#endif205#define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__)206#define _LIBUNWIND_TRACE_API(msg, ...) \207do { \208if (logAPIs()) \209_LIBUNWIND_LOG(msg, __VA_ARGS__); \210} while (0)211#define _LIBUNWIND_TRACING_UNWINDING logUnwinding()212#define _LIBUNWIND_TRACING_DWARF logDWARF()213#define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \214do { \215if (logUnwinding()) \216_LIBUNWIND_LOG(msg, __VA_ARGS__); \217} while (0)218#define _LIBUNWIND_TRACE_DWARF(...) \219do { \220if (logDWARF()) \221fprintf(stderr, __VA_ARGS__); \222} while (0)223#endif224225#ifdef __cplusplus226// Used to fit UnwindCursor and Registers_xxx types against unw_context_t /227// unw_cursor_t sized memory blocks.228#if defined(_LIBUNWIND_IS_NATIVE_ONLY)229# define COMP_OP ==230#else231# define COMP_OP <=232#endif233template <typename _Type, typename _Mem>234struct check_fit {235template <typename T>236struct blk_count {237static const size_t count =238(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);239};240static const bool does_fit =241(blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);242};243#undef COMP_OP244#endif // __cplusplus245246#endif // LIBUNWIND_CONFIG_H247248249