Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -29,6 +29,19 @@ elseif (LIBUNWIND_HAS_GCC_S_LIB) list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) endif () + if (MINGW) + # Mingw64 requires quite a few "C" runtime libraries in order for basic + # programs to link successfully with -nodefaultlibs. + if (LIBUNWIND_USE_COMPILER_RT) + set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY}) + else () + set(MINGW_RUNTIME gcc_s gcc) + endif() + set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32 + shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME} + moldname mingwex msvcrt) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES}) + endif() if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") endif () Index: include/unwind.h =================================================================== --- include/unwind.h +++ include/unwind.h @@ -122,7 +122,7 @@ _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 Index: src/AddressSpace.hpp =================================================================== --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -18,7 +18,7 @@ #include #include -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) #include #endif @@ -68,7 +68,7 @@ /// 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 @@ -290,7 +290,7 @@ Dl_info dlinfo; if (!dladdr(addr, &dlinfo)) return false; -#if __LP64__ +#if defined(__LP64__) || defined(_WIN64) const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase; #else const struct mach_header *mh = (const struct mach_header *)dlinfo.dli_fbase; @@ -327,7 +327,9 @@ // independent ELF header traversal is not provided by on some // systems (e.g., FreeBSD). On these systems the data structures are // just called Elf_XXX. Define ElfW() locally. +#ifndef _WIN32 #include +#endif #if !defined(ElfW) #define ElfW(type) Elf_##type #endif @@ -478,7 +480,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, size_t bufLen, unw_word_t *offset) { -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { Index: src/assembly.h =================================================================== --- src/assembly.h +++ 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 Index: src/config.h =================================================================== --- src/config.h +++ src/config.h @@ -37,6 +37,13 @@ #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif +#elif defined(_WIN32) + // #define _LIBUNWIND_BUILD_SJLJ_APIS + // #define _LIBUNWIND_SUPPORT_FRAME_APIS + #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 + // #define _LIBUNWIND_SUPPORT_DWARF_UNWIND + // #define _LIBUNWIND_SUPPORT_DWARF_INDEX + #define bzero(s,n) memset(s,0,n) #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 @@ -44,9 +51,13 @@ #endif #endif -// FIXME: these macros are not correct for COFF targets +#ifdef _WIN32 +#define _LIBUNWIND_EXPORT +#define _LIBUNWIND_HIDDEN +#else #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