Supporting libunwind on Windows 10 (32bit; 64bit) for MSVC and Clang

Hello.
I was trying to compile https://github.com/llvm/llvm-project/tree/master/libunwind using:

  • MSVC
  • Clang
    I wasn’t able to configure this project for using MSVC (directly or via clang-cl):

cmake -G Ninja -DLLVM_PATH=“C:/Users/clang/llvm-project-10.0.1/llvm” -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=“C:\Users\clang\libunwind_llvm” …/libunwind
– The C compiler identification is MSVC 19.27.29109.0
– The CXX compiler identification is MSVC 19.27.29109.0
– Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.27.29109/bin/Hostx86/x86/cl.exe
– Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.27.29109/bin/Hostx86/x86/cl.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.27.29109/bin/Hostx86/x86/cl.exe
– Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.27.29109/bin/Hostx86/x86/cl.exe – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Using Release VC++ CRT: MD
– Looking for os_signpost_interval_begin
– Looking for os_signpost_interval_begin - not found
– Looking for fopen in c
– Looking for fopen in c - not found
– Looking for __gcc_personality_v0 in gcc_s
– Looking for __gcc_personality_v0 in gcc_s - not found
– Looking for __absvdi2 in gcc
– Looking for __absvdi2 in gcc - not found
– Performing Test LIBUNWIND_HAS_NODEFAULTLIBS_FLAG
– Performing Test LIBUNWIND_HAS_NODEFAULTLIBS_FLAG - Failed
– Performing Test LIBUNWIND_HAS_NOSTDINCXX_FLAG
– Performing Test LIBUNWIND_HAS_NOSTDINCXX_FLAG - Failed
– Looking for arm
– Looking for arm - not found
– Looking for USING_SJLJ_EXCEPTIONS
– Looking for USING_SJLJ_EXCEPTIONS - not found
– Looking for ARM_DWARF_EH
– Looking for ARM_DWARF_EH - not found
– Looking for dladdr in dl
– Looking for dladdr in dl - not found
– Looking for pthread_once in pthread
– Looking for pthread_once in pthread - not found
– Performing Test LIBUNWIND_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_W_FLAG
– Performing Test LIBUNWIND_SUPPORTS_W_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WALL_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WALL_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WCHAR_SUBSCRIPTS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WCHAR_SUBSCRIPTS_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WCONVERSION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WCONVERSION_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WMISMATCHED_TAGS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WMISMATCHED_TAGS_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WMISSING_BRACES_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WMISSING_BRACES_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WNEWLINE_EOF_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNEWLINE_EOF_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WNO_UNUSED_FUNCTION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNO_UNUSED_FUNCTION_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSHADOW_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSHADOW_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSHORTEN_64_TO_32_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSHORTEN_64_TO_32_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_COMPARE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_COMPARE_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_CONVERSION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_CONVERSION_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_ALIASING_EQ_2_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_ALIASING_EQ_2_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_OVERFLOW_EQ_4_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_OVERFLOW_EQ_4_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_PARAMETER_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_PARAMETER_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_VARIABLE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_VARIABLE_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WWRITE_STRINGS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WWRITE_STRINGS_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WUNDEF_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNDEF_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WNO_ERROR_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNO_ERROR_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_WX_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WX_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_PEDANTIC_FLAG
– Performing Test LIBUNWIND_SUPPORTS_PEDANTIC_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_FSTRICT_ALIASING_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FSTRICT_ALIASING_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_EHSC_FLAG
– Performing Test LIBUNWIND_SUPPORTS_EHSC_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_FNO_RTTI_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FNO_RTTI_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG - Failed
CMake Error at src/CMakeLists.txt:86 (message):
Compiler doesn’t support generation of unwind tables if exception support
is disabled. Building libunwind DSO with runtime dependency on C++ ABI
library is not supported.

– Configuring incomplete, errors occurred!
See also “C:/Users/clang/libunwind2/CMakeFiles/CMakeOutput.log”.
See also “C:/Users/clang/libunwind2/CMakeFiles/CMakeError.log”.

So I am attaching these logs.

I tried to compile using Clang.

I have configured libunwind:

cmake -G Ninja -DLLVM_PATH=“C:/Users/clang/llvm-project-10.0.1/llvm” -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=“C:\Users\clang\libunwind_llvm” -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ …/libunwind
– The C compiler identification is Clang 10.0.0 with GNU-like command-line
– The CXX compiler identification is Clang 10.0.0 with GNU-like command-line
– Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
– Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
– Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Performing Test C_SUPPORTS_WERROR_DATE_TIME
– Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
– Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
– Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
– Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
– Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
– Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
– Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
– Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG
– Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
– Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
– Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
– Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
– Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
– Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
– Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
– Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
– Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
– Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG
– Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Failed
– Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG
– Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
– Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG
– Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
– Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG
– Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
– Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP
– Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Success
– Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG
– Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Success
– Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG
– Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Success
– Looking for os_signpost_interval_begin
– Looking for os_signpost_interval_begin - not found
– Looking for fopen in c
– Looking for fopen in c - not found
– Looking for __gcc_personality_v0 in gcc_s
– Looking for __gcc_personality_v0 in gcc_s - not found
– Looking for __absvdi2 in gcc
– Looking for __absvdi2 in gcc - not found
– Performing Test LIBUNWIND_HAS_NODEFAULTLIBS_FLAG
– Performing Test LIBUNWIND_HAS_NODEFAULTLIBS_FLAG - Success
– Performing Test LIBUNWIND_HAS_COMMENT_LIB_PRAGMA
– Performing Test LIBUNWIND_HAS_COMMENT_LIB_PRAGMA - Failed
– Performing Test LIBUNWIND_HAS_NOSTDINCXX_FLAG
– Performing Test LIBUNWIND_HAS_NOSTDINCXX_FLAG - Success
– Looking for arm
– Looking for arm - not found
– Looking for USING_SJLJ_EXCEPTIONS
– Looking for USING_SJLJ_EXCEPTIONS - not found
– Looking for ARM_DWARF_EH
– Looking for ARM_DWARF_EH - not found
– Looking for dladdr in dl
– Looking for dladdr in dl - not found
– Looking for pthread_once in pthread
– Looking for pthread_once in pthread - not found
– Performing Test LIBUNWIND_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WERROR_EQ_RETURN_TYPE_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_W_FLAG
– Performing Test LIBUNWIND_SUPPORTS_W_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WALL_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WALL_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WCHAR_SUBSCRIPTS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WCHAR_SUBSCRIPTS_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WCONVERSION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WCONVERSION_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WMISMATCHED_TAGS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WMISMATCHED_TAGS_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WMISSING_BRACES_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WMISSING_BRACES_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WNEWLINE_EOF_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNEWLINE_EOF_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WNO_UNUSED_FUNCTION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNO_UNUSED_FUNCTION_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSHADOW_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSHADOW_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSHORTEN_64_TO_32_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSHORTEN_64_TO_32_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_COMPARE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_COMPARE_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_CONVERSION_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSIGN_CONVERSION_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_ALIASING_EQ_2_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_ALIASING_EQ_2_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_OVERFLOW_EQ_4_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WSTRICT_OVERFLOW_EQ_4_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_PARAMETER_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_PARAMETER_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_VARIABLE_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNUSED_VARIABLE_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WWRITE_STRINGS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WWRITE_STRINGS_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WUNDEF_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WUNDEF_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WNO_ERROR_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WNO_ERROR_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_WX_FLAG
– Performing Test LIBUNWIND_SUPPORTS_WX_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_PEDANTIC_FLAG
– Performing Test LIBUNWIND_SUPPORTS_PEDANTIC_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_FSTRICT_ALIASING_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FSTRICT_ALIASING_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_EHSC_FLAG
– Performing Test LIBUNWIND_SUPPORTS_EHSC_FLAG - Failed
– Performing Test LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_FNO_RTTI_FLAG
– Performing Test LIBUNWIND_SUPPORTS_FNO_RTTI_FLAG - Success
– Performing Test LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG
– Performing Test LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG - Success
– Configuring done
– Generating done
– Build files have been written to: C:/Users/clang/libunwind2

Then I tried to build it:

ninja -w dupbuild=warn
ninja: warning: multiple rules generate lib/unwind.lib. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]
[4/9] Building C object src/CMakeFiles/unwind_shared.dir/Unwind-sjlj.c.obj
In file included from C:/Users/clang/libunwind/src/Unwind-sjlj.c:19:
C:/Users/clang/libunwind/src/config.h:26:11: warning: keyword is hidden by macro definition [-Wkeyword-macro]
#define static_assert(__b, __m)
^
1 warning generated.
[5/9] Building C object src/CMakeFiles/unwind_shared.dir/UnwindLevel1.c.obj
In file included from C:/Users/clang/libunwind/src/UnwindLevel1.c:28:
C:/Users/clang/libunwind/src/config.h:26:11: warning: keyword is hidden by macro definition [-Wkeyword-macro]
#define static_assert(__b, __m)
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:350:1: warning: redeclaration of ‘_Unwind_RaiseException’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_RaiseException(_Unwind_Exception *exception_object) {
^
C:/Users/clang/libunwind/include\unwind.h:174:5: note: previous declaration is here
_Unwind_RaiseException(_Unwind_Exception *exception_object);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:385:1: warning: redeclaration of ‘_Unwind_Resume’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_Resume(_Unwind_Exception *exception_object) {
^
C:/Users/clang/libunwind/include\unwind.h:175:13: note: previous declaration is here
extern void _Unwind_Resume(_Unwind_Exception *exception_object);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:408:1: warning: redeclaration of ‘_Unwind_ForcedUnwind’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
^
C:/Users/clang/libunwind/include\unwind.h:277:5: note: previous declaration is here
_Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:428:1: warning: redeclaration of ‘_Unwind_GetLanguageSpecificData’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:270:5: note: previous declaration is here
_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:449:1: warning: redeclaration of ‘_Unwind_GetRegionStart’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_GetRegionStart(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:268:18: note: previous declaration is here
extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:465:1: warning: redeclaration of ‘_Unwind_DeleteException’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_DeleteException(_Unwind_Exception *exception_object) {
^
C:/Users/clang/libunwind/include\unwind.h:177:13: note: previous declaration is here
extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:475:1: warning: redeclaration of ‘_Unwind_GetGR’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_GetGR(struct _Unwind_Context *context, int index) {
^
C:/Users/clang/libunwind/include\unwind.h:221:18: note: previous declaration is here
extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:485:24: warning: redeclaration of ‘_Unwind_SetGR’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index,
^
C:/Users/clang/libunwind/include\unwind.h:222:13: note: previous declaration is here
extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:495:29: warning: redeclaration of ‘_Unwind_GetIP’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:224:18: note: previous declaration is here
extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
^
C:/Users/clang/libunwind/src/UnwindLevel1.c:507:24: warning: redeclaration of ‘_Unwind_SetIP’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
^
C:/Users/clang/libunwind/include\unwind.h:225:13: note: previous declaration is here
extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);
^
11 warnings generated.
[6/9] Building C object src/CMakeFiles/unwind_shared.dir/UnwindLevel1-gcc-ext.c.obj
In file included from C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:19:
C:/Users/clang/libunwind/src/config.h:26:11: warning: keyword is hidden by macro definition [-Wkeyword-macro]
#define static_assert(__b, __m)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:33:1: warning: redeclaration of ‘_Unwind_Resume_or_Rethrow’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
^
C:/Users/clang/libunwind/include\unwind.h:299:5: note: previous declaration is here
_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:70:1: warning: redeclaration of ‘_Unwind_GetDataRelBase’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_GetDataRelBase(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:356:18: note: previous declaration is here
extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:80:1: warning: redeclaration of ‘_Unwind_GetTextRelBase’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_GetTextRelBase(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:358:18: note: previous declaration is here
extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:89:25: warning: redeclaration of ‘_Unwind_FindEnclosingFunction’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) {
^
C:/Users/clang/libunwind/include\unwind.h:352:14: note: previous declaration is here
extern void *_Unwind_FindEnclosingFunction(void *pc);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:108:1: warning: redeclaration of ‘_Unwind_Backtrace’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
^
C:/Users/clang/libunwind/include\unwind.h:307:28: note: previous declaration is here
extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:187:31: warning: redeclaration of ‘_Unwind_Find_FDE’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT const void *_Unwind_Find_FDE(const void *pc,
^
C:/Users/clang/libunwind/include\unwind.h:344:20: note: previous declaration is here
extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:208:29: warning: redeclaration of ‘_Unwind_GetCFA’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) {
^
C:/Users/clang/libunwind/include\unwind.h:312:18: note: previous declaration is here
extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:221:29: warning: redeclaration of ‘_Unwind_GetIPInfo’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
^
C:/Users/clang/libunwind/include\unwind.h:321:18: note: previous declaration is here
extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:241:24: warning: redeclaration of ‘__register_frame’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame(const void *fde) {
^
C:/Users/clang/libunwind/include\unwind.h:331:13: note: previous declaration is here
extern void __register_frame(const void *fde);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:251:24: warning: redeclaration of ‘__deregister_frame’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __deregister_frame(const void *fde) {
^
C:/Users/clang/libunwind/include\unwind.h:332:13: note: previous declaration is here
extern void __deregister_frame(const void *fde);
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:266:24: warning: redeclaration of ‘__register_frame_info_bases’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame_info_bases(const void *fde, void *ob,
^
C:/Users/clang/libunwind/include\unwind.h:364:13: note: previous declaration is here
extern void __register_frame_info_bases(const void *fde, void *ob, void *tb,
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:277:24: warning: redeclaration of ‘__register_frame_info’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame_info(const void *fde, void *ob) {
^
C:/Users/clang/libunwind/include\unwind.h:366:13: note: previous declaration is here
extern void __register_frame_info(const void *fde, void *ob)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:284:24: warning: redeclaration of ‘__register_frame_info_table_bases’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame_info_table_bases(const void *fde,
^
C:/Users/clang/libunwind/include\unwind.h:368:13: note: previous declaration is here
extern void __register_frame_info_table_bases(const void *fde, void *ob,
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:296:24: warning: redeclaration of ‘__register_frame_info_table’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame_info_table(const void *fde, void *ob) {
^
C:/Users/clang/libunwind/include\unwind.h:371:13: note: previous declaration is here
extern void __register_frame_info_table(const void *fde, void *ob)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:303:24: warning: redeclaration of ‘__register_frame_table’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void __register_frame_table(const void *fde) {
^
C:/Users/clang/libunwind/include\unwind.h:373:13: note: previous declaration is here
extern void __register_frame_table(const void *fde)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:309:25: warning: redeclaration of ‘__deregister_frame_info’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void *__deregister_frame_info(const void *fde) {
^
C:/Users/clang/libunwind/include\unwind.h:375:14: note: previous declaration is here
extern void *__deregister_frame_info(const void *fde)
^
C:/Users/clang/libunwind/src/UnwindLevel1-gcc-ext.c:316:25: warning: redeclaration of ‘__deregister_frame_info_bases’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT void *__deregister_frame_info_bases(const void *fde) {
^
C:/Users/clang/libunwind/include\unwind.h:377:14: note: previous declaration is here
extern void *__deregister_frame_info_bases(const void *fde)
^
18 warnings generated.
[8/9] Building CXX object src/CMakeFiles/unwind_shared.dir/libunwind.cpp.obj
In file included from C:/Users/clang/libunwind/src/libunwind.cpp:22:
In file included from C:/Users/clang/libunwind/src/UnwindCursor.hpp:67:
In file included from C:/Users/clang/libunwind/src/CompactUnwinder.hpp:19:
C:/Users/clang/libunwind/include\mach-o/compact_unwind_encoding.h:45:5: warning: enumerator value is not representable in the underlying type ‘int’ [-Wmicrosoft-enum-value]
UNWIND_IS_NOT_FUNCTION_START = 0x80000000,
^
C:/Users/clang/libunwind/src/libunwind.cpp:29:36: warning: redeclaration of ‘unw_local_addr_space’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_EXPORT unw_addr_space_t unw_local_addr_space =
^
C:/Users/clang/libunwind/include\libunwind.h:125:25: note: previous declaration is here
extern unw_addr_space_t unw_local_addr_space;
^
C:/Users/clang/libunwind/src/libunwind.cpp:76:41: warning: redeclaration of ‘unw_init_local’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_init_local, unw_init_local)
^
C:/Users/clang/libunwind/include\libunwind.h:104:12: note: previous declaration is here
extern int unw_init_local(unw_cursor_t *, unw_context_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:91:38: warning: redeclaration of ‘unw_get_reg’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_get_reg, unw_get_reg)
^
C:/Users/clang/libunwind/include\libunwind.h:106:12: note: previous declaration is here
extern int unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:123:38: warning: redeclaration of ‘unw_set_reg’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_set_reg, unw_set_reg)
^
C:/Users/clang/libunwind/include\libunwind.h:108:12: note: previous declaration is here
extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:138:40: warning: redeclaration of ‘unw_get_fpreg’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_get_fpreg, unw_get_fpreg)
^
C:/Users/clang/libunwind/include\libunwind.h:107:12: note: previous declaration is here
extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:157:40: warning: redeclaration of ‘unw_set_fpreg’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_set_fpreg, unw_set_fpreg)
^
C:/Users/clang/libunwind/include\libunwind.h:109:12: note: previous declaration is here
extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:165:35: warning: redeclaration of ‘unw_step’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_step, unw_step)
^
C:/Users/clang/libunwind/include\libunwind.h:105:12: note: previous declaration is here
extern int unw_step(unw_cursor_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:178:44: warning: redeclaration of ‘unw_get_proc_info’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info)
^
C:/Users/clang/libunwind/include\libunwind.h:119:12: note: previous declaration is here
extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:187:37: warning: redeclaration of ‘unw_resume’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_resume, unw_resume)
^
C:/Users/clang/libunwind/include\libunwind.h:110:12: note: previous declaration is here
extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:200:44: warning: redeclaration of ‘unw_get_proc_name’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_name, unw_get_proc_name)
^
C:/Users/clang/libunwind/include\libunwind.h:122:12: note: previous declaration is here
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:210:39: warning: redeclaration of ‘unw_is_fpreg’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_is_fpreg, unw_is_fpreg)
^
C:/Users/clang/libunwind/include\libunwind.h:120:12: note: previous declaration is here
extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:220:38: warning: redeclaration of ‘unw_regname’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_regname, unw_regname)
^
C:/Users/clang/libunwind/include\libunwind.h:118:20: note: previous declaration is here
extern const char *unw_regname(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:229:46: warning: redeclaration of ‘unw_is_signal_frame’ should not add ‘dllexport’ attribute [-Wdll-attribute-on-redeclaration]
_LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame)
^
C:/Users/clang/libunwind/include\libunwind.h:121:12: note: previous declaration is here
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
^
C:/Users/clang/libunwind/src/libunwind.cpp:293:12: warning: ‘getenv’ is deprecated: This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
log = (getenv(“LIBUNWIND_PRINT_APIS”) != NULL);
^
C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\stdlib.h:1190:20: note: ‘getenv’ has been explicitly marked deprecated here
Check_return _CRT_INSECURE_DEPRECATE(_dupenv_s)
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:320:55: note: expanded from macro ‘_CRT_INSECURE_DEPRECATE’
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:310:47: note: expanded from macro ‘_CRT_DEPRECATE_TEXT’
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
C:/Users/clang/libunwind/src/libunwind.cpp:305:12: warning: ‘getenv’ is deprecated: This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
log = (getenv(“LIBUNWIND_PRINT_UNWINDING”) != NULL);
^
C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\stdlib.h:1190:20: note: ‘getenv’ has been explicitly marked deprecated here
Check_return _CRT_INSECURE_DEPRECATE(_dupenv_s)
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:320:55: note: expanded from macro ‘_CRT_INSECURE_DEPRECATE’
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:310:47: note: expanded from macro ‘_CRT_DEPRECATE_TEXT’
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
C:/Users/clang/libunwind/src/libunwind.cpp:317:12: warning: ‘getenv’ is deprecated: This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
log = (getenv(“LIBUNWIND_PRINT_DWARF”) != NULL);
^
C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\stdlib.h:1190:20: note: ‘getenv’ has been explicitly marked deprecated here
Check_return _CRT_INSECURE_DEPRECATE(_dupenv_s)
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:320:55: note: expanded from macro ‘_CRT_INSECURE_DEPRECATE’
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(
^
C:\Program Files\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.27.29109\include\vcruntime.h:310:47: note: expanded from macro ‘_CRT_DEPRECATE_TEXT’
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
17 warnings generated.
[9/9] Linking C shared library lib\unwind.dll
FAILED: lib/unwind.dll lib/unwind.lib
cmd.exe /C “cd . && C:\PROGRA~1\LLVM\bin\clang.exe -nostartfiles -nostdlib -Werror=date-time -Werror=unguarded-availability-new -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wdelete-non-virtual-dtor -Wstring-conversion -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -nodefaultlibs -shared -o lib\unwind.dll -Xlinker /implib:lib\unwind.lib -Xlinker /pdb:lib\unwind.pdb -Xlinker /version:1.0 src/CMakeFiles/unwind_shared.dir/libunwind.cpp.obj src/CMakeFiles/unwind_shared.dir/Unwind-EHABI.cpp.obj src/CMakeFiles/unwind_shared.dir/Unwind-seh.cpp.obj src/CMakeFiles/unwind_shared.dir/UnwindLevel1.c.obj src/CMakeFiles/unwind_shared.dir/UnwindLevel1-gcc-ext.c.obj src/CMakeFiles/unwind_shared.dir/Unwind-sjlj.c.obj src/CMakeFiles/unwind_shared.dir/UnwindRegistersRestore.S.obj src/CMakeFiles/unwind_shared.dir/UnwindRegistersSave.S.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd .”
Creating library lib\unwind.lib and object lib\unwind.exp
libunwind.cpp.obj :
error LNK2019: unresolved external symbol “public: void __thiscall libunwind::Registers_x86::jumpto(void)” (?jumpto@Registers_x86@libunwind@@QAEXXZ) referenced in function "public: virtual void __thiscall libunwind::UnwindCursor<class libunwind::LocalAddressSpace,class libunwind::Registers_x86>::jumpto(void)" (?jumpto@?$UnwindCursor@VLocalAddressSpace@libunwind@@VRegisters_x86@2@@libunwind@@UAEXXZ)
lib\unwind.dll : fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
ninja: build stopped: subcommand failed.

So there were some linking issues.
Some assistance would be much appreciated.

Microsoft’s linker has it’s version 14.27.29109.0 (VS 2019).
Clang’s version is clang version 10.0.0 (Target: i686-pc-windows-msvc)
Ninja’s version is 1.10.0.git.kitware.jobserver-1

Ivan

CMakeOutput.log (4.5 KB)

CMakeError.log (40.4 KB)

libunwind is only needed on Windows if you’re using the Itanium C++ ABI (e.g. with MinGW). What’s your end goal with building libunwind?

I had no targets on Itanium - and I do not have such hardware around.

https://go.googlesource.com/gollvm/ depends on https://github.com/ianlancetaylor/libbacktrace .
It was able to compile libbacktrace on x86_64 Linux (Intel) https://github.com/ianlancetaylor/libbacktrace/blob/5a99ff7fed66b8ea8f09c9805c138524a7035ece/README.md - and must say that Itanium related API was adopted to work on Linux.
So my issues are around searching for a replacement - I thought that LLVM’s subproject could be a modern option. Ian explained that he is not familiar with what LLVM’s sub-projects offer - but it is more modern, compared to what GNU lib offers.
So it would allow me to get read of GNU related dependencies.

Back to the linking bug: the question is in a choice for Windows native functionality (library), which would either give similar capabilities or it would make sense to re-implemented unwinding API (Windows has its own support for unwinding, according to MSDN).
So while patching the build config is a matter of the near future (just to check API compatibility and allow gollvm to compile, during the next stage) - alternative unwinding APIs could be proposed.

https://github.com/ianlancetaylor/libbacktrace/tree/5a99ff7fed66b8ea8f09c9805c138524a7035ece doesn’t have a Windows poty, so far. It would require re-designing, to use LLVM oriented approach.

Ivan

libunwind is only needed on Windows if you’re using the Itanium C++ ABI (e.g. with MinGW).

That does not explain why I saw x86_64 options, among the source code.

Hi,

I was trying to
compile https://github.com/llvm/llvm-project/tree/master/libunwind using:
* MSVC
* Clang
I wasn't able to configure this project for using MSVC (directly or via
clang-cl):

error LNK2019: unresolved external symbol "public: void __thiscall
libunwind::Registers_x86::jumpto(void)"
(?jumpto@Registers_x86@libunwind@@QAEXXZ) referenced in function "public:
virtual void __thiscall libunwind::UnwindCursor<class
libunwind::LocalAddressSpace,class libunwind::Registers_x86>::jumpto(void)"(?jumpto@?$UnwindCursor@VLocalAddressSpace@libunwind@@VRegisters_x86@2@@lib
unwind@@UAEXXZ)
lib\unwind.dll : fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see
invocation)
ninja: build stopped: subcommand failed.

Just as Shoaib said, libunwind only is useful in environments that use the Itanium C++ ABI - there's really no use for it in an MSVC context (either using MSVC or clang-cl to compile it).

The particular linker error comes from the fact that there's functions implemented in assembly, that expect the function name to be mangled the itanium way, while the object files built by the compiler expect the symbols to use the MSVC C++ name mangling, so there's an undefined reference.

// Martin

Hi,

Please keep the discussion on the list.

      Just as Shoaib said, libunwind only is useful in environments
      that use
      the Itanium C++ ABI - there's really no use for it in an MSVC
      context
      (either using MSVC or clang-cl to compile it).

      The particular linker error comes from the fact that there's
      functions
      implemented in assembly, that expect the function name to be
      mangled the
      itanium way, while the object files built by the compiler expect
      the
      symbols to use the MSVC C++ name mangling, so there's an
      undefined
      reference.

I see, thanks.

Which options exist for MSVC, in sense an alternative to libunwind and
libbacktrace ?

Well for libunwind, there's really no use for it in an MSVC setting. All the unwinding functionality is already built into the operating system, available via the Rtl*Unwind* functions.

For libbacktrace, I guess the _Unwind_Backtrace function in libunwind might work and be useful, even if the rest of libunwind doesn't make sense in such a context. I haven't tested this function on windows though, and it'd require you to fix the linker error one way or another.

Another alternative, requiring much less code, would be to just extract the SEH version of _Unwind_Backtrace function from libgcc [1]. I think that function is fairly independent from the rest of libgcc and from the rest of the surrounding file, and only calls Windows system APIs.

// Martin

[1] https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-seh.c#L434

Hi,

Just as Shoaib said, libunwind only is useful in environments
that use
the Itanium C++ ABI - there’s really no use for it in an MSVC
context
(either using MSVC or clang-cl to compile it).

The particular linker error comes from the fact that there’s
functions
implemented in assembly, that expect the function name to be
mangled the
itanium way, while the object files built by the compiler expect
the
symbols to use the MSVC C++ name mangling, so there’s an
undefined
reference.

I see, thanks.

Which options exist for MSVC, in sense an alternative to libunwind and
libbacktrace ?

Well for libunwind, there’s really no use for it in an MSVC setting. All
the unwinding functionality is already built into the operating system,
available via the RtlUnwind functions.

Martin,
you mean these functions
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwind
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwind2
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwindex
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlvirtualunwind
?

For libbacktrace, I guess the _Unwind_Backtrace function in libunwind
might work and be useful, even if the rest of libunwind doesn’t make sense
in such a context.

Ian,
please share your vision/propose some plan.

I haven’t tested this function on windows though, and
it’d require you to fix the linker error one way or another.

I see.

Another alternative, requiring much less code, would be to just extract
the SEH version of _Unwind_Backtrace function from libgcc [1]. I think
that function is fairly independent from the rest of libgcc and from the
rest of the surrounding file, and only calls Windows system APIs.

Well, adding committers to the discussion.
Richard, Tristan, Bernd, Jon - please verify/elaborate.

Thanks in advance.
Ivan

+ Kai Tietz. I have not touched on libgcc unwinders, I believe Kai would
be a better help.

SEH was only implemented for x86_64 Windows in GCC, Kai described the
32bit implementation was very different. The 32bit SEH was under Borland
patent at the time, but it has since expired.

Ivan Serdyuk <local.tourist.kiev@gmail.com> writes:

For libbacktrace, I guess the _Unwind_Backtrace function in libunwind
might work and be useful, even if the rest of libunwind doesn't make sense
in such a context.

Ian,
please share your vision/propose some plan.

Currently libbacktrace relies on _Unwind_Backtrace, which as you know
calls a callback function for each stack frame. The current callback
functions call either_Unwind_GetIPInfo or _Unwind_GetIP, but that is a
detail. If there is some alternative function that can be called on
Windows, I'm happy to have libbacktrace call that when _Unwind_Backtrace
is not available. It's look like we might be able to use
RtlVirtualUnwind in a loop to do the job.

Of course, most of libbacktrace is parsing DWARF, so to be really
effective on Windows we would need to add some code to parse the Windows
debug format.

Ian

Ian, Jon - thanks for your suggestions.
Kai, please share your vision/opinion.

Ivan

https://reviews.llvm.org/D50564 - this seems to be related, but for the targeted architecture.
But this is somewhat an aside reference, just to get some general understanding.

Ivan

      Hi,

      > Just as Shoaib said, libunwind only is useful in
      environments
      > that use
      > the Itanium C++ ABI - there's really no use for it in an
      MSVC
      > context
      > (either using MSVC or clang-cl to compile it).
      >
      > The particular linker error comes from the fact that
      there's
      > functions
      > implemented in assembly, that expect the function name
      to be
      > mangled the
      > itanium way, while the object files built by the
      compiler expect
      > the
      > symbols to use the MSVC C++ name mangling, so there's an
      > undefined
      > reference.
      >
      > I see, thanks.
      >
      > Which options exist for MSVC, in sense an alternative to
      libunwind and
      > libbacktrace ?

      Well for libunwind, there's really no use for it in an MSVC
      setting. All
      the unwinding functionality is already built into the operating
      system,
      available via the Rtl*Unwind* functions.

Martin,
you mean these functions
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwind

https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwind
2
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlunwind
ex
https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlvirtua
lunwind
?

Yes, those are the functions used for unwinding on windows.

      For libbacktrace, I guess the _Unwind_Backtrace function in
      libunwind
      might work and be useful, even if the rest of libunwind doesn't
      make sense
      in such a context.

Just FWIW, I made a RFC patch that fixes building libunwind in MSVC mode (still requiring clang-cl though), at https://reviews.llvm.org/D86041 - mostly just to show what it takes - not convinced that it necessarily is something that should be done.

It does seem like _Unwind_Backtrace in libunwind doesn't work properly on x86_64 windows at the moment though, but on aarch64 it seems to do what one would expect.

// Martin

Martin,
good to hear from you.
Thanks for the effort - I will test on 32bit and 64bit Windows 10.
I will report ASAP.

Ivan

This is what Ken Johnson replied:

I just briefly skimmed the discussion, so hopefully I didn’t misunderstand what you are trying to do … but if your objective is to capture a stack trace under NT, the OS exports several services for this purpose, depending on what you need out of such a stack trace :

  1. There is a “pre-cooked” stack trace facility that will perform the entire stack trace for you (optionally skipping some frames at the top), returning an array of program counter values for each return address on the stack: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb204633(v=vs.85)?redirectedfrom=MSDN (CaptureStackBackTrace) and its kernel/NTDLL equivalent https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlcapturestackbacktrace (RtlCaptureStackBackTrace)

  2. Alternatively, if more customization for the operation than what CaptureStackBackTrace/RtlCaptureStackBackTrace affords is required, then you could walk the stack manually by successively invoking https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlvirtualunwind (RtlVirtualUnwind) for each frame, starting with a live register context (e.g. as captured by https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlcapturecontext (RtlCaptureContext)). This would give you the opportunity to examine, for instance, the nonvolatile register context for each frame, albeit at the cost of having to write platform dependent code for each build target (e.g. AMD64, 32-bit ARMNT, ARM64, etc.). RtlCaptureStackBackTrace is essentially implemented in this way for non-32-bit-x86 targets (x86 doesn’t have what most architectures would consider an “unwinder” in the sense of restoring registers; there is simply a linked list of frames that participate in SEH and that desire to be called for a dynamic unwind operation, so RtlCaptureStackBackTrace assumes that EBP-based frames are in use and walks an EBP-based frame chain on x86 - not all x86 code is written with EBP-based frames so while even though we generally build the OS that way, you might always run the risk of encountering external code that uses EBP as a general purpose register for which such an unwind attempt for a stack trace would fail). On non-x86 architectures, the various NT platform ABIs typically strive to provide for precise unwinding at all frames and at every instruction boundary where interrupts are enabled (at least assuming that all code in the process is well-formed and follows the ABI properly etc. - interrupts are always enabled in user mode code). For C/C++ code, VC, ICC, and (I believe) LLVM/clang should support the platform exception/unwind ABIs; GCC may or may not these days.

The OS’s exception and unwind dispatcher, for non-x86 build targets, uses the virtual unwind facility to accomplish unwinding for purposes of exception handling related exception dispatching & unwinding.

On the non-x86 targets, debuggers and related tools would typically use the platform ABI’s exception and unwind handling structures for their unwinding as well. Debuggers on x86 might either assume EBP-based frames, or use compiler-specific debug information from debug symbols (typically not embedded in the compiled binary for most NT-targeted code but rather kept in a standalone .pdb/.dbg file etc.).

Note that the platform exception and unwind APIs and associated structures embedded in executable images don’t, on their own, provide a way to map a PC value to a meaningful symbolic function name, line number, etc… If you want to resolve PC values to function names, then you’ll typically need debug symbols for each module present on the call stack. For that, provided that you have debug symbols available for all such frames (OS binaries have these published on the Microsoft public symbol server; some major third parties like web browsers publish their symbols on their own symbol servers as well but many other third party binaries may not make such affordances available). There are a set of APIs (https://docs.microsoft.com/en-us/windows/win32/debug/symbol-handling) to load debug symbols for a module, and resolve a module + RVA (i.e. module + offset into the module) to a symbol name and offset into the symbol. When debug symbols aren’t available, these facilities will typically pick the nearest exported symbol (if any), which may or may not be at all meaningful (most symbols aren’t exported in most executables targeting NT). Note that loading and processing debug symbols is typically a considerably more “heavyweight” operation than invoking the platform unwind APIs.

  • S

Ian,
how close are these capabilities to what you planned for libbacktrace?

Than,

please explain which scenarios did you assume, for libbacktrace, while integrating Ian’s project with https://go.googlesource.com/gollvm/.
Please check Ken’s considerations and tell which of those would be the native way to support unwinding capabilities.
I think there is some undocumented context, for that, related to gollvm.
Consider this related to github issues, targeting support of Windows 10 (x86_64; i386). And btw - specifically ARM64 oriented Windows 10 haven’t been suggested yet, by ARM’s engineers, which contributed into brief support of ARM64 oriented Linux.

Ivan

Than,
please explain which scenarios did you assume, for libbacktrace, while integrating Ian’s project with https://go.googlesource.com/gollvm/.

Not really sure I understand your question. By “scenarios” are you talking about strategies for doing stack unwinding?

Gollvm targets libgo (the version of the Go runtime used by gccgo); the libgo runtime uses libbacktrace, but Gollvm is not doing anything special as relates to setting up or configuring libbacktrace.

Thanks, Than

Ivan Serdyuk <local.tourist.kiev@gmail.com> writes:

how close are these capabilities to what you planned for libbacktrace?

To be clear, I don't personally plan to do anything.

I agree that the capabilities mentioned in that e-mail are ones that
libbacktrace would use on Windows when not building with GCC or clang.
libbacktrace would also need more information from the debug info, such
as mapping PC to file/line, which I didn't see mentioned.

Ian