From 46a001b37a0355b588ad99a3aab5593926fa31bc Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Tue, 21 Jul 2015 04:35:55 +0100 Subject: [PATCH 1/2] libunwind add support for mingw-w64 --- include/unwind.h | 2 +- src/AddressSpace.hpp | 11 +++++++---- src/UnwindLevel1-gcc-ext.c | 2 +- src/assembly.h | 2 ++ src/config.h | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/unwind.h b/include/unwind.h index f3860d9..8f54d4d 100644 --- a/include/unwind.h +++ b/include/unwind.h @@ -121,7 +121,7 @@ struct _Unwind_Exception { _Unwind_Exception *exc); uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use -#ifndef __LP64__ +#if !defined(__LP64__) && !defined(_WIN64) // The implementation of _Unwind_Exception uses an attribute mode on the // above fields which has the side effect of causing this whole struct to // round up to 32 bytes in size. To be more explicit, we add pad fields diff --git a/src/AddressSpace.hpp b/src/AddressSpace.hpp index da1b6a4..892950f 100644 --- a/src/AddressSpace.hpp +++ b/src/AddressSpace.hpp @@ -18,7 +18,7 @@ #include #include -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) #include #endif @@ -109,7 +109,7 @@ struct UnwindInfoSections { /// making local unwinds fast. class __attribute__((visibility("hidden"))) LocalAddressSpace { public: -#ifdef __LP64__ +#if defined(__LP64__) || defined(_WIN64) typedef uint64_t pint_t; typedef int64_t sint_t; #else @@ -161,7 +161,7 @@ public: }; inline uintptr_t LocalAddressSpace::getP(pint_t addr) { -#ifdef __LP64__ +#if defined(__LP64__) || defined(_WIN64) return get64(addr); #else return get32(addr); @@ -439,6 +439,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, }, &cb_data); return static_cast(found); +#elif defined(_WIN32) #else #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform." #endif @@ -462,7 +463,9 @@ inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) { inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, size_t bufLen, unw_word_t *offset) { -#ifndef _LIBUNWIND_IS_BAREMETAL +#ifdef _WIN32 +// FIXME: support DLLs on Windows. +#elif !defined(_LIBUNWIND_IS_BAREMETAL) Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { diff --git a/src/UnwindLevel1-gcc-ext.c b/src/UnwindLevel1-gcc-ext.c index 28ba092..0decf77 100644 --- a/src/UnwindLevel1-gcc-ext.c +++ b/src/UnwindLevel1-gcc-ext.c @@ -29,7 +29,7 @@ _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { #if _LIBUNWIND_ARM_EHABI - _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld\n", + _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR "\n", (void *)exception_object, (long)exception_object->unwinder_cache.reserved1); #else diff --git a/src/assembly.h b/src/assembly.h index 06b29b3..96f46e3 100644 --- a/src/assembly.h +++ b/src/assembly.h @@ -26,6 +26,8 @@ #if defined(__APPLE__) #define HIDDEN_DIRECTIVE .private_extern +#elif defined(_WIN32) +#define HIDDEN_DIRECTIVE .globl #else #define HIDDEN_DIRECTIVE .hidden #endif diff --git a/src/config.h b/src/config.h index a50222f..acc52a5 100644 --- a/src/config.h +++ b/src/config.h @@ -39,6 +39,14 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 #endif +#elif defined(_WIN32) + + #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 + // libcxx may have defined __USE_MINGW_ANSI_STDIO. + // Here we would like to get the regular versions, not the _mingw ones. + #undef __USE_MINGW_ANSI_STDIO #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 @@ -51,9 +59,14 @@ #endif #endif +#ifdef _WIN32 +#define _LIBUNWIND_EXPORT +#define _LIBUNWIND_HIDDEN +#else // FIXME: these macros are not correct for COFF targets #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) +#endif #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) #define _LIBUNWIND_BUILD_SJLJ_APIS 1 @@ -69,6 +82,7 @@ #if defined(__i386__) || defined(__x86_64__) || \ (!defined(__APPLE__) && defined(__arm__)) || \ + (defined(_WIN32)) || \ (defined(__arm64__) || defined(__aarch64__)) || \ (defined(__APPLE__) && defined(__mips__)) #define _LIBUNWIND_BUILD_ZERO_COST_APIS 1 -- 2.7.4