[PATCH] D50199: [MinGW] Predefine UNICODE if -municode is specified during compilation
This revision was automatically updated to reflect the committed changes. Closed by commit rC339048: [MinGW] Predefine UNICODE if -municode is specified during compilation (authored by mstorsjo, committed by ). Repository: rC Clang https://reviews.llvm.org/D50199 Files: lib/Driver/ToolChains/Clang.cpp test/Driver/mingw.cpp Index: test/Driver/mingw.cpp === --- test/Driver/mingw.cpp +++ test/Driver/mingw.cpp @@ -56,3 +56,8 @@ // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32" // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward" // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include" + +// RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s +// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s +// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE" +// CHECK_MINGW_UNICODE: "-DUNICODE" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3346,6 +3346,9 @@ if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-static-define"); + if (Args.hasArg(options::OPT_municode)) +CmdArgs.push_back("-DUNICODE"); + if (isa(JA)) RenderAnalyzerOptions(Args, CmdArgs, Triple, Input); Index: test/Driver/mingw.cpp === --- test/Driver/mingw.cpp +++ test/Driver/mingw.cpp @@ -56,3 +56,8 @@ // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32" // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward" // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include" + +// RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s +// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s +// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE" +// CHECK_MINGW_UNICODE: "-DUNICODE" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3346,6 +3346,9 @@ if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-static-define"); + if (Args.hasArg(options::OPT_municode)) +CmdArgs.push_back("-DUNICODE"); + if (isa(JA)) RenderAnalyzerOptions(Args, CmdArgs, Triple, Input); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50380: [Headers] Expand _Unwind_Exception for SEH on MinGW/x86_64
mstorsjo created this revision. mstorsjo added reviewers: rnk, compnerd, hans. Herald added a subscriber: chrib. This matches how GCC defines this struct. Repository: rC Clang https://reviews.llvm.org/D50380 Files: lib/Headers/unwind.h Index: lib/Headers/unwind.h === --- lib/Headers/unwind.h +++ lib/Headers/unwind.h @@ -154,8 +154,12 @@ struct _Unwind_Exception { _Unwind_Exception_Class exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; +#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__) + _Unwind_Word private_[6]; +#else _Unwind_Word private_1; _Unwind_Word private_2; +#endif /* The Itanium ABI requires that _Unwind_Exception objects are "double-word * aligned". GCC has interpreted this to mean "use the maximum useful * alignment for the target"; so do we. */ Index: lib/Headers/unwind.h === --- lib/Headers/unwind.h +++ lib/Headers/unwind.h @@ -154,8 +154,12 @@ struct _Unwind_Exception { _Unwind_Exception_Class exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; +#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__) + _Unwind_Word private_[6]; +#else _Unwind_Word private_1; _Unwind_Word private_2; +#endif /* The Itanium ABI requires that _Unwind_Exception objects are "double-word * aligned". GCC has interpreted this to mean "use the maximum useful * alignment for the target"; so do we. */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50380: [Headers] Expand _Unwind_Exception for SEH on MinGW/x86_64
This revision was automatically updated to reflect the committed changes. Closed by commit rL339170: [Headers] Expand _Unwind_Exception for SEH on MinGW/x86_64 (authored by mstorsjo, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D50380?vs=159481&id=159580#toc Repository: rL LLVM https://reviews.llvm.org/D50380 Files: cfe/trunk/lib/Headers/unwind.h Index: cfe/trunk/lib/Headers/unwind.h === --- cfe/trunk/lib/Headers/unwind.h +++ cfe/trunk/lib/Headers/unwind.h @@ -154,8 +154,12 @@ struct _Unwind_Exception { _Unwind_Exception_Class exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; +#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__) + _Unwind_Word private_[6]; +#else _Unwind_Word private_1; _Unwind_Word private_2; +#endif /* The Itanium ABI requires that _Unwind_Exception objects are "double-word * aligned". GCC has interpreted this to mean "use the maximum useful * alignment for the target"; so do we. */ Index: cfe/trunk/lib/Headers/unwind.h === --- cfe/trunk/lib/Headers/unwind.h +++ cfe/trunk/lib/Headers/unwind.h @@ -154,8 +154,12 @@ struct _Unwind_Exception { _Unwind_Exception_Class exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; +#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__) + _Unwind_Word private_[6]; +#else _Unwind_Word private_1; _Unwind_Word private_2; +#endif /* The Itanium ABI requires that _Unwind_Exception objects are "double-word * aligned". GCC has interpreted this to mean "use the maximum useful * alignment for the target"; so do we. */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50380: [Headers] Expand _Unwind_Exception for SEH on MinGW/x86_64
mstorsjo added a comment. @hans Can you merge this for 7.0? This is necessary for https://reviews.llvm.org/D49638 (merged well before the branch) to work properly without causing heap corruption. Repository: rL LLVM https://reviews.llvm.org/D50380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50412: [libunwind] Fix pointer-to-integer cast warnings on LLP64.
mstorsjo accepted this revision. mstorsjo added a comment. This revision is now accepted and ready to land. LGTM Repository: rUNW libunwind https://reviews.llvm.org/D50412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50414: [libunwind][include] Add SEH declarations to .
mstorsjo added a comment. Should we maybe add the same declaration of `_GCC_specific_handler` to clang's unwind.h? That would allow removing the forward declaration in libcxxabi from https://reviews.llvm.org/D49638. Do you plan on implementing these SEH specific bits in libunwind, or are you just trying to sync things? Comment at: include/unwind.h:383 +#ifdef __x86_64__ +// The DISPATCHER_CONTEXT struct is only defined on x64. +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, I think `__x86_64__` is the wrong condition here. `DISPATCHER_CONTEXT` is defined on ARM and ARM64 as well (and probably other obscure cases like IA-64), so I would rather make this `#ifndef __i386__` instead, or explicitly listing `__x86_64__`, `__arm__` and `__aarch64__`. On the other hand, we don't really ever build code with `__SEH__` defined for i386 here either, so we could also just leave it out - I see that GCC's unwind.h does that. Repository: rUNW libunwind https://reviews.llvm.org/D50414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50413: [libunwind][include] Add some missing definitions to .
mstorsjo added inline comments. Comment at: include/unwind.h:46 +typedef uintptr_t _Unwind_Ptr; +#endif + What other reference is this list of typedefs for `_Unwind_Ptr` based on? I don't see any of these cases in clang's unwind.h at least. Comment at: include/unwind.h:172 struct _Unwind_Context* context); +typedef _Unwind_Personality_Fn __personality_routine; #endif Minor nitpick: Would it make sense to move the `typedef _Unwind_Personality_Fn __personality_routine;` out of the ifdef, since the same one can be used for both cases? Repository: rUNW libunwind https://reviews.llvm.org/D50413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50412: [libunwind] Fix pointer-to-integer cast warnings on LLP64.
mstorsjo added a subscriber: hans. mstorsjo added a comment. @hans This looks 7.0-worthy to me. Repository: rL LLVM https://reviews.llvm.org/D50412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50144: Add Windows support for the GNUstep Objective-C ABI V2.
mstorsjo added inline comments. Comment at: lib/CodeGen/CGBlocks.cpp:1276 +InitVar->setSection(".CRT$XCLa"); +CGM.addUsedGlobal(InitVar); + } rjmccall wrote: > DHowett-MSFT wrote: > > rjmccall wrote: > > > Is the priority system not good enough? > > My reading of the LLVM language reference leads me to believe it’s only > > ordered per-module. If that’s the case, the benefit of emitting into `XC*` > > is that it provides guaranteed order over all linker input. > > > > `llvm.global_ctors` excerpt: > > > > > The functions referenced by this array will be called in ascending order > > > of priority (i.e. lowest first) when the module is loaded. > > > > Now if the priority system _is_ guaranteed over all linker input, will that > > guarantee hold for mixed Clang and CL objects? > Init priorities on ELF are preserved in the section name like > `.init_array.200`, and the sections get sorted by that in the image — it's > really a very similar trick to how it works with `.CRT$XC`. Of the major > formats, I think it's just Mach-O that doesn't have any built-in > prioritization mechanism across object files. But I don't know if LLVM > actually tries to translate init priorities over into `.CRT$XC` suffices when > targeting PE/COFF, and arguably that's good: init priorities as presented in > LLVM right now are pretty specific to the ELF mechanism. Long-term, maybe > `llvm.global_ctors` should be generalized so that on ELF targets it takes an > integer priority, on PE/COFF targets it takes a string, and on Mach-O it > doesn't take anything at all; but I won't hold up this patch for that. > > On the other hand, I tend to agree that maybe the best solution is for the > backend to just take care of this and automatically create a global > initializer to install non-function (or maybe non-function & `unnamed_addr`) > `dllimport`ed symbols in global data. > But I don't know if LLVM actually tries to translate init priorities over > into .CRT$XC suffices when targeting PE/COFF, and arguably that's good: init > priorities as presented in LLVM right now are pretty specific to the ELF > mechanism. Long-term, maybe llvm.global_ctors should be generalized so that > on ELF targets it takes an integer priority, on PE/COFF targets it takes a > string, and on Mach-O it doesn't take anything at all; but I won't hold up > this patch for that. FWIW, for the MinGW targets, the same ELF-like priority system is used (or I think it's actually an older mechanism previously used on ELF); constructors are emitted in `.ctors`, and those with a priority go into sections named `.ctors.01234` where the number is 65535 minus the init priority specified. By making these zero padded, they get ordered right by the normal alphabetical sorting. MinGW CRT startup routines then have extra code to run constructors in the right order from the `.ctors` section, in addition to the normal `.CRT$XC` ones. Repository: rC Clang https://reviews.llvm.org/D50144 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50414: [libunwind][include] Add SEH declarations to .
mstorsjo accepted this revision. mstorsjo added a comment. This revision is now accepted and ready to land. In https://reviews.llvm.org/D50414#1192267, @cdavis5x wrote: > In https://reviews.llvm.org/D50414#1191834, @mstorsjo wrote: > > > Do you plan on implementing these SEH specific bits in libunwind, > > > Already have. Patch forthcoming. Oh, excellent - looking forward to it. This version LGTM. Repository: rUNW libunwind https://reviews.llvm.org/D50414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50413: [libunwind][include] Add some missing definitions to .
mstorsjo added a comment. @cdavis5x I presume the fact that this one turned out tricky is blocking submitting the SEH unwinding patch. Would it be worth to rework that patch to just use the basic types just like libunwind does today, e.g. having `_Unwind_GetRegionStart` return plain `uintptr_t` instead of `_Unwind_Ptr`, which also would be consistent with the existing entry points in Unwind-EHABI.cpp, Unwind-sjlj.c and UnwindLevel1.c, in order to be able to submit it before this one gets sorted out? Repository: rUNW libunwind https://reviews.llvm.org/D50413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50564: Add support for SEH unwinding on Windows.
mstorsjo added a comment. > I've tested this implementation on x86-64 to ensure that it works. All > libc++abi tests pass, as do all libc++ exception-related tests. I tested it now as well, and seems to work for my simple testcase. > ARM still remains to be implemented (@compnerd?). LLVM doesn't generate SEH unwind data for ARM at all yet. ARM64 implementation is ongoing at the moment though, see https://reviews.llvm.org/D50166 and https://reviews.llvm.org/D50288. > Special thanks to KJK::Hyperion for his excellent series of articles on how > EH works on x86-64 Windows. (Seriously, check it out. It's awesome.) Can you give some links to it? A brief googling didn't turn up much else than the PSEH library. > I'm actually not sure if this should go in as is. I particularly don't like > that I duplicated the UnwindCursor class for this special case. As I'm not totally familiar with how it works, I can only give cursory comments and compare to the libgcc implementation when trying to wrap my head around it, but this does seem way, way more complex than the libgcc version of the same. As for the duplicated UnwindCursor, I'm thinking if it'd become more straightforward by avoiding touching those parts altogether, and just reimplementing all the other public functions, `_Unwind_G/SetGR/IP`, `_Unwind_Backtrace` etc, directly in Unwind-seh.cpp, and not care about using the libunwind.h APIs (`unw_*`) inbetween altogether? Or perhaps my libgcc comparison is making me biased. Comment at: src/Unwind-seh.cpp:53 + +/// Exception cleanup routine used by \c __libunwind_frame_consolidate to +/// regain control after handling an SEH exception. I don't see any `__libunwind_frame_consolidate` anywhere, is this comment outdated? Comment at: src/UnwindLevel1.c:35 +#if !_LIBUNWIND_SUPPORT_SEH_UNWIND + This probably works, but isn't `#if !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)` more of the common form? Comment at: src/libunwind_ext.h:43 + #if defined(__x86_64__) && !defined(__MINGW64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; What's this all about? winnt.h (from both MSVC and mingw-w64) should define this struct, no? Comment at: src/libunwind_ext.h:73 + #endif +extern int _unw_init_seh(unw_cursor_t *cursor, CONTEXT *ctx); +extern DISPATCHER_CONTEXT *_unw_seh_get_disp_ctx(unw_cursor_t *cursor); These are all both defined and called from Unwind-seh.cpp, so couldn't they just be static functions within there? Repository: rUNW libunwind https://reviews.llvm.org/D50564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50663: [libunwind] [cmake] Add MINGW_LIBRARIES to the linker flags
mstorsjo created this revision. mstorsjo added reviewers: rnk, compnerd, phosek, smeenai. Herald added subscribers: chrib, mgorny. This is essential when building with -nodefaultlibs. In some CMake versions (noticed in 3.5.1), the same libraries are picked up from CMAKE_REQUIRED_LIBRARIES in some exceptional situations (if CXX probing failed, due to libc++ not being built yet, the libraries from CMAKE_REQUIRED_LIBRARIES are used for linking the target library), but not at all in other newer CMake versions (3.10). This is similar to what already is done in libcxxabi in SVN r302760 and libcxx in SVN r312498. Repository: rUNW libunwind https://reviews.llvm.org/D50663 Files: src/CMakeLists.txt Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -62,6 +62,9 @@ append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) +# MINGW_LIBRARIES is defined in config-ix.cmake +append_if(libraries MINGW "${MINGW_LIBRARIES}") + if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES) list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions) list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables) Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -62,6 +62,9 @@ append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) +# MINGW_LIBRARIES is defined in config-ix.cmake +append_if(libraries MINGW "${MINGW_LIBRARIES}") + if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES) list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions) list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50663: [libunwind] [cmake] Add MINGW_LIBRARIES to the linker flags
This revision was automatically updated to reflect the committed changes. Closed by commit rL339642: [cmake] Add MINGW_LIBRARIES to the linker flags (authored by mstorsjo, committed by ). Herald added subscribers: llvm-commits, christof. Changed prior to commit: https://reviews.llvm.org/D50663?vs=160442&id=160517#toc Repository: rL LLVM https://reviews.llvm.org/D50663 Files: libunwind/trunk/src/CMakeLists.txt Index: libunwind/trunk/src/CMakeLists.txt === --- libunwind/trunk/src/CMakeLists.txt +++ libunwind/trunk/src/CMakeLists.txt @@ -62,6 +62,9 @@ append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) +# MINGW_LIBRARIES is defined in config-ix.cmake +append_if(libraries MINGW "${MINGW_LIBRARIES}") + if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES) list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions) list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables) Index: libunwind/trunk/src/CMakeLists.txt === --- libunwind/trunk/src/CMakeLists.txt +++ libunwind/trunk/src/CMakeLists.txt @@ -62,6 +62,9 @@ append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) +# MINGW_LIBRARIES is defined in config-ix.cmake +append_if(libraries MINGW "${MINGW_LIBRARIES}") + if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES) list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions) list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50691: [CMake] Fix the LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY option
mstorsjo created this revision. mstorsjo added reviewers: phosek, rnk, compnerd, smeenai. Herald added subscribers: ldionne, mgorny. This option should be available if LIBCXX_ENABLE_SHARED is enabled, not LIBCXX_ENABLE_STATIC, since the option is about linking shard libraries. This fixes a typo from SVN r337814. Repository: rCXX libc++ https://reviews.llvm.org/D50691 Files: CMakeLists.txt Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -175,7 +175,7 @@ cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY "Statically link the ABI library to shared library" ON - "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -175,7 +175,7 @@ cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY "Statically link the ABI library to shared library" ON - "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50691: [CMake] Fix the LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY option
mstorsjo added a comment. @hans I think this should be merged to 7.0, if reviewers agree with the change. Repository: rCXX libc++ https://reviews.llvm.org/D50691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50564: Add support for SEH unwinding on Windows.
mstorsjo added a comment. In https://reviews.llvm.org/D50564#1199285, @rnk wrote: > In https://reviews.llvm.org/D50564#1198996, @cdavis5x wrote: > > > Could somebody verify that the `DISPATCHER_CONTEXT` struct is defined in > > `` for the Win8 and Win10 SDKs? I can't install them right now. > > > I checked both, and they are available, so I think we should guard the > definition like this: > > // Provide a definition for _DISPATCHER_CONTEXT for Win7 and earlier SDK > versions. > // Mingw64 has always provided this struct. > #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW64__) && > defined(WINVER) && WINVER < _WIN32_WINNT_WIN8 For the mingw check, I'd prefer checking for `__MINGW32__`, as the -64 version isn't defined when targeting 32 bit ARM (which uses SEH, even though everything isn't in place for it in LLVM). And mingw-w64 might lack this struct for arm/arm64, but I can fix that and wouldn't bother with older versions of that. And if these structs only are added for compat with the win7 sdk, maybe omit the arm one altogether, as all modern non-windows ce versions on arm is >= win8. Repository: rUNW libunwind https://reviews.llvm.org/D50564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50691: [CMake] Fix the LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY option
This revision was automatically updated to reflect the committed changes. Closed by commit rL339697: [CMake] Fix the LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY option (authored by mstorsjo, committed by ). Herald added subscribers: llvm-commits, christof. Changed prior to commit: https://reviews.llvm.org/D50691?vs=160529&id=160635#toc Repository: rL LLVM https://reviews.llvm.org/D50691 Files: libcxx/trunk/CMakeLists.txt Index: libcxx/trunk/CMakeLists.txt === --- libcxx/trunk/CMakeLists.txt +++ libcxx/trunk/CMakeLists.txt @@ -175,7 +175,7 @@ cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY "Statically link the ABI library to shared library" ON - "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default Index: libcxx/trunk/CMakeLists.txt === --- libcxx/trunk/CMakeLists.txt +++ libcxx/trunk/CMakeLists.txt @@ -175,7 +175,7 @@ cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY "Statically link the ABI library to shared library" ON - "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50564: Add support for SEH unwinding on Windows.
mstorsjo added a comment. In https://reviews.llvm.org/D50564#1206370, @cdavis5x wrote: > In https://reviews.llvm.org/D50564#1206302, @kristina wrote: > > > I'm all for this change except the core issue is that you're using > > libunwind as a shim around the actual unwinding API provided by Windows. It > > would be nice to have something that did not have to do that and was > > capable of performing unwinding of SEH-style exceptions without needing > > additional runtime support. > > > It would be nice, but that would require extra work. We'd have to implement > reading and interpreting unwind codes, and calling any handlers present at > each frame (which all have a different calling convention from Itanium > handlers), and handling chained unwind info... Or we could use the > implementation that MS provided to us for free--and which gets loaded into > every process anyway by virtue of being in NTDLL, and which is extremely well > tested. Given all that, I'm wondering what implementing all that ourselves > would gain us. I suppose we could eventually do all that, but for now, I > think this is outside the scope of my change. +1. I guess such a library would be very nice to have, but from the point of view of implementing exception handling, using the underlying APIs probably is the way to go. The other question, as posted before, is whether we want to wrap the whole CONTEXT structs in the UnwindCursor class and expose it via the unw_* set of APIs. It gives quite a significant amount of extra code here compared to libgcc's unwind-seh.c which is <500 loc altogether, providing only the _Unwind_* API, implementing it directly with the Windows Rtl* APIs from ntdll. That would give only a partial libunwind, with only the higher level API available, but that's the only part used for exception handling at least. Repository: rUNW libunwind https://reviews.llvm.org/D50564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51026: [CodeGen] Implicitly set stackrealign on the main function, if custom stack alignment is used
mstorsjo created this revision. mstorsjo added reviewers: craig.topper, erichkeane, rnk. If using a custom stack alignment, one is expected to make sure that all callers provide such alignment, or realign the stack in all entry points (and callbacks). Despite this, the compiler can assume that the main function will need realignment in these cases, since the startup routines calling the main function most probably won't provide the custom alignment. This matches what GCC does in similar cases; if compiling with -mincoming-stack-boundary=X -mpreferred-stack-boundary=X, GCC normally assumes such alignment on entry to a function, but specifically for the main function still does realignment. Repository: rC Clang https://reviews.llvm.org/D51026 Files: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/stackrealign-main.c Index: test/CodeGen/stackrealign-main.c === --- /dev/null +++ test/CodeGen/stackrealign-main.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - -mstack-alignment=64 %s | FileCheck %s + +// CHECK-LABEL: define void @other() +// CHECK: [[OTHER:#[0-9]+]] +// CHECK: { +void other(void) {} + +// CHECK-LABEL: define i32 @main( +// CHECK: [[MAIN:#[0-9]+]] +// CHECK: { +int main(int argc, char **argv) { + other(); + return 0; +} + +// CHECK: attributes [[OTHER]] = { noinline nounwind optnone +// CHECK-NOT: "stackrealign" +// CHECK: } +// CHECK: attributes [[MAIN]] = { noinline nounwind optnone {{.*}}"stackrealign"{{.*}} } Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -981,6 +981,13 @@ if (FD->isMain()) Fn->addFnAttr(llvm::Attribute::NoRecurse); + // If a custom alignment is used, force realigning to this alignment on + // any main function which certainly will need it. + if (const FunctionDecl *FD = dyn_cast_or_null(D)) +if ((FD->isMain() || FD->isMSVCRTEntryPoint()) && +CGM.getCodeGenOpts().StackAlignment) + Fn->addFnAttr("stackrealign"); + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock Index: test/CodeGen/stackrealign-main.c === --- /dev/null +++ test/CodeGen/stackrealign-main.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - -mstack-alignment=64 %s | FileCheck %s + +// CHECK-LABEL: define void @other() +// CHECK: [[OTHER:#[0-9]+]] +// CHECK: { +void other(void) {} + +// CHECK-LABEL: define i32 @main( +// CHECK: [[MAIN:#[0-9]+]] +// CHECK: { +int main(int argc, char **argv) { + other(); + return 0; +} + +// CHECK: attributes [[OTHER]] = { noinline nounwind optnone +// CHECK-NOT: "stackrealign" +// CHECK: } +// CHECK: attributes [[MAIN]] = { noinline nounwind optnone {{.*}}"stackrealign"{{.*}} } Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -981,6 +981,13 @@ if (FD->isMain()) Fn->addFnAttr(llvm::Attribute::NoRecurse); + // If a custom alignment is used, force realigning to this alignment on + // any main function which certainly will need it. + if (const FunctionDecl *FD = dyn_cast_or_null(D)) +if ((FD->isMain() || FD->isMSVCRTEntryPoint()) && +CGM.getCodeGenOpts().StackAlignment) + Fn->addFnAttr("stackrealign"); + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51026: [CodeGen] Implicitly set stackrealign on the main function, if custom stack alignment is used
mstorsjo added inline comments. Comment at: lib/CodeGen/CodeGenFunction.cpp:989 +CGM.getCodeGenOpts().StackAlignment) + Fn->addFnAttr("stackrealign"); + erichkeane wrote: > Is there not an attribute name for this already in LLVM? I guess I'm > otherwise fine with this, but would want @craig.topper or @rnk to confirm > that we're Ok just sending this string as an attribute. I don't see one in llvm/include/llvm/IR/Attributes.td at least, and all other occurrances in clang just use the plain string. Repository: rC Clang https://reviews.llvm.org/D51026 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51026: [CodeGen] Implicitly set stackrealign on the main function, if custom stack alignment is used
This revision was automatically updated to reflect the committed changes. Closed by commit rL340334: [CodeGen] Implicitly set stackrealign on the main function, if custom stack… (authored by mstorsjo, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D51026?vs=161653&id=161809#toc Repository: rL LLVM https://reviews.llvm.org/D51026 Files: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/test/CodeGen/stackrealign-main.c Index: cfe/trunk/test/CodeGen/stackrealign-main.c === --- cfe/trunk/test/CodeGen/stackrealign-main.c +++ cfe/trunk/test/CodeGen/stackrealign-main.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - -mstack-alignment=64 %s | FileCheck %s + +// CHECK-LABEL: define void @other() +// CHECK: [[OTHER:#[0-9]+]] +// CHECK: { +void other(void) {} + +// CHECK-LABEL: define i32 @main( +// CHECK: [[MAIN:#[0-9]+]] +// CHECK: { +int main(int argc, char **argv) { + other(); + return 0; +} + +// CHECK: attributes [[OTHER]] = { noinline nounwind optnone +// CHECK-NOT: "stackrealign" +// CHECK: } +// CHECK: attributes [[MAIN]] = { noinline nounwind optnone {{.*}}"stackrealign"{{.*}} } Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -979,6 +979,13 @@ if (FD->isMain()) Fn->addFnAttr(llvm::Attribute::NoRecurse); + // If a custom alignment is used, force realigning to this alignment on + // any main function which certainly will need it. + if (const FunctionDecl *FD = dyn_cast_or_null(D)) +if ((FD->isMain() || FD->isMSVCRTEntryPoint()) && +CGM.getCodeGenOpts().StackAlignment) + Fn->addFnAttr("stackrealign"); + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock Index: cfe/trunk/test/CodeGen/stackrealign-main.c === --- cfe/trunk/test/CodeGen/stackrealign-main.c +++ cfe/trunk/test/CodeGen/stackrealign-main.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - -mstack-alignment=64 %s | FileCheck %s + +// CHECK-LABEL: define void @other() +// CHECK: [[OTHER:#[0-9]+]] +// CHECK: { +void other(void) {} + +// CHECK-LABEL: define i32 @main( +// CHECK: [[MAIN:#[0-9]+]] +// CHECK: { +int main(int argc, char **argv) { + other(); + return 0; +} + +// CHECK: attributes [[OTHER]] = { noinline nounwind optnone +// CHECK-NOT: "stackrealign" +// CHECK: } +// CHECK: attributes [[MAIN]] = { noinline nounwind optnone {{.*}}"stackrealign"{{.*}} } Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -979,6 +979,13 @@ if (FD->isMain()) Fn->addFnAttr(llvm::Attribute::NoRecurse); + // If a custom alignment is used, force realigning to this alignment on + // any main function which certainly will need it. + if (const FunctionDecl *FD = dyn_cast_or_null(D)) +if ((FD->isMain() || FD->isMSVCRTEntryPoint()) && +CGM.getCodeGenOpts().StackAlignment) + Fn->addFnAttr("stackrealign"); + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50564: Add support for SEH unwinding on Windows.
mstorsjo added inline comments. Comment at: src/Unwind-seh.cpp:163 +#ifdef __x86_64__ +unw_get_reg(&cursor, UNW_X86_64_RAX, &retval); +unw_get_reg(&cursor, UNW_X86_64_RDX, &exc->private_[3]); Without understanding the code flow completely - is there a risk that this tries to use an uninitialized cursor, in case we hit `ctx = (struct _Unwind_Context *)ms_exc->ExceptionInformation[1];` above and never initialized the local cursor? Comment at: src/Unwind-seh.cpp:174 +CONTEXT new_ctx; +RtlUnwindEx(frame, (PVOID)target, ms_exc, (PVOID)retval, &new_ctx, disp->HistoryTable); +_LIBUNWIND_ABORT("RtlUnwindEx() failed"); Who will get this new uninitialized CONTEXT here, and will they try to use it for something? Comment at: src/UnwindCursor.hpp:31 +struct UNWIND_INFO { + uint8_t Version : 3; + uint8_t Flags : 5; Hmm, I think this one is supposed to be arch independent. Although it's easy to remove the ifdef once we want to use it for anything else than x86_64... Comment at: src/UnwindCursor.hpp:54 #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" This looks like another leftover; there's no `libunwind_ext.h` any longer here. Comment at: src/UnwindCursor.hpp:482 + int stepWithSEHData() { +#if !defined(_LIBUNWIND_TARGET_I386) +_dispContext.LanguageHandler = RtlVirtualUnwind(UNW_FLAG_UHANDLER, Maybe skip the i386 ifdefs here, to keep it concise, as we don't expect to build this with `__SEH__` defined for i386. Comment at: src/UnwindCursor.hpp:625 + memset(&_histTable, 0, sizeof(_histTable)); + // FIXME + // fill in _registers from thread arg If this constructor is unused and unimplemented, I'd omit it altogether. Comment at: src/UnwindCursor.hpp:1157 +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + pint_t getLastPC() const { /* FIXME: Implement */ return 0; } What does this whole block do here? Isn't this within an !SEH ifdef block? The same methods are declared for the SEH version of this struct further above. Comment at: src/UnwindCursor.hpp:1801 + if (pc != getLastPC()) { +UNWIND_INFO *xdata = reinterpret_cast(base + unwindEntry->UnwindData); +if (xdata->Flags & (UNW_FLAG_EHANDLER|UNW_FLAG_UHANDLER)) { I can't say I understand all of this yet, but I'm slowly getting there, and I'm trying to compare this to what libgcc does. libgcc doesn't use any definition of UNWIND_INFO and doesn't need to do the equivalent of `getInfoFromSEH`, used by `step()`, anywhere. `unw_step()` is used in `_Unwind_ForcedUnwind`, which in libgcc is implemented using `RaiseException (STATUS_GCC_FORCED, ...`. I guess if you happen to have all of the `unw_step` API available, it's easier to just do it like this, in custom code without relying on the NTDLL functions for it, while the libgcc version relies more on the NTDLL API. Repository: rUNW libunwind https://reviews.llvm.org/D50564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46287: [Driver] Don't add -dwarf-column-info when using -gcodeview on non-msvc targets
This revision was automatically updated to reflect the committed changes. Closed by commit rL331807: [Driver] Don't add -dwarf-column-info when using -gcodeview on non-msvc targets (authored by mstorsjo, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D46287?vs=144630&id=145776#toc Repository: rL LLVM https://reviews.llvm.org/D46287 Files: cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/test/Driver/codeview-column-info.c Index: cfe/trunk/test/Driver/codeview-column-info.c === --- cfe/trunk/test/Driver/codeview-column-info.c +++ cfe/trunk/test/Driver/codeview-column-info.c @@ -6,6 +6,8 @@ // RUN: FileCheck < %t1 %s // RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2 // RUN: FileCheck < %t2 %s +// RUN: %clangxx -### --target=x86_64-windows-gnu -c -g -gcodeview %s 2> %t2 +// RUN: FileCheck < %t2 %s // RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 -- %s 2> %t2 // RUN: FileCheck < %t2 %s Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp === --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -3000,7 +3000,7 @@ // debuggers don't handle missing end columns well, so it's better not to // include any column info. if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info, - /*Default=*/!(IsWindowsMSVC && EmitCodeView) && + /*Default=*/!EmitCodeView && DebuggerTuning != llvm::DebuggerKind::SCE)) CmdArgs.push_back("-dwarf-column-info"); Index: cfe/trunk/test/Driver/codeview-column-info.c === --- cfe/trunk/test/Driver/codeview-column-info.c +++ cfe/trunk/test/Driver/codeview-column-info.c @@ -6,6 +6,8 @@ // RUN: FileCheck < %t1 %s // RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2 // RUN: FileCheck < %t2 %s +// RUN: %clangxx -### --target=x86_64-windows-gnu -c -g -gcodeview %s 2> %t2 +// RUN: FileCheck < %t2 %s // RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 -- %s 2> %t2 // RUN: FileCheck < %t2 %s Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp === --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -3000,7 +3000,7 @@ // debuggers don't handle missing end columns well, so it's better not to // include any column info. if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info, - /*Default=*/!(IsWindowsMSVC && EmitCodeView) && + /*Default=*/!EmitCodeView && DebuggerTuning != llvm::DebuggerKind::SCE)) CmdArgs.push_back("-dwarf-column-info"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46520: [Driver] Use -fuse-line-directives by default in MSVC mode
mstorsjo added a comment. In https://reviews.llvm.org/D46520#1092233, @rnk wrote: > Please don't do this, this is actually really problematic, since `#line` > directives lose information about what's a system header. That means the > result of -E usually won't compile, since Windows headers are typically full > of warnings and default-error warnings. Oh, ok - I can revert it then; I didn't have any specific need for this, I just noticed that clang in msvc mode and cl.exe differed in this aspect. Repository: rL LLVM https://reviews.llvm.org/D46520 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46520: [Driver] Use -fuse-line-directives by default in MSVC mode
mstorsjo closed this revision. mstorsjo added a comment. Reverted in SVN r331858. Repository: rL LLVM https://reviews.llvm.org/D46520 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D47476: Support __iso_volatile_load8 etc on aarch64-win32.
mstorsjo accepted this revision. mstorsjo added a comment. This revision is now accepted and ready to land. LGTM, thanks! Repository: rC Clang https://reviews.llvm.org/D47476 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37530: [MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked
This revision was automatically updated to reflect the committed changes. Closed by commit rL314138: [MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D37530?vs=114429&id=116587#toc Repository: rL LLVM https://reviews.llvm.org/D37530 Files: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp cfe/trunk/test/Driver/mingw-msvcrt.c Index: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp === --- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp +++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp @@ -82,6 +82,9 @@ CmdArgs.push_back("-lmoldname"); CmdArgs.push_back("-lmingwex"); + for (auto Lib : Args.getAllArgValues(options::OPT_l)) +if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase") + return; CmdArgs.push_back("-lmsvcrt"); } Index: cfe/trunk/test/Driver/mingw-msvcrt.c === --- cfe/trunk/test/Driver/mingw-msvcrt.c +++ cfe/trunk/test/Driver/mingw-msvcrt.c @@ -0,0 +1,5 @@ +// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s +// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s + +// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32" +// CHECK_MSVCR120: "-lmingwex" "-ladvapi32" Index: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp === --- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp +++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp @@ -82,6 +82,9 @@ CmdArgs.push_back("-lmoldname"); CmdArgs.push_back("-lmingwex"); + for (auto Lib : Args.getAllArgValues(options::OPT_l)) +if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase") + return; CmdArgs.push_back("-lmsvcrt"); } Index: cfe/trunk/test/Driver/mingw-msvcrt.c === --- cfe/trunk/test/Driver/mingw-msvcrt.c +++ cfe/trunk/test/Driver/mingw-msvcrt.c @@ -0,0 +1,5 @@ +// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s +// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s + +// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32" +// CHECK_MSVCR120: "-lmingwex" "-ladvapi32" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38247: [libunwind] Correct data types in the _Unwind_FunctionContext struct
mstorsjo created this revision. This makes it match the definition used within llvm and in libgcc, we previously got the wrong layout on 64 bit. https://reviews.llvm.org/D38247 Files: src/Unwind-sjlj.c Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -39,10 +39,10 @@ struct _Unwind_FunctionContext *prev; // set by calling function before registering to be the landing pad - uintptr_t resumeLocation; + uint32_tresumeLocation; // set by personality handler to be parameters passed to landing pad function - uintptr_t resumeParameters[4]; + uint32_tresumeParameters[4]; // set by calling function before registering __personality_routine personality; // arm offset=24 Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -39,10 +39,10 @@ struct _Unwind_FunctionContext *prev; // set by calling function before registering to be the landing pad - uintptr_t resumeLocation; + uint32_tresumeLocation; // set by personality handler to be parameters passed to landing pad function - uintptr_t resumeParameters[4]; + uint32_tresumeParameters[4]; // set by calling function before registering __personality_routine personality; // arm offset=24 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38249: [libunwind] Skip building unused parts when targeting SJLJ
mstorsjo created this revision. Herald added subscribers: kristof.beyls, aemerson. When SJLJ exceptions are used, those functions aren't used. This fixes build failures on ARM with SJLJ enabled, such as armv7/iOS. https://reviews.llvm.org/D38249 Files: src/UnwindLevel1.c src/UnwindRegistersRestore.S src/UnwindRegistersSave.S src/libunwind.cpp Index: src/libunwind.cpp === --- src/libunwind.cpp +++ src/libunwind.cpp @@ -24,6 +24,7 @@ #include +#ifndef __USING_SJLJ_EXCEPTIONS__ #include "AddressSpace.hpp" #include "UnwindCursor.hpp" @@ -341,6 +342,7 @@ DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde); } #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#endif // !defined(__USING_SJLJ_EXCEPTIONS__) Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -289,7 +289,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !defined(__APPLE__) +#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) #if !defined(__ARM_ARCH_ISA_ARM) .thumb Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -308,7 +308,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !defined(__APPLE__) +#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) #if !defined(__ARM_ARCH_ISA_ARM) .thumb Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -30,7 +30,7 @@ #include "unwind.h" #include "config.h" -#if !defined(_LIBUNWIND_ARM_EHABI) +#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { @@ -503,4 +503,4 @@ unw_set_reg(cursor, UNW_REG_IP, value); } -#endif // !defined(_LIBUNWIND_ARM_EHABI) +#endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) Index: src/libunwind.cpp === --- src/libunwind.cpp +++ src/libunwind.cpp @@ -24,6 +24,7 @@ #include +#ifndef __USING_SJLJ_EXCEPTIONS__ #include "AddressSpace.hpp" #include "UnwindCursor.hpp" @@ -341,6 +342,7 @@ DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde); } #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) +#endif // !defined(__USING_SJLJ_EXCEPTIONS__) Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -289,7 +289,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !defined(__APPLE__) +#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) #if !defined(__ARM_ARCH_ISA_ARM) .thumb Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -308,7 +308,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !defined(__APPLE__) +#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) #if !defined(__ARM_ARCH_ISA_ARM) .thumb Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -30,7 +30,7 @@ #include "unwind.h" #include "config.h" -#if !defined(_LIBUNWIND_ARM_EHABI) +#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { @@ -503,4 +503,4 @@ unw_set_reg(cursor, UNW_REG_IP, value); } -#endif // !defined(_LIBUNWIND_ARM_EHABI) +#endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo created this revision. When targeting apple platforms, these functions are implemented in Unwind_AppleExtras.cpp, but there's previously no implementation for other platforms. Does `__thread` have any specific runtime requirements on e.g. windows? https://reviews.llvm.org/D38250 Files: src/Unwind-sjlj.c Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -465,4 +465,18 @@ return 0; } +#ifndef __APPLE__ +__thread struct _Unwind_FunctionContext *stack = NULL; + +_LIBUNWIND_HIDDEN +struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { + return stack; +} + +_LIBUNWIND_HIDDEN +void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) { + stack = fc; +} +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -465,4 +465,18 @@ return 0; } +#ifndef __APPLE__ +__thread struct _Unwind_FunctionContext *stack = NULL; + +_LIBUNWIND_HIDDEN +struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { + return stack; +} + +_LIBUNWIND_HIDDEN +void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) { + stack = fc; +} +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38249: [libunwind] Skip building unused parts when targeting SJLJ
mstorsjo closed this revision. mstorsjo marked an inline comment as done. mstorsjo added a comment. Committed in SVN r314197. https://reviews.llvm.org/D38249 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38247: [libunwind] Correct data types in the _Unwind_FunctionContext struct
mstorsjo closed this revision. mstorsjo added a comment. Committed in SVN r314196. https://reviews.llvm.org/D38247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo added a comment. In https://reviews.llvm.org/D38250#880871, @compnerd wrote: > I have a complete implementation for this which is known to work on Windows > at least. Patches for libunwind, or standalone? In any case, please do share if you think it's relevant. > The only thing that `__thread` requires is a working linker (which does not > include binutils -- I do have a local patch to make that work though). Ok, thanks for clarifying. (If I read wikipedia right, it requires Vista if built into a DLL that isn't linked to by an executable but loaded via LoadLibrary though.) > Are these two the only ones that are missing? As far as I've seen in my tests, these are the only ones missing yes. Most of the rest of `Unwind_AppleExtras.cpp` contains things not relating to SJLJ. > At the very least, the implementation of `SetTopOfFunctionStack` is incorrect. In which way? My implementation does pretty much exactly the same as the apple version of `SetTopOfFunctionStack`, but using a `__thread` variable instead of `_pthread_setspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key, fc);`. https://reviews.llvm.org/D38250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38290: Add a ld64.lld alias for the MACHO LLD target
mstorsjo added inline comments. Comment at: tools/clang/lib/Driver/ToolChain.cpp:394 +llvm::SmallString<8> LinkerName; +if(Triple.isOSDarwin()) + LinkerName.append("ld64."); Space between `if` and `(` Repository: rL LLVM https://reviews.llvm.org/D38290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38380: [libunwind] Add CMake support for building for MinGW
mstorsjo created this revision. Herald added a subscriber: mgorny. This is the cmake specific parts of https://reviews.llvm.org/D33601 (by Martell Malone) split out into a separate patch, to ease getting this part reviewed indendent of the rest of that patch. https://reviews.llvm.org/D38380 Files: cmake/config-ix.cmake 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: 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 () ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38381: [libunwind] Skip building x86 parts of UnwindRegisters*.S when targeting SjLj
mstorsjo created this revision. Herald added subscribers: kristof.beyls, aemerson. This extends SVN r314197 (https://reviews.llvm.org/D38249) from the arm parts to the whole file (the x86 parts as well). https://reviews.llvm.org/D38381 Files: src/UnwindRegistersRestore.S src/UnwindRegistersSave.S Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) # @@ -289,7 +291,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -471,5 +473,7 @@ l.sw 124(r3), r31 #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind13Registers_x866jumptoEv) # @@ -308,7 +310,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -491,5 +493,7 @@ #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) # @@ -289,7 +291,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -471,5 +473,7 @@ l.sw 124(r3), r31 #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind13Registers_x866jumptoEv) # @@ -308,7 +310,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -491,5 +493,7 @@ #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo added inline comments. Comment at: src/Unwind-sjlj.c:468 +#ifndef __APPLE__ +__thread struct _Unwind_FunctionContext *stack = NULL; compnerd wrote: > I would prefer: > > #if !defined(__APPLE__) Sure, I can change that. Comment at: src/Unwind-sjlj.c:469 +#ifndef __APPLE__ +__thread struct _Unwind_FunctionContext *stack = NULL; + compnerd wrote: > Please make this `static`. Oh, indeed, yes, I'll change that. Comment at: src/Unwind-sjlj.c:481 +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) compnerd wrote: > Can't both of these also be static? No, since they're declared earlier as non-static. https://reviews.llvm.org/D38250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo updated this revision to Diff 117089. mstorsjo edited the summary of this revision. mstorsjo added a comment. Made the tls variable static, changed ifndef into !defined(). https://reviews.llvm.org/D38250 Files: src/Unwind-sjlj.c Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -465,4 +465,18 @@ return 0; } +#if !defined(__APPLE__) +static __thread struct _Unwind_FunctionContext *stack = NULL; + +_LIBUNWIND_HIDDEN +struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { + return stack; +} + +_LIBUNWIND_HIDDEN +void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) { + stack = fc; +} +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) Index: src/Unwind-sjlj.c === --- src/Unwind-sjlj.c +++ src/Unwind-sjlj.c @@ -465,4 +465,18 @@ return 0; } +#if !defined(__APPLE__) +static __thread struct _Unwind_FunctionContext *stack = NULL; + +_LIBUNWIND_HIDDEN +struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() { + return stack; +} + +_LIBUNWIND_HIDDEN +void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) { + stack = fc; +} +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38380: [libunwind] Add CMake support for building for MinGW
mstorsjo added inline comments. Comment at: cmake/config-ix.cmake:38 +else () + set(MINGW_RUNTIME gcc_s gcc) +endif() compnerd wrote: > This seems really weird. `gcc_s` and `gcc` are the same library, the former > is the shared version of the latter. Is this really correct? I think so; my impression is that `libgcc.a` contains some object files that end up linked into every module, even if you're otherwise using a shared `libgcc_s_.dll`. In any case, this is identical to the same lines in libcxxabi and libcxx as well; the only difference is in the library name above in `if (_USE_COMPILER_RT)`, so if there needs to be a change, it should be changed there as well. https://reviews.llvm.org/D38380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38381: [libunwind] Skip building x86 parts of UnwindRegisters*.S when targeting SjLj
This revision was automatically updated to reflect the committed changes. Closed by commit rL314492: Skip building x86 parts of UnwindRegisters*.S when targeting SjLj (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38381?vs=117047&id=117092#toc Repository: rL LLVM https://reviews.llvm.org/D38381 Files: libunwind/trunk/src/UnwindRegistersRestore.S libunwind/trunk/src/UnwindRegistersSave.S Index: libunwind/trunk/src/UnwindRegistersSave.S === --- libunwind/trunk/src/UnwindRegistersSave.S +++ libunwind/trunk/src/UnwindRegistersSave.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) # @@ -289,7 +291,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -471,5 +473,7 @@ l.sw 124(r3), r31 #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: libunwind/trunk/src/UnwindRegistersRestore.S === --- libunwind/trunk/src/UnwindRegistersRestore.S +++ libunwind/trunk/src/UnwindRegistersRestore.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind13Registers_x866jumptoEv) # @@ -308,7 +310,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -491,5 +493,7 @@ #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: libunwind/trunk/src/UnwindRegistersSave.S === --- libunwind/trunk/src/UnwindRegistersSave.S +++ libunwind/trunk/src/UnwindRegistersSave.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) # @@ -289,7 +291,7 @@ movx0, #0 // return UNW_ESUCCESS ret -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -471,5 +473,7 @@ l.sw 124(r3), r31 #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE Index: libunwind/trunk/src/UnwindRegistersRestore.S === --- libunwind/trunk/src/UnwindRegistersRestore.S +++ libunwind/trunk/src/UnwindRegistersRestore.S @@ -11,6 +11,8 @@ .text +#if !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) + #if defined(__i386__) DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind13Registers_x866jumptoEv) # @@ -308,7 +310,7 @@ ldpx0, x1, [x0, #0x000] // restore x0,x1 retx30// jump to pc -#elif defined(__arm__) && !(defined(__APPLE__) || defined(__USING_SJLJ_EXCEPTIONS__)) +#elif defined(__arm__) #if !defined(__ARM_ARCH_ISA_ARM) .thumb @@ -491,5 +493,7 @@ #endif +#endif /* !defined(__APPLE__) && !defined(__USING_SJLJ_EXCEPTIONS__) */ + NO_EXEC_STACK_DIRECTIVE ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo added inline comments. Comment at: src/Unwind-sjlj.c:481 +#endif // !defined(__APPLE__) + #endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) compnerd wrote: > mstorsjo wrote: > > compnerd wrote: > > > Can't both of these also be static? > > No, since they're declared earlier as non-static. > Yeah, that is a bug :-). `__Unwind_SjLj_GetTopOfFunctionStack` and > `__Unwind_SjLj_SetToOfFunctionStack` are implementation details of LLVM's > libunwind. They are not part of the public interfaces, and are not used > outside of this TU, and should be marked as static as such. I think that > changing the prototype declaration to indicate this is reasonable. I suppose > that I can make that change separately. Yes, except that in the apple case, those functions are provided by another TU (Unwind_AppleExtras.cpp). So in that case, those functions only should be static in the non-apple case. https://reviews.llvm.org/D38250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38250: [libunwind] Implement the Get/SetTopOfFunctionStack functions via a __thread TLS variable
mstorsjo abandoned this revision. mstorsjo added a comment. Works fine with the version from r314632 (with a minor fixup in r314635). https://reviews.llvm.org/D38250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38380: [libunwind] Add CMake support for building for MinGW
This revision was automatically updated to reflect the committed changes. Closed by commit rL314716: Add CMake support for building for MinGW (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38380?vs=117046&id=117417#toc Repository: rL LLVM https://reviews.llvm.org/D38380 Files: libunwind/trunk/cmake/config-ix.cmake Index: libunwind/trunk/cmake/config-ix.cmake === --- libunwind/trunk/cmake/config-ix.cmake +++ libunwind/trunk/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: libunwind/trunk/cmake/config-ix.cmake === --- libunwind/trunk/cmake/config-ix.cmake +++ libunwind/trunk/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 () ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38576: |libunwind] [docs] Mention that SjLj works on any OS on the archs where supported by the compiler
mstorsjo created this revision. https://reviews.llvm.org/D38576 Files: docs/index.rst Index: docs/index.rst === --- docs/index.rst +++ docs/index.rst @@ -50,6 +50,7 @@ LinuxARM Clang, GCC EHABI Bare Metal ARM Clang, GCC EHABI NetBSD x86_64 Clang, GCC DWARF CFI +Any i386, x86_64, ARMClangSjLj The following minimum compiler versions are strongly recommended. Index: docs/index.rst === --- docs/index.rst +++ docs/index.rst @@ -50,6 +50,7 @@ LinuxARM Clang, GCC EHABI Bare Metal ARM Clang, GCC EHABI NetBSD x86_64 Clang, GCC DWARF CFI +Any i386, x86_64, ARMClangSjLj The following minimum compiler versions are strongly recommended. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38576: |libunwind] [docs] Mention that SjLj works on any OS on the archs where supported by the compiler
This revision was automatically updated to reflect the committed changes. Closed by commit rL315090: [docs] Mention that SjLj works on any OS on the archs where supported by the… (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38576?vs=117778&id=118054#toc Repository: rL LLVM https://reviews.llvm.org/D38576 Files: libunwind/trunk/docs/index.rst Index: libunwind/trunk/docs/index.rst === --- libunwind/trunk/docs/index.rst +++ libunwind/trunk/docs/index.rst @@ -50,6 +50,7 @@ LinuxARM Clang, GCC EHABI Bare Metal ARM Clang, GCC EHABI NetBSD x86_64 Clang, GCC DWARF CFI +Any i386, x86_64, ARMClangSjLj The following minimum compiler versions are strongly recommended. Index: libunwind/trunk/docs/index.rst === --- libunwind/trunk/docs/index.rst +++ libunwind/trunk/docs/index.rst @@ -50,6 +50,7 @@ LinuxARM Clang, GCC EHABI Bare Metal ARM Clang, GCC EHABI NetBSD x86_64 Clang, GCC DWARF CFI +Any i386, x86_64, ARMClangSjLj The following minimum compiler versions are strongly recommended. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38680: [libunwind] Fix handling of DW_CFA_GNU_args_size
mstorsjo created this revision. This effectively reverts SVN r204290 and r204292 (back when this code was part of libcxxabi). According to SVN r204290, the primary architecture using the DW_CFA_GNU_args_size opcode is VAX. However, clang also produces it on X86 when it has done X86CallFrameOptimization, which gets done much more frequently if the stack is aligned to 4 bytes (which is the default when targeting windows). This issue can be tested by building code for x86 linux (at least for 32 bit) with clang with -mstack-alignment=4. I'm not sure if this code should be handled differently for VAX with some ifdef, or what the correct interpretation of this opcode is. I ran into this issue while trying to use libunwind for 32 bit windows (where clang uses a 4 byte stack alignment by default), found this commit, and noticed I got it working by reverting it. And later noticed I could reproduce the same issue on 32 bit x86 linux as well, by forcing -mstack-alignment=4. https://reviews.llvm.org/D38680 Files: src/UnwindCursor.hpp src/libunwind.cpp Index: src/libunwind.cpp === --- src/libunwind.cpp +++ src/libunwind.cpp @@ -182,8 +182,16 @@ co->setReg(regNum, (pint_t)value); // specical case altering IP to re-find info (being called by personality // function) -if (regNum == UNW_REG_IP) +if (regNum == UNW_REG_IP) { + unw_proc_info_t info; + co->getInfo(&info); + pint_t orgArgSize = (pint_t)info.gp; + uint64_t orgFuncStart = info.start_ip; co->setInfoBasedOnIPRegister(false); + // and adjust REG_SP if there was a DW_CFA_GNU_args_size + if ((orgFuncStart == info.start_ip) && (orgArgSize != 0)) +co->setReg(UNW_REG_SP, co->getReg(UNW_REG_SP) + orgArgSize); +} return UNW_ESUCCESS; } return UNW_EBADREG; Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -1356,8 +1356,6 @@ this->setInfoBasedOnIPRegister(true); if (_unwindInfoMissing) return UNW_STEP_END; -if (_info.gp) - setReg(UNW_REG_SP, getReg(UNW_REG_SP) + _info.gp); } return result; Index: src/libunwind.cpp === --- src/libunwind.cpp +++ src/libunwind.cpp @@ -182,8 +182,16 @@ co->setReg(regNum, (pint_t)value); // specical case altering IP to re-find info (being called by personality // function) -if (regNum == UNW_REG_IP) +if (regNum == UNW_REG_IP) { + unw_proc_info_t info; + co->getInfo(&info); + pint_t orgArgSize = (pint_t)info.gp; + uint64_t orgFuncStart = info.start_ip; co->setInfoBasedOnIPRegister(false); + // and adjust REG_SP if there was a DW_CFA_GNU_args_size + if ((orgFuncStart == info.start_ip) && (orgArgSize != 0)) +co->setReg(UNW_REG_SP, co->getReg(UNW_REG_SP) + orgArgSize); +} return UNW_ESUCCESS; } return UNW_EBADREG; Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -1356,8 +1356,6 @@ this->setInfoBasedOnIPRegister(true); if (_unwindInfoMissing) return UNW_STEP_END; -if (_info.gp) - setReg(UNW_REG_SP, getReg(UNW_REG_SP) + _info.gp); } return result; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo created this revision. This builds on some parts from https://reviews.llvm.org/D33601 - some of them were commented on before. This patch contains comments and explanations about those non-obvious parts. https://reviews.llvm.org/D38679 Files: docs/index.rst src/AddressSpace.hpp src/UnwindRegistersRestore.S src/assembly.h src/config.h Index: src/config.h === --- src/config.h +++ src/config.h @@ -37,6 +37,8 @@ #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif +#elif defined(_WIN32) + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -26,6 +26,14 @@ #if defined(__APPLE__) #define HIDDEN_DIRECTIVE .private_extern +#elif defined(_WIN32) +// In the COFF object file format, there's no attributes for a global, +// non-static symbol to make it somehow hidden. So on windows, we don't +// want to set this at all. To avoid conditionals in +// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already +// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the +// duplicate .globl directives are harmless). +#define HIDDEN_DIRECTIVE .globl #else #define HIDDEN_DIRECTIVE .hidden #endif Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -26,7 +26,12 @@ # + return address+ # +---+ <-- SP # + + +#if !defined(_WIN32) movl 4(%esp), %eax +#else + # On windows, the 'this' pointer is passed in ecx instead of on the stack + movl %ecx, %eax +#endif # set up eax and ret on new stack location movl 28(%eax), %edx # edx holds new stack pointer subl $8,%edx 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 @@ -97,7 +97,12 @@ // 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 +#else +#include +#include +#endif #if !defined(ElfW) #define ElfW(type) Elf_##type #endif @@ -356,6 +361,41 @@ info.arm_section, info.arm_section_length); if (info.arm_section && info.arm_section_length) return true; +#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) + HMODULE mods[1024]; + HANDLE process = GetCurrentProcess(); + DWORD needed; + + if (!EnumProcessModules(process, mods, sizeof(mods), &needed)) +return false; + + for (unsigned i = 0; i < (needed / sizeof(HMODULE)); i++) { +PIMAGE_DOS_HEADER pidh = (PIMAGE_DOS_HEADER)mods[i]; +PIMAGE_NT_HEADERS pinh = (PIMAGE_NT_HEADERS)((BYTE *)pidh + pidh->e_lfanew); +PIMAGE_FILE_HEADER pifh = (PIMAGE_FILE_HEADER)&pinh->FileHeader; +PIMAGE_SECTION_HEADER pish = IMAGE_FIRST_SECTION(pinh); +bool found_obj = false; +bool found_hdr = false; + +info.dso_base = (uintptr_t)mods[i]; +for (unsigned j = 0; j < pifh->NumberOfSections; j++, pish++) { + uintptr_t begin = pish->VirtualAddress + (uintptr_t)mods[i]; + uintptr_t end = begin + pish->Misc.VirtualSize; + if (!strncmp((const char *)pish->Name, ".text", + IMAGE_SIZEOF_SHORT_NAME)) { +if (targetAddr >= begin && targetAddr < end) + found_obj = true; + } else if (!strncmp((const char *)pish->Name, ".eh_frame", + IMAGE_SIZEOF_SHORT_NAME)) { +info.dwarf_section = begin; +info.dwarf_section_length = pish->Misc.VirtualSize; +found_hdr = true; + } + if (found_obj && found_hdr) +return true; +} + } + return false; #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) struct dl_iterate_cb_data { LocalAddressSpace *addressSpace; @@ -478,7 +518,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: docs/index.rst === --- docs/index.rst +++ docs/index.rst @@ -50,6 +50,7 @@ LinuxARM
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added inline comments. Comment at: src/AddressSpace.hpp:388-389 + found_obj = true; + } else if (!strncmp((const char *)pish->Name, ".eh_frame", + IMAGE_SIZEOF_SHORT_NAME)) { +info.dwarf_section = begin; rnk wrote: > ".eh_frame" is 9 characters, right? I thought mingw linkers took sections > with long names and moved them to an extended symbol table. Does that not > apply to .eh_frame? Yes, they do, so this actually only matches `.eh_fram`. I didn't yet look at how to navigate the IMAGE_*_HEADERS structs to find the coresponding full long name. https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added inline comments. Comment at: src/AddressSpace.hpp:521 unw_word_t *offset) { -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) Dl_info dyldInfo; jroelofs wrote: > Would it work to implement the win32 side of this via `SymFromAddr`? Hmm, I guess that would work. Comment at: src/UnwindRegistersRestore.S:29 # + + +#if !defined(_WIN32) movl 4(%esp), %eax jroelofs wrote: > Please invert the condition, and swap the if/else on this. That will make it > more straightforward to adjust this for other platforms later. Ok, will do. https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added inline comments. Comment at: src/AddressSpace.hpp:521 unw_word_t *offset) { -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) Dl_info dyldInfo; mstorsjo wrote: > jroelofs wrote: > > Would it work to implement the win32 side of this via `SymFromAddr`? > Hmm, I guess that would work. ... actually, I'm not sure how useful it is - it requires initializing the symbol handler with `SymInitialize` and point to a path to find the symbols. Plus that the symbol handler is single threaded and any calls to that would need to be guarded with a global mutex. So I think I'd defer that for now at least. https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo updated this revision to Diff 118263. mstorsjo added a comment. Added a fixme comment about the truncated section name, flipped the ifdef in the assembly source. Didn't implement findFunctionName. https://reviews.llvm.org/D38679 Files: docs/index.rst src/AddressSpace.hpp src/UnwindRegistersRestore.S src/assembly.h src/config.h Index: src/config.h === --- src/config.h +++ src/config.h @@ -37,6 +37,8 @@ #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif +#elif defined(_WIN32) + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -26,6 +26,14 @@ #if defined(__APPLE__) #define HIDDEN_DIRECTIVE .private_extern +#elif defined(_WIN32) +// In the COFF object file format, there's no attributes for a global, +// non-static symbol to make it somehow hidden. So on windows, we don't +// want to set this at all. To avoid conditionals in +// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already +// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the +// duplicate .globl directives are harmless). +#define HIDDEN_DIRECTIVE .globl #else #define HIDDEN_DIRECTIVE .hidden #endif Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -18,6 +18,10 @@ # # void libunwind::Registers_x86::jumpto() # +#if defined(_WIN32) +# On windows, the 'this' pointer is passed in ecx instead of on the stack + movl %ecx, %eax +#else # On entry: # + + # +---+ @@ -27,6 +31,7 @@ # +---+ <-- SP # + + movl 4(%esp), %eax +#endif # set up eax and ret on new stack location movl 28(%eax), %edx # edx holds new stack pointer subl $8,%edx 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 @@ -97,7 +97,12 @@ // 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 +#else +#include +#include +#endif #if !defined(ElfW) #define ElfW(type) Elf_##type #endif @@ -356,6 +361,43 @@ info.arm_section, info.arm_section_length); if (info.arm_section && info.arm_section_length) return true; +#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) + HMODULE mods[1024]; + HANDLE process = GetCurrentProcess(); + DWORD needed; + + if (!EnumProcessModules(process, mods, sizeof(mods), &needed)) +return false; + + for (unsigned i = 0; i < (needed / sizeof(HMODULE)); i++) { +PIMAGE_DOS_HEADER pidh = (PIMAGE_DOS_HEADER)mods[i]; +PIMAGE_NT_HEADERS pinh = (PIMAGE_NT_HEADERS)((BYTE *)pidh + pidh->e_lfanew); +PIMAGE_FILE_HEADER pifh = (PIMAGE_FILE_HEADER)&pinh->FileHeader; +PIMAGE_SECTION_HEADER pish = IMAGE_FIRST_SECTION(pinh); +bool found_obj = false; +bool found_hdr = false; + +info.dso_base = (uintptr_t)mods[i]; +for (unsigned j = 0; j < pifh->NumberOfSections; j++, pish++) { + uintptr_t begin = pish->VirtualAddress + (uintptr_t)mods[i]; + uintptr_t end = begin + pish->Misc.VirtualSize; + if (!strncmp((const char *)pish->Name, ".text", + IMAGE_SIZEOF_SHORT_NAME)) { +if (targetAddr >= begin && targetAddr < end) + found_obj = true; + } else if (!strncmp((const char *)pish->Name, ".eh_frame", + IMAGE_SIZEOF_SHORT_NAME)) { +// FIXME: This section name actually is truncated, ideally we +// should locate and check the full long name instead. +info.dwarf_section = begin; +info.dwarf_section_length = pish->Misc.VirtualSize; +found_hdr = true; + } + if (found_obj && found_hdr) +return true; +} + } + return false; #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) struct dl_iterate_cb_data { LocalAddressSpace *addressSpace; @@ -478,7 +520,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,
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added inline comments. Comment at: docs/index.rst:53 NetBSD x86_64 Clang, GCC DWARF CFI +Windows i386 ClangDWARF CFI Any i386, x86_64, ARMClangSjLj FWIW, for this to actually work correct which this docs change claims, this also depends on D38680. https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Emulate pthread rwlocks via SRW locks for windows
mstorsjo created this revision. Herald added a subscriber: mehdi_amini. This makes sure that the FDE cache is thread safe. This requires building with `_WIN32_WINNT >= 0x0600`. The alternative would be to skip the FDE cache altogether if building without threads. https://reviews.llvm.org/D38704 Files: src/UnwindCursor.hpp Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -17,7 +17,11 @@ #include #include #ifndef _LIBUNWIND_HAS_NO_THREADS - #include + #ifdef _WIN32 +#include + #else +#include + #endif #endif #include @@ -36,6 +40,34 @@ #include "Registers.hpp" #include "Unwind-EHABI.h" +#if !defined(_LIBUNWIND_HAS_NO_THREADS) && defined(_WIN32) +#define pthread_rwlock_t SRWLOCK +#define PTHREAD_RWLOCK_INITIALIZER SRWLOCK_INIT +// As long as these functions are only ever used with one lock, +// we can get away with a global flag to decide which kind of +// unlock to do. +static bool lockedForWrite = false; +static int pthread_rwlock_rdlock(pthread_rwlock_t *lock) { + AcquireSRWLockShared(lock); + lockedForWrite = false; + return 0; +} +static int pthread_rwlock_wrlock(pthread_rwlock_t *lock) { + AcquireSRWLockExclusive(lock); + lockedForWrite = true; + return 0; +} +static int pthread_rwlock_unlock(pthread_rwlock_t *lock) { + if (lockedForWrite) { +lockedForWrite = false; +ReleaseSRWLockExclusive(lock); + } else { +ReleaseSRWLockShared(lock); + } + return 0; +} +#endif + namespace libunwind { #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -17,7 +17,11 @@ #include #include #ifndef _LIBUNWIND_HAS_NO_THREADS - #include + #ifdef _WIN32 +#include + #else +#include + #endif #endif #include @@ -36,6 +40,34 @@ #include "Registers.hpp" #include "Unwind-EHABI.h" +#if !defined(_LIBUNWIND_HAS_NO_THREADS) && defined(_WIN32) +#define pthread_rwlock_t SRWLOCK +#define PTHREAD_RWLOCK_INITIALIZER SRWLOCK_INIT +// As long as these functions are only ever used with one lock, +// we can get away with a global flag to decide which kind of +// unlock to do. +static bool lockedForWrite = false; +static int pthread_rwlock_rdlock(pthread_rwlock_t *lock) { + AcquireSRWLockShared(lock); + lockedForWrite = false; + return 0; +} +static int pthread_rwlock_wrlock(pthread_rwlock_t *lock) { + AcquireSRWLockExclusive(lock); + lockedForWrite = true; + return 0; +} +static int pthread_rwlock_unlock(pthread_rwlock_t *lock) { + if (lockedForWrite) { +lockedForWrite = false; +ReleaseSRWLockExclusive(lock); + } else { +ReleaseSRWLockShared(lock); + } + return 0; +} +#endif + namespace libunwind { #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Emulate pthread rwlocks via SRW locks for windows
mstorsjo added a comment. In https://reviews.llvm.org/D38704#892479, @zturner wrote: > I'm a little nervous about re-inventing a poor man's version of a reader > writer lock. Can we not just copy LLVM's? I guess I could have a look to see how much extra either kitchen sink it would bring. Since it almost mapped 1:1 to the windows functions, I thought it wouldn't end up too large - unfortunately the return values and unlock functions made it a bit harder though. Comment at: src/UnwindCursor.hpp:20 #ifndef _LIBUNWIND_HAS_NO_THREADS - #include + #ifdef _WIN32 +#include zturner wrote: > Maybe you want to check `_MSC_VER` here? I think MinGW compilers will have > `pthread` support. MinGW compilers can have optional pthread support (it's not a feature of the compiler itself but an extra library that one can choose to build), but not everybody wants to use it and at least I wouldn't want to use it as mandatory dependency for any C++ support based on libunwind. Comment at: src/UnwindCursor.hpp:50 +static bool lockedForWrite = false; +static int pthread_rwlock_rdlock(pthread_rwlock_t *lock) { + AcquireSRWLockShared(lock); zturner wrote: > This doesn't seem like what you want. a global `static` function / variable > in a header file is going to be duplicated in every translation unit. i.e. > two translation units will have different copies of `lockedForWrite`. Same > goes for the rest of the functions. Oh, right - I would need to make it match the static class member `_lock` instead. Comment at: src/UnwindCursor.hpp:61-64 + if (lockedForWrite) { +lockedForWrite = false; +ReleaseSRWLockExclusive(lock); + } else { zturner wrote: > Doesn't `lockedForWrite` need to be atomic? If it is not atomic, there is no > guarantee that thread 2 will see the results of thread 1's modifications with > any kind of reasonable order. I don't think it needs to be atomic, although the `rdlock` function perhaps shouldn't touch it at all. It only ever gets set to true once we have an exclusive lock, and in those cases gets set back to false before the exclusive lock gets released. So without touching it in the `rdlock` function, we only ever write to it while holding the exclusive write lock. https://reviews.llvm.org/D38704 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38680: [libunwind] Fix handling of DW_CFA_GNU_args_size
mstorsjo added a comment. In https://reviews.llvm.org/D38680#892487, @compnerd wrote: > I think that the problem is that we are using the generic register name, but > we need to use the target specific register name. On x86, EIP/ESP are > swapped. You mean EBP/ESP? I think the code here does the right thing, with `UNW_REG_SP` always mapping to the actual ESP. > We should also have a test case for this. I had reduced this down to a > simpler test case of: > > void f(int,int,int,int,int,int,int,int,int); > > int main() { > try { > f(0,1,2,3,4,5,6,7,8); > } catch (int) { > return 0; > } > return 1; > } > Oh, great if you can reproduce the issue with that! Feel free to try to dig into the issue and figure out a better fix then. https://reviews.llvm.org/D38680 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added a comment. Are there any further comments on this, or can someone of those who commented on it before approve it? https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36111: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo added a comment. @mgrang, did you ever get to completing this? I've got a need for this now (only `__dmb` so far), and if you don't have time, I can try to finish it. https://reviews.llvm.org/D36111 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
mstorsjo added a comment. In https://reviews.llvm.org/D38679#894668, @jroelofs wrote: > LGTM Thanks, will push this one without the docs update since it's still buggy in practice on windows until https://reviews.llvm.org/D38680 gets resolved. https://reviews.llvm.org/D38679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36111: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo added a comment. In https://reviews.llvm.org/D36111#895084, @mgrang wrote: > Sorry, I never got to complete this as I moved to other priorities. I do not > think I have cycles to do this now. Please feel free to take over this patch > :) Ok - will do! Thanks for letting me know! https://reviews.llvm.org/D36111 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38679: [libunwind] Support dwarf unwinding on i386 windows
This revision was automatically updated to reflect the committed changes. Closed by commit rL315498: Support DWARF unwinding on i386 windows (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38679?vs=118263&id=118673#toc Repository: rL LLVM https://reviews.llvm.org/D38679 Files: libunwind/trunk/src/AddressSpace.hpp libunwind/trunk/src/UnwindRegistersRestore.S libunwind/trunk/src/assembly.h libunwind/trunk/src/config.h Index: libunwind/trunk/src/UnwindRegistersRestore.S === --- libunwind/trunk/src/UnwindRegistersRestore.S +++ libunwind/trunk/src/UnwindRegistersRestore.S @@ -18,6 +18,10 @@ # # void libunwind::Registers_x86::jumpto() # +#if defined(_WIN32) +# On windows, the 'this' pointer is passed in ecx instead of on the stack + movl %ecx, %eax +#else # On entry: # + + # +---+ @@ -27,6 +31,7 @@ # +---+ <-- SP # + + movl 4(%esp), %eax +#endif # set up eax and ret on new stack location movl 28(%eax), %edx # edx holds new stack pointer subl $8,%edx Index: libunwind/trunk/src/config.h === --- libunwind/trunk/src/config.h +++ libunwind/trunk/src/config.h @@ -37,6 +37,8 @@ #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif +#elif defined(_WIN32) + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: libunwind/trunk/src/AddressSpace.hpp === --- libunwind/trunk/src/AddressSpace.hpp +++ libunwind/trunk/src/AddressSpace.hpp @@ -18,7 +18,7 @@ #include #include -#ifndef _LIBUNWIND_IS_BAREMETAL +#if !defined(_LIBUNWIND_IS_BAREMETAL) && !defined(_WIN32) #include #endif @@ -97,7 +97,12 @@ // 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 +#else +#include +#include +#endif #if !defined(ElfW) #define ElfW(type) Elf_##type #endif @@ -356,6 +361,43 @@ info.arm_section, info.arm_section_length); if (info.arm_section && info.arm_section_length) return true; +#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32) + HMODULE mods[1024]; + HANDLE process = GetCurrentProcess(); + DWORD needed; + + if (!EnumProcessModules(process, mods, sizeof(mods), &needed)) +return false; + + for (unsigned i = 0; i < (needed / sizeof(HMODULE)); i++) { +PIMAGE_DOS_HEADER pidh = (PIMAGE_DOS_HEADER)mods[i]; +PIMAGE_NT_HEADERS pinh = (PIMAGE_NT_HEADERS)((BYTE *)pidh + pidh->e_lfanew); +PIMAGE_FILE_HEADER pifh = (PIMAGE_FILE_HEADER)&pinh->FileHeader; +PIMAGE_SECTION_HEADER pish = IMAGE_FIRST_SECTION(pinh); +bool found_obj = false; +bool found_hdr = false; + +info.dso_base = (uintptr_t)mods[i]; +for (unsigned j = 0; j < pifh->NumberOfSections; j++, pish++) { + uintptr_t begin = pish->VirtualAddress + (uintptr_t)mods[i]; + uintptr_t end = begin + pish->Misc.VirtualSize; + if (!strncmp((const char *)pish->Name, ".text", + IMAGE_SIZEOF_SHORT_NAME)) { +if (targetAddr >= begin && targetAddr < end) + found_obj = true; + } else if (!strncmp((const char *)pish->Name, ".eh_frame", + IMAGE_SIZEOF_SHORT_NAME)) { +// FIXME: This section name actually is truncated, ideally we +// should locate and check the full long name instead. +info.dwarf_section = begin; +info.dwarf_section_length = pish->Misc.VirtualSize; +found_hdr = true; + } + if (found_obj && found_hdr) +return true; +} + } + return false; #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) struct dl_iterate_cb_data { LocalAddressSpace *addressSpace; @@ -478,7 +520,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: libunwind/trunk/src/assembly.h === --- libunwind/trunk/src/assembly.h +++ libunwind/trunk/src/assembly.h @@ -26,6 +26,14 @@ #if defined(__APPLE__) #define HIDDEN_DIRECTIVE .private_extern +#elif defined(_WIN32) +// In the COFF object file format, there's no attributes for a global, +// non-static symbol to make it somehow hidden. S
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo created this revision. Herald added a subscriber: aprantl. Clang doesn't currently support building for windows/x86_64 with dwarf by setting command line parameters, but if manually modified to use dwarf, we can make libunwind work in this configuration as well. Even if support for this is deemed pointless, I guess one could omit the assembly changes, but the fixes for the generic code probably are worthwhile at least. https://reviews.llvm.org/D38819 Files: docs/index.rst include/unwind.h src/AddressSpace.hpp src/UnwindLevel1.c src/UnwindRegistersRestore.S src/UnwindRegistersSave.S Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -63,6 +63,27 @@ # thread_state pointer is in rdi # DEFINE_LIBUNWIND_FUNCTION(unw_getcontext) +#if defined(_WIN32) + movq %rax, (%rcx) + movq %rbx, 8(%rcx) + movq %rcx, 16(%rcx) + movq %rdx, 24(%rcx) + movq %rdi, 32(%rcx) + movq %rsi, 40(%rcx) + movq %rbp, 48(%rcx) + movq %rsp, 56(%rcx) + addq $8, 56(%rcx) + movq %r8, 64(%rcx) + movq %r9, 72(%rcx) + movq %r10, 80(%rcx) + movq %r11, 88(%rcx) + movq %r12, 96(%rcx) + movq %r13,104(%rcx) + movq %r14,112(%rcx) + movq %r15,120(%rcx) + movq (%rsp),%rdx + movq %rdx,128(%rcx) # store return address as rip +#else movq %rax, (%rdi) movq %rbx, 8(%rdi) movq %rcx, 16(%rdi) @@ -82,6 +103,7 @@ movq %r15,120(%rdi) movq (%rsp),%rsi movq %rsi,128(%rdi) # store return address as rip +#endif # skip rflags # skip cs # skip fs Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -65,6 +65,40 @@ # # void libunwind::Registers_x86_64::jumpto() # +#if defined(_WIN32) +# On entry, thread_state pointer is in rcx + + movq 56(%rcx), %rax # rax holds new stack pointer + subq $16, %rax + movq %rax, 56(%rcx) + movq 16(%rcx), %rdx # store new rcx on new stack + movq %rdx, 0(%rax) + movq 128(%rcx), %rdx # store new rip on new stack + movq %rdx, 8(%rax) + # restore all registers + movq0(%rcx), %rax + movq8(%rcx), %rbx + # restore rcx later + movq 24(%rcx), %rdx + movq 32(%rcx), %rdi + movq 40(%rcx), %rsi + movq 48(%rcx), %rbp + # restore rsp later + movq 64(%rcx), %r8 + movq 72(%rcx), %r9 + movq 80(%rcx), %r10 + movq 88(%rcx), %r11 + movq 96(%rcx), %r12 + movq 104(%rcx), %r13 + movq 112(%rcx), %r14 + movq 120(%rcx), %r15 + # skip rflags + # skip cs + # skip fs + # skip gs + movq 56(%rcx), %rsp # cut back rsp to new location + pop%rcx # rcx was saved here earlier +#else # On entry, thread_state pointer is in rdi movq 56(%rdi), %rax # rax holds new stack pointer @@ -97,6 +131,7 @@ # skip gs movq 56(%rdi), %rsp # cut back rsp to new location pop%rdi # rdi was saved here earlier +#endif ret# rip was saved here Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -86,7 +86,7 @@ // this frame. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); @@ -181,7 +181,7 @@ // If there is a personality routine, tell it we are unwinding. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _Unwind_Action action = _UA_CLEANUP_PHASE; if (sp == exception_object->private_2) { // Tell personality this was the frame it marked in phase 1. Index: src/AddressSpace.hpp === --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -142,7 +142,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 @@ -194,7 +194,7 @@ }; inline uintptr_t LocalAddressSpace::getP(pint_t addr) { -#ifdef __LP64__ +#if defined(__LP64__) || defined(_WIN64) return get64(addr); #else return get32(addr); 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 __LP
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added a comment. As further explanation/justification - libcxxabi and libunwind don't support SEH exceptions yet. https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38821: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo created this revision. Herald added subscribers: kristof.beyls, javed.absar, aemerson. This is an update to https://reviews.llvm.org/D36111 by @mgrang, taking over finishing of this patch. Compared to his version, this makes the intrinsics conditional to ALL_MS_LANGUAGES. https://reviews.llvm.org/D38821 Files: include/clang/Basic/BuiltinsAArch64.def lib/Basic/Targets/AArch64.cpp test/CodeGen/arm64-microsoft-intrinsics.c Index: test/CodeGen/arm64-microsoft-intrinsics.c === --- /dev/null +++ test/CodeGen/arm64-microsoft-intrinsics.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple arm64-windows -fms-compatibility -emit-llvm -o - %s \ +// RUN:| FileCheck %s -check-prefix CHECK-MSVC + +// RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-LINUX + +void check__dmb(void) { + __dmb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dmb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dmb' + +void check__dsb(void) { + __dsb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dsb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dsb' + +void check__isb(void) { + __isb(0); +} + +// CHECK-MSVC: @llvm.aarch64.isb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__isb' Index: lib/Basic/Targets/AArch64.cpp === --- lib/Basic/Targets/AArch64.cpp +++ lib/Basic/Targets/AArch64.cpp @@ -27,6 +27,8 @@ #define BUILTIN(ID, TYPE, ATTRS) \ {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) \ + {#ID, TYPE, ATTRS, nullptr, LANG, nullptr}, #include "clang/Basic/BuiltinsAArch64.def" }; Index: include/clang/Basic/BuiltinsAArch64.def === --- include/clang/Basic/BuiltinsAArch64.def +++ include/clang/Basic/BuiltinsAArch64.def @@ -14,6 +14,10 @@ // The format of this database matches clang/Basic/Builtins.def. +#if defined(BUILTIN) && !defined(LANGBUILTIN) +# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS) +#endif + // In libgcc BUILTIN(__clear_cache, "vv*v*", "i") @@ -61,4 +65,9 @@ BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc") BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc") +LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES) + #undef BUILTIN +#undef LANGBUILTIN Index: test/CodeGen/arm64-microsoft-intrinsics.c === --- /dev/null +++ test/CodeGen/arm64-microsoft-intrinsics.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple arm64-windows -fms-compatibility -emit-llvm -o - %s \ +// RUN:| FileCheck %s -check-prefix CHECK-MSVC + +// RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-LINUX + +void check__dmb(void) { + __dmb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dmb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dmb' + +void check__dsb(void) { + __dsb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dsb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dsb' + +void check__isb(void) { + __isb(0); +} + +// CHECK-MSVC: @llvm.aarch64.isb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__isb' Index: lib/Basic/Targets/AArch64.cpp === --- lib/Basic/Targets/AArch64.cpp +++ lib/Basic/Targets/AArch64.cpp @@ -27,6 +27,8 @@ #define BUILTIN(ID, TYPE, ATTRS) \ {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) \ + {#ID, TYPE, ATTRS, nullptr, LANG, nullptr}, #include "clang/Basic/BuiltinsAArch64.def" }; Index: include/clang/Basic/BuiltinsAArch64.def === --- include/clang/Basic/BuiltinsAArch64.def +++ include/clang/Basic/BuiltinsAArch64.def @@ -14,6 +14,10 @@ // The format of this database matches clang/Basic/Builtins.def. +#if defined(BUILTIN) && !defined(LANGBUILTIN) +# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS) +#endif + // In libgcc BUILTIN(__clear_cache, "vv*v*", "i") @@ -61,4 +65,9 @@ BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc") BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc") +LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES) + #undef BUILTIN +#undef LANGBUILTIN ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/c
[PATCH] D38680: [libunwind] Fix handling of DW_CFA_GNU_args_size
mstorsjo added inline comments. Comment at: src/libunwind.cpp:188 + co->getInfo(&info); + pint_t orgArgSize = (pint_t)info.gp; + uint64_t orgFuncStart = info.start_ip; rnk wrote: > I think it makes sense to have this here: the contract is that if the > personality sets the IP when the cursor pointed to a PC with a non-zero arg > size, we should adjust SP for the personality. > > However, it's not clear to me that we don't need the same adjustment when > stepping across frames that use arg size without a frame pointer. When stepping across frames, the gnu args size is already included in, as part of the CFA offset, so with the current code, it steps too far. https://reviews.llvm.org/D38680 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38821: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo added a comment. In https://reviews.llvm.org/D38821#895527, @compnerd wrote: > Don't you need a change to the intrinsics to actually map the builtin? Apparently, this change is all that's needed since the tests pass. I can of course try to look closer and see what actually makes it work. https://reviews.llvm.org/D38821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38821: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo added a comment. In https://reviews.llvm.org/D38821#895527, @compnerd wrote: > Don't you need a change to the intrinsics to actually map the builtin? This seems to be automatically mapped via this piece of code in CGBuiltin.cpp: // See if we have a target specific intrinsic. const char *Name = getContext().BuiltinInfo.getName(BuiltinID); Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; StringRef Prefix = llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch()); if (!Prefix.empty()) { IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix.data(), Name); // NOTE we dont need to perform a compatibility flag check here since the // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter the // MS builtins via ALL_MS_LANGUAGES and are filtered earlier. if (IntrinsicID == Intrinsic::not_intrinsic) IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix.data(), Name); } And these target specific intrinsics are already hooked up on the LLVM side in SVN r310502. https://reviews.llvm.org/D38821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38821: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
This revision was automatically updated to reflect the committed changes. Closed by commit rL315567: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38821?vs=118689&id=118747#toc Repository: rL LLVM https://reviews.llvm.org/D38821 Files: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def cfe/trunk/lib/Basic/Targets/AArch64.cpp cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c Index: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def === --- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def +++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def @@ -14,6 +14,10 @@ // The format of this database matches clang/Basic/Builtins.def. +#if defined(BUILTIN) && !defined(LANGBUILTIN) +# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS) +#endif + // In libgcc BUILTIN(__clear_cache, "vv*v*", "i") @@ -61,4 +65,9 @@ BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc") BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc") +LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES) + #undef BUILTIN +#undef LANGBUILTIN Index: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c === --- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c +++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple arm64-windows -fms-compatibility -emit-llvm -o - %s \ +// RUN:| FileCheck %s -check-prefix CHECK-MSVC + +// RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-LINUX + +void check__dmb(void) { + __dmb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dmb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dmb' + +void check__dsb(void) { + __dsb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dsb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dsb' + +void check__isb(void) { + __isb(0); +} + +// CHECK-MSVC: @llvm.aarch64.isb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__isb' Index: cfe/trunk/lib/Basic/Targets/AArch64.cpp === --- cfe/trunk/lib/Basic/Targets/AArch64.cpp +++ cfe/trunk/lib/Basic/Targets/AArch64.cpp @@ -27,6 +27,8 @@ #define BUILTIN(ID, TYPE, ATTRS) \ {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) \ + {#ID, TYPE, ATTRS, nullptr, LANG, nullptr}, #include "clang/Basic/BuiltinsAArch64.def" }; Index: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def === --- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def +++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def @@ -14,6 +14,10 @@ // The format of this database matches clang/Basic/Builtins.def. +#if defined(BUILTIN) && !defined(LANGBUILTIN) +# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS) +#endif + // In libgcc BUILTIN(__clear_cache, "vv*v*", "i") @@ -61,4 +65,9 @@ BUILTIN(__builtin_arm_wsr64, "vcC*LUi", "nc") BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc") +LANGBUILTIN(__dmb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__dsb, "vUi", "nc", ALL_MS_LANGUAGES) +LANGBUILTIN(__isb, "vUi", "nc", ALL_MS_LANGUAGES) + #undef BUILTIN +#undef LANGBUILTIN Index: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c === --- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c +++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple arm64-windows -fms-compatibility -emit-llvm -o - %s \ +// RUN:| FileCheck %s -check-prefix CHECK-MSVC + +// RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-LINUX + +void check__dmb(void) { + __dmb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dmb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dmb' + +void check__dsb(void) { + __dsb(0); +} + +// CHECK-MSVC: @llvm.aarch64.dsb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__dsb' + +void check__isb(void) { + __isb(0); +} + +// CHECK-MSVC: @llvm.aarch64.isb(i32 0) +// CHECK-LINUX: error: implicit declaration of function '__isb' Index: cfe/trunk/lib/Basic/Targets/AArch64.cpp === --- cfe/trunk/lib/Basic/Targets/AArch64.cpp +++ cfe/trunk/lib/Basic/Targets/AArch64.cpp @@ -27,6 +27,8 @@ #define BUILTIN(ID, TYPE, ATTRS) \ {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define LANGBUILTIN(ID, TYPE,
[PATCH] D36111: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo added a comment. This one can be abandoned now. https://reviews.llvm.org/D36111 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38900: libunwind: document tested FreeBSD configs and sort OS list
mstorsjo accepted this revision. mstorsjo added a comment. This revision is now accepted and ready to land. Seems ok to me, with whatever other architectures it's verified on as well. https://reviews.llvm.org/D38900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Emulate pthread rwlocks via SRW locks for windows
mstorsjo added a comment. In https://reviews.llvm.org/D38704#892479, @zturner wrote: > I'm a little nervous about re-inventing a poor man's version of a reader > writer lock. Can we not just copy LLVM's? I had a closer look at this, and noticed the following: - The LLVM RWMutex class on windows tries to load the SRW functions dynamically, and falls back on a normal critical section otherwise. This init procedure doesn't seem to be threadsafe though, but as long as the first RWMutex object is initialized before any extra threads are started, we should be fine. For libunwind, it would probably be done in a constructor on CRT startup. - Importing this implementation verbatim would require including one header, 3 implementation files, and probably some CMake hookups. - Until the LLVM relicensing is done, afaik we can't include code verbatim from LLVM into the runtime libs, or did I get this wrong? If you prefer, it's pretty trivial to do a smaller but similar implementation for libunwind though. If we add a new RWMutex class instead of using the pthread API (and implementing the windows version behind that API), we can have separate unlock methods for read and write mode, getting rid of the ugly `lockedForWrite` variable I currently have. And one could have it either just use SRW, or try loading SRW dynamically if that's preferred (if one wants to spend extra effort on libunwind on pre-vista). What do you think @zturner? https://reviews.llvm.org/D38704 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added inline comments. Comment at: include/unwind.h:125 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 compnerd wrote: > I think I would prefer that we do this generically as: > > #if __POINTER_WIDTH__ == 32 It seems like GCC doesn't set `__POINTER_WIDTH__`, but both GCC and clang set `__SIZEOF_POINTER__`, so I can use that. Comment at: src/AddressSpace.hpp:145 public: -#ifdef __LP64__ +#if defined(__LP64__) || defined(_WIN64) typedef uint64_t pint_t; compnerd wrote: > I think I prefer the generic: > > #if __POINTER_WIDTH__ == 64 This one probably could be simplified even further by just using `intptr_t` and `uintptr_t`, right? Comment at: src/UnwindRegistersRestore.S:68 # +#if defined(_WIN32) +# On entry, thread_state pointer is in rcx compnerd wrote: > This is confusing. Why is this `_WIN32`? Shouldn't this be `_WIN64`? I guess I could use that as well. I just used `_WIN32` out of habit as generic identifier for windows-in-whatever-form; both `_WIN32` and `_WIN64` are defined, and we're within an `#ifdef __x86_64__` anyway. I can change it into `_WIN64` for clarity. Comment at: src/UnwindRegistersRestore.S:72 + movq 56(%rcx), %rax # rax holds new stack pointer + subq $16, %rax + movq %rax, 56(%rcx) compnerd wrote: > Hmm, why is this `$16`? The `$rsp` was adjusted by `$8` in the `setjmp`. This is the exact same thing as is done right now for x86_64 on unixy systems already, just with different registers. The adjustment by 16 bytes is because we store `rcx` and `rip` on the stack here to restore them slightly differently than the others. See the `store new rcx/rip on new stack`, `restore rcx later` and `rcx was saved here earlier` and `rip was saved here` comments below. Comment at: src/UnwindRegistersSave.S:66 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext) +#if defined(_WIN32) + movq %rax, (%rcx) compnerd wrote: > Shouldn't this be `_WIN64`? Same as the otherone; we're within `#ifdef __x86_64__`, but I can change it into `_WIN64` for clarity. https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo updated this revision to Diff 119068. mstorsjo added a comment. Use `__SIZEOF_POINTER__` instead of checking `__LP64__` together with `_WIN64`. Changed `_WIN32` into `_WIN64` within the assembly sources for consistency/clarity. Removed one type definition ifdef by just using `(u)intptr_t` instead. https://reviews.llvm.org/D38819 Files: docs/index.rst include/unwind.h src/AddressSpace.hpp src/UnwindLevel1.c src/UnwindRegistersRestore.S src/UnwindRegistersSave.S Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -63,6 +63,27 @@ # thread_state pointer is in rdi # DEFINE_LIBUNWIND_FUNCTION(unw_getcontext) +#if defined(_WIN64) + movq %rax, (%rcx) + movq %rbx, 8(%rcx) + movq %rcx, 16(%rcx) + movq %rdx, 24(%rcx) + movq %rdi, 32(%rcx) + movq %rsi, 40(%rcx) + movq %rbp, 48(%rcx) + movq %rsp, 56(%rcx) + addq $8, 56(%rcx) + movq %r8, 64(%rcx) + movq %r9, 72(%rcx) + movq %r10, 80(%rcx) + movq %r11, 88(%rcx) + movq %r12, 96(%rcx) + movq %r13,104(%rcx) + movq %r14,112(%rcx) + movq %r15,120(%rcx) + movq (%rsp),%rdx + movq %rdx,128(%rcx) # store return address as rip +#else movq %rax, (%rdi) movq %rbx, 8(%rdi) movq %rcx, 16(%rdi) @@ -82,6 +103,7 @@ movq %r15,120(%rdi) movq (%rsp),%rsi movq %rsi,128(%rdi) # store return address as rip +#endif # skip rflags # skip cs # skip fs Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -65,6 +65,40 @@ # # void libunwind::Registers_x86_64::jumpto() # +#if defined(_WIN64) +# On entry, thread_state pointer is in rcx + + movq 56(%rcx), %rax # rax holds new stack pointer + subq $16, %rax + movq %rax, 56(%rcx) + movq 16(%rcx), %rdx # store new rcx on new stack + movq %rdx, 0(%rax) + movq 128(%rcx), %rdx # store new rip on new stack + movq %rdx, 8(%rax) + # restore all registers + movq0(%rcx), %rax + movq8(%rcx), %rbx + # restore rcx later + movq 24(%rcx), %rdx + movq 32(%rcx), %rdi + movq 40(%rcx), %rsi + movq 48(%rcx), %rbp + # restore rsp later + movq 64(%rcx), %r8 + movq 72(%rcx), %r9 + movq 80(%rcx), %r10 + movq 88(%rcx), %r11 + movq 96(%rcx), %r12 + movq 104(%rcx), %r13 + movq 112(%rcx), %r14 + movq 120(%rcx), %r15 + # skip rflags + # skip cs + # skip fs + # skip gs + movq 56(%rcx), %rsp # cut back rsp to new location + pop%rcx # rcx was saved here earlier +#else # On entry, thread_state pointer is in rdi movq 56(%rdi), %rax # rax holds new stack pointer @@ -97,6 +131,7 @@ # skip gs movq 56(%rdi), %rsp # cut back rsp to new location pop%rdi # rdi was saved here earlier +#endif ret# rip was saved here Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -86,7 +86,7 @@ // this frame. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); @@ -181,7 +181,7 @@ // If there is a personality routine, tell it we are unwinding. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _Unwind_Action action = _UA_CLEANUP_PHASE; if (sp == exception_object->private_2) { // Tell personality this was the frame it marked in phase 1. Index: src/AddressSpace.hpp === --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -142,13 +142,8 @@ /// making local unwinds fast. class __attribute__((visibility("hidden"))) LocalAddressSpace { public: -#ifdef __LP64__ - typedef uint64_t pint_t; - typedef int64_t sint_t; -#else - typedef uint32_t pint_t; - typedef int32_t sint_t; -#endif + typedef uintptr_t pint_t; + typedef intptr_t sint_t; uint8_t get8(pint_t addr) { uint8_t val; memcpy(&val, (void *)addr, sizeof(val)); @@ -194,7 +189,7 @@ }; inline uintptr_t LocalAddressSpace::getP(pint_t addr) { -#ifdef __LP64__ +#if __SIZEOF_POINTER__ == 8 return get64(addr); #else return get32(addr); 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
[PATCH] D38704: [libunwind] Emulate pthread rwlocks via SRW locks for windows
mstorsjo added a comment. In https://reviews.llvm.org/D38704#897935, @majnemer wrote: > I don't think we should depend on LLVM for the locking stuff. This sort of > infrastructure is in the same bucket as the demangler which we haven't really > solved. > > I *do* find it weird to do it this way though. I think you should have some > mutex functions which include read/write unlock. This way you don't need the > weird state. Ok, sure. I can add a new class with an API similar to the one in LLVM, but only the bare essentials (i.e. exactly what libunwind has got right now, plus SRW locks for windows) for now. https://reviews.llvm.org/D38704 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added inline comments. Comment at: docs/index.rst:55 NetBSD x86_64 Clang, GCC DWARF CFI -Windows i386 ClangDWARF CFI +Windows i386, x86_64 ClangDWARF CFI martell wrote: > Based on your comments above I assume this supports GCC also ? > If so, replace > `Windows i386, x86_64 ClangDWARF CFI` > with > `Windows i386, x86_64 Clang, GCC DWARF CFI` > > This is exciting stuff Martin :) I'm not sure if gcc supports dwarf exceptions on x86_64 or how much hacking is needed to enable it; the comment about gcc for `__SIZEOF_POINTER__` was because it was in generic code that could be used by gcc in one of the existing cases where gcc actually is supported. https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows
mstorsjo updated this revision to Diff 119094. mstorsjo retitled this revision from "[libunwind] Emulate pthread rwlocks via SRW locks for windows" to "[libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows". mstorsjo edited the summary of this revision. mstorsjo added reviewers: majnemer, zturner. mstorsjo removed subscribers: majnemer, zturner. mstorsjo added a comment. Herald added a subscriber: mgorny. Instead of trying to emulate the pthread rwlocks api with windows implementations, add a RWMutex class (with an interface similar to SmartRWMutex from LLVM) with inline implementations, which can either be no-ops (for no-threads configurations), implemented with SRW locks for windows or pthreads. https://reviews.llvm.org/D38704 Files: src/CMakeLists.txt src/RWMutex.hpp src/UnwindCursor.hpp src/config.h Index: src/config.h === --- src/config.h +++ src/config.h @@ -93,20 +93,15 @@ fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__) #endif -#if defined(_LIBUNWIND_HAS_NO_THREADS) - // only used with pthread calls, not needed for the single-threaded builds - #define _LIBUNWIND_LOG_NON_ZERO(x) +#if defined(NDEBUG) + #define _LIBUNWIND_LOG_IF_FALSE(x) x #else - #if defined(NDEBUG) -#define _LIBUNWIND_LOG_NON_ZERO(x) x - #else -#define _LIBUNWIND_LOG_NON_ZERO(x) \ - do { \ -int _err = x; \ -if (_err != 0) \ - _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \ - } while (0) - #endif + #define _LIBUNWIND_LOG_IF_FALSE(x) \ +do { \ + bool _ret = x; \ + if (!_ret) \ +_LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \ +} while (0) #endif // Macros that define away in non-Debug builds Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -16,9 +16,6 @@ #include #include #include -#ifndef _LIBUNWIND_HAS_NO_THREADS - #include -#endif #include #ifdef __APPLE__ @@ -34,6 +31,7 @@ #include "EHHeaderParser.hpp" #include "libunwind.h" #include "Registers.hpp" +#include "RWMutex.hpp" #include "Unwind-EHABI.h" namespace libunwind { @@ -62,9 +60,7 @@ // These fields are all static to avoid needing an initializer. // There is only one instance of this class per process. -#ifndef _LIBUNWIND_HAS_NO_THREADS - static pthread_rwlock_t _lock; -#endif + static RWMutex _lock; #ifdef __APPLE__ static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide); static bool _registeredForDyldUnloads; @@ -91,10 +87,8 @@ template typename DwarfFDECache::entry DwarfFDECache::_initialBuffer[64]; -#ifndef _LIBUNWIND_HAS_NO_THREADS template -pthread_rwlock_t DwarfFDECache::_lock = PTHREAD_RWLOCK_INITIALIZER; -#endif +RWMutex DwarfFDECache::_lock; #ifdef __APPLE__ template @@ -104,24 +98,24 @@ template typename A::pint_t DwarfFDECache::findFDE(pint_t mh, pint_t pc) { pint_t result = 0; - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_rdlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared()); for (entry *p = _buffer; p < _bufferUsed; ++p) { if ((mh == p->mh) || (mh == 0)) { if ((p->ip_start <= pc) && (pc < p->ip_end)) { result = p->fde; break; } } } - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_unlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.unlock_shared()); return result; } template void DwarfFDECache::add(pint_t mh, pint_t ip_start, pint_t ip_end, pint_t fde) { #if !defined(_LIBUNWIND_NO_HEAP) - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_wrlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.lock()); if (_bufferUsed >= _bufferEnd) { size_t oldSize = (size_t)(_bufferEnd - _buffer); size_t newSize = oldSize * 4; @@ -145,13 +139,13 @@ _registeredForDyldUnloads = true; } #endif - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_unlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.unlock()); #endif } template void DwarfFDECache::removeAllIn(pint_t mh) { - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_wrlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.lock()); entry *d = _buffer; for (const entry *s = _buffer; s < _bufferUsed; ++s) { if (s->mh != mh) { @@ -161,7 +155,7 @@ } } _bufferUsed = d; - _LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_unlock(&_lock)); + _LIBUNWIND_LOG_IF_FALSE(_lock.unlock()); }
[PATCH] D38680: [libunwind] Fix handling of DW_CFA_GNU_args_size
mstorsjo added a comment. In https://reviews.llvm.org/D38680#901892, @dtzWill wrote: > Wow, I've finally debugged some unwind failures to this on x86_64 Linux ... > > 1. Call-frame optimization introduces it > 2. This fixes the cases I was investigating!! That's good to hear! FWIW, I've talked to @joerg off-list and he said he'll try to look into it soon. https://reviews.llvm.org/D38680 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows
mstorsjo added a comment. Ping @zturner and others https://reviews.llvm.org/D38704 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added a comment. Ping https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39156: [libunwind] Make HIDDEN_DIRECTIVE a function-like macro. NFCI.
mstorsjo created this revision. This avoids a hack for making it a no-op for windows. Also explicitly check for `_WIN32` instead of asduming it. https://reviews.llvm.org/D39156 Files: src/assembly.h Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -24,27 +24,14 @@ #define SEPARATOR ; #endif -#if defined(__APPLE__) -#define HIDDEN_DIRECTIVE .private_extern -#elif defined(_WIN32) -// In the COFF object file format, there's no attributes for a global, -// non-static symbol to make it somehow hidden. So on windows, we don't -// want to set this at all. To avoid conditionals in -// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already -// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the -// duplicate .globl directives are harmless). -#define HIDDEN_DIRECTIVE .globl -#else -#define HIDDEN_DIRECTIVE .hidden -#endif - #define GLUE2(a, b) a ## b #define GLUE(a, b) GLUE2(a, b) #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE #elif defined(__ELF__) @@ -54,24 +41,30 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ defined(__linux__) #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits #else #define NO_EXEC_STACK_DIRECTIVE #endif -#else +#elif defined(_WIN32) #define SYMBOL_IS_FUNC(name) \ .def name SEPARATOR \ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE +#else + +#error Unsupported target + #endif #define DEFINE_LIBUNWIND_FUNCTION(name) \ @@ -81,7 +74,7 @@ #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ - HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR\ + HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_NAME(name): Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -24,27 +24,14 @@ #define SEPARATOR ; #endif -#if defined(__APPLE__) -#define HIDDEN_DIRECTIVE .private_extern -#elif defined(_WIN32) -// In the COFF object file format, there's no attributes for a global, -// non-static symbol to make it somehow hidden. So on windows, we don't -// want to set this at all. To avoid conditionals in -// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already -// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the -// duplicate .globl directives are harmless). -#define HIDDEN_DIRECTIVE .globl -#else -#define HIDDEN_DIRECTIVE .hidden -#endif - #define GLUE2(a, b) a ## b #define GLUE(a, b) GLUE2(a, b) #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE #elif defined(__ELF__) @@ -54,24 +41,30 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ defined(__linux__) #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits #else #define NO_EXEC_STACK_DIRECTIVE #endif -#else +#elif defined(_WIN32) #define SYMBOL_IS_FUNC(name) \ .def name SEPARATOR \ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE +#else + +#error Unsupported target + #endif #define DEFINE_LIBUNWIND_FUNCTION(name) \ @@ -81,7 +74,7 @@ #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ - HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR\ + HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_NAME(name): ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39127: Fix template parameter default args missed if redecled
mstorsjo added inline comments. Comment at: lib/Sema/SemaTemplate.cpp:4808 + // Make sure we get the template parameter list from the most + // recentdeclaration, since that is the only one that has is guaranteed to + // have all the default template argument information. Typo in "recentdeclaration" Comment at: lib/Sema/SemaTemplate.cpp:4811 + TemplateParameterList *Params = + cast(Template->getMostRecentDecl()) + ->getTemplateParameters(); How does this work if there's another forward declaration missing the parameter later? Is the logic with "most recent" ok, or should it be "most qualified/complete" instead? https://reviews.llvm.org/D39127 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39127: Fix template parameter default args missed if redecled
mstorsjo added inline comments. Comment at: lib/Sema/SemaTemplate.cpp:4811 + TemplateParameterList *Params = + cast(Template->getMostRecentDecl()) + ->getTemplateParameters(); erichkeane wrote: > mstorsjo wrote: > > How does this work if there's another forward declaration missing the > > parameter later? Is the logic with "most recent" ok, or should it be "most > > qualified/complete" instead? > I'm not sure the case you mean. Any future declarations with fewer > parameters would be aspecialization and a different decl, right? Sorry, I meant a declaration with fewer defaults. E.g. the original forward declaration without defaults again after the actual definition. E.g. by adding ``` namespace llvm { template struct StringSet; } ``` before the last `namespace lld`. https://reviews.llvm.org/D39127 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39156: [libunwind] Make HIDDEN_DIRECTIVE a function-like macro. NFCI.
This revision was automatically updated to reflect the committed changes. Closed by commit rL316300: Make HIDDEN_DIRECTIVE a function-like macro. NFCI. (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D39156?vs=119740&id=119792#toc Repository: rL LLVM https://reviews.llvm.org/D39156 Files: libunwind/trunk/src/assembly.h Index: libunwind/trunk/src/assembly.h === --- libunwind/trunk/src/assembly.h +++ libunwind/trunk/src/assembly.h @@ -24,27 +24,14 @@ #define SEPARATOR ; #endif -#if defined(__APPLE__) -#define HIDDEN_DIRECTIVE .private_extern -#elif defined(_WIN32) -// In the COFF object file format, there's no attributes for a global, -// non-static symbol to make it somehow hidden. So on windows, we don't -// want to set this at all. To avoid conditionals in -// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already -// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the -// duplicate .globl directives are harmless). -#define HIDDEN_DIRECTIVE .globl -#else -#define HIDDEN_DIRECTIVE .hidden -#endif - #define GLUE2(a, b) a ## b #define GLUE(a, b) GLUE2(a, b) #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE #elif defined(__ELF__) @@ -54,24 +41,30 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ defined(__linux__) #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits #else #define NO_EXEC_STACK_DIRECTIVE #endif -#else +#elif defined(_WIN32) #define SYMBOL_IS_FUNC(name) \ .def name SEPARATOR \ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE +#else + +#error Unsupported target + #endif #define DEFINE_LIBUNWIND_FUNCTION(name) \ @@ -81,7 +74,7 @@ #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ - HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR\ + HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_NAME(name): Index: libunwind/trunk/src/assembly.h === --- libunwind/trunk/src/assembly.h +++ libunwind/trunk/src/assembly.h @@ -24,27 +24,14 @@ #define SEPARATOR ; #endif -#if defined(__APPLE__) -#define HIDDEN_DIRECTIVE .private_extern -#elif defined(_WIN32) -// In the COFF object file format, there's no attributes for a global, -// non-static symbol to make it somehow hidden. So on windows, we don't -// want to set this at all. To avoid conditionals in -// DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already -// is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the -// duplicate .globl directives are harmless). -#define HIDDEN_DIRECTIVE .globl -#else -#define HIDDEN_DIRECTIVE .hidden -#endif - #define GLUE2(a, b) a ## b #define GLUE(a, b) GLUE2(a, b) #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE #elif defined(__ELF__) @@ -54,24 +41,30 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ defined(__linux__) #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits #else #define NO_EXEC_STACK_DIRECTIVE #endif -#else +#elif defined(_WIN32) #define SYMBOL_IS_FUNC(name) \ .def name SEPARATOR \ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE +#else + +#error Unsupported target + #endif #define DEFINE_LIBUNWIND_FUNCTION(name) \ @@ -81,7 +74,7 @@ #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ - HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR\ + HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added inline comments. Comment at: src/UnwindRegistersRestore.S:98 + # skip fs + # skip gs + movq 56(%rcx), %rsp # cut back rsp to new location compnerd wrote: > Doesn't Win64 ABI require some of the MMX registers be saved/restored too? Right, yes, xmm6-xmm15 should be backed up and restored. I'll try to amend this with such a change. https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39127: Fix template parameter default args missed if redecled
mstorsjo added inline comments. Comment at: lib/Sema/SemaTemplate.cpp:4811 + TemplateParameterList *Params = + cast(Template->getMostRecentDecl()) + ->getTemplateParameters(); erichkeane wrote: > mstorsjo wrote: > > erichkeane wrote: > > > mstorsjo wrote: > > > > How does this work if there's another forward declaration missing the > > > > parameter later? Is the logic with "most recent" ok, or should it be > > > > "most qualified/complete" instead? > > > I'm not sure the case you mean. Any future declarations with fewer > > > parameters would be aspecialization and a different decl, right? > > Sorry, I meant a declaration with fewer defaults. E.g. the original forward > > declaration without defaults again after the actual definition. > > > > E.g. by adding > > > > ``` > > namespace llvm { > > template struct StringSet; > > } > > ``` > > before the last `namespace lld`. > > > > > I think thats OK. The code propagates those forward. The problem here is > that it does NOT propagate them backwards. Ok then, then I guess it sounds fine to me, although I'm very much not familiar with this code. So I'm not comfortable with giving it a formal approval. https://reviews.llvm.org/D39127 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added inline comments. Comment at: src/UnwindRegistersRestore.S:98 + # skip fs + # skip gs + movq 56(%rcx), %rsp # cut back rsp to new location mstorsjo wrote: > compnerd wrote: > > Doesn't Win64 ABI require some of the MMX registers be saved/restored too? > Right, yes, xmm6-xmm15 should be backed up and restored. I'll try to amend > this with such a change. Actually, such a change doesn't necessarily make much sense on its own. As long as the dwarf encoding itself doesn't describe how to restore those registers (and on unix platforms you don't need to, so it probably isn't even specified), you'd just end up backing up the xmm registers on entry when throwing the exception, and restoring the exactly same ones again - it only guards against changes within libcxxabi/libunwind and the unwinding machinery itself, not against changes further down in the call stack between the thrower and catcher of the exception. So with that, I guess this patch is futile unless planning to extend the x86_64 dwarf handling in llvm to include those registers as well - and that's a little out of scope of what I intended to do here... https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38704: [libunwind] Abstract rwlocks into a class, provide a SRW lock implementation for windows
This revision was automatically updated to reflect the committed changes. Closed by commit rL316364: Abstract rwlocks into a class, provide a SRW lock implementation for windows (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D38704?vs=119094&id=119914#toc Repository: rL LLVM https://reviews.llvm.org/D38704 Files: libunwind/trunk/src/CMakeLists.txt libunwind/trunk/src/RWMutex.hpp libunwind/trunk/src/UnwindCursor.hpp libunwind/trunk/src/config.h Index: libunwind/trunk/src/CMakeLists.txt === --- libunwind/trunk/src/CMakeLists.txt +++ libunwind/trunk/src/CMakeLists.txt @@ -30,6 +30,7 @@ DwarfParser.hpp libunwind_ext.h Registers.hpp +RWMutex.hpp UnwindCursor.hpp ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h) Index: libunwind/trunk/src/RWMutex.hpp === --- libunwind/trunk/src/RWMutex.hpp +++ libunwind/trunk/src/RWMutex.hpp @@ -0,0 +1,77 @@ +//===- Registers.hpp --===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +// +// Abstract interface to shared reader/writer log, hiding platform and +// configuration differences. +// +//===--===// + +#ifndef __RWMUTEX_HPP__ +#define __RWMUTEX_HPP__ + +#if defined(_WIN32) +#include +#elif !defined(_LIBUNWIND_HAS_NO_THREADS) +#include +#endif + +namespace libunwind { + +#if defined(_LIBUNWIND_HAS_NO_THREADS) + +class _LIBUNWIND_HIDDEN RWMutex { +public: + bool lock_shared() { return true; } + bool unlock_shared() { return true; } + bool lock() { return true; } + bool unlock() { return true; } +}; + +#elif defined(_WIN32) + +class _LIBUNWIND_HIDDEN RWMutex { +public: + bool lock_shared() { +AcquireSRWLockShared(&_lock); +return true; + } + bool unlock_shared() { +ReleaseSRWLockShared(&_lock); +return true; + } + bool lock() { +AcquireSRWLockExclusive(&_lock); +return true; + } + bool unlock() { +ReleaseSRWLockExclusive(&_lock); +return true; + } + +private: + SRWLOCK _lock = SRWLOCK_INIT; +}; + +#else + +class _LIBUNWIND_HIDDEN RWMutex { +public: + bool lock_shared() { return pthread_rwlock_rdlock(&_lock) == 0; } + bool unlock_shared() { return pthread_rwlock_unlock(&_lock) == 0; } + bool lock() { return pthread_rwlock_wrlock(&_lock) == 0; } + bool unlock() { return pthread_rwlock_unlock(&_lock) == 0; } + +private: + pthread_rwlock_t _lock = PTHREAD_RWLOCK_INITIALIZER; +}; + +#endif + +} // namespace libunwind + +#endif // __RWMUTEX_HPP__ Index: libunwind/trunk/src/config.h === --- libunwind/trunk/src/config.h +++ libunwind/trunk/src/config.h @@ -93,20 +93,15 @@ fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__) #endif -#if defined(_LIBUNWIND_HAS_NO_THREADS) - // only used with pthread calls, not needed for the single-threaded builds - #define _LIBUNWIND_LOG_NON_ZERO(x) +#if defined(NDEBUG) + #define _LIBUNWIND_LOG_IF_FALSE(x) x #else - #if defined(NDEBUG) -#define _LIBUNWIND_LOG_NON_ZERO(x) x - #else -#define _LIBUNWIND_LOG_NON_ZERO(x) \ - do { \ -int _err = x; \ -if (_err != 0) \ - _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \ - } while (0) - #endif + #define _LIBUNWIND_LOG_IF_FALSE(x) \ +do { \ + bool _ret = x; \ + if (!_ret) \ +_LIBUNWIND_LOG("" #x " failed in %s", __FUNCTION__); \ +} while (0) #endif // Macros that define away in non-Debug builds Index: libunwind/trunk/src/UnwindCursor.hpp === --- libunwind/trunk/src/UnwindCursor.hpp +++ libunwind/trunk/src/UnwindCursor.hpp @@ -16,9 +16,6 @@ #include #include #include -#ifndef _LIBUNWIND_HAS_NO_THREADS - #include -#endif #include #ifdef __APPLE__ @@ -34,6 +31,7 @@ #include "EHHeaderParser.hpp" #include "libunwind.h" #include "Registers.hpp" +#include "RWMutex.hpp" #include "Unwind-EHABI.h" namespace libunwind { @@ -62,9 +60,7 @@ // These fields are all static to avoid needing an initializer. // There is only one instance
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo added inline comments. Comment at: src/UnwindRegistersRestore.S:98 + # skip fs + # skip gs + movq 56(%rcx), %rsp # cut back rsp to new location rnk wrote: > mstorsjo wrote: > > mstorsjo wrote: > > > compnerd wrote: > > > > Doesn't Win64 ABI require some of the MMX registers be saved/restored > > > > too? > > > Right, yes, xmm6-xmm15 should be backed up and restored. I'll try to > > > amend this with such a change. > > Actually, such a change doesn't necessarily make much sense on its own. > > > > As long as the dwarf encoding itself doesn't describe how to restore those > > registers (and on unix platforms you don't need to, so it probably isn't > > even specified), you'd just end up backing up the xmm registers on entry > > when throwing the exception, and restoring the exactly same ones again - it > > only guards against changes within libcxxabi/libunwind and the unwinding > > machinery itself, not against changes further down in the call stack > > between the thrower and catcher of the exception. > > > > So with that, I guess this patch is futile unless planning to extend the > > x86_64 dwarf handling in llvm to include those registers as well - and > > that's a little out of scope of what I intended to do here... > If we have XMM values in the register context, we might as well reload them > here. I assume libunwind will switch away from DWARF and over to UNWIND_INFO > opcodes in the near future, and that will give us an accurate register > context. Yeah, although to do anything useful with the XMM registers, the llvm backend would have to output dwarf opcodes for callee saved xmm registers, which it currently doesn't. Otherwise it'll just reload them back to the same values as they already are. I've managed to hack LLVM to do that (without fully understanding what I'm doing though), and I'll see if I manage to update libunwind to use that as well. https://reviews.llvm.org/D38819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39206: [libunwind] Add missing checks for register number
mstorsjo created this revision. Herald added a subscriber: JDevlieghere. Most other cases that touch `savedRegisters[reg]` have got this check, but these three seemed to lack it. https://reviews.llvm.org/D39206 Files: src/DwarfParser.hpp Index: src/DwarfParser.hpp === --- src/DwarfParser.hpp +++ src/DwarfParser.hpp @@ -605,6 +605,11 @@ break; case DW_CFA_val_offset: reg = addressSpace.getULEB128(p, instructionsEnd); + if (reg > kMaxRegisterNumber) { +fprintf(stderr, +"malformed DW_CFA_val_offset DWARF unwind, reg too big\n"); +return false; + } offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; @@ -668,6 +673,11 @@ switch (opcode & 0xC0) { case DW_CFA_offset: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, + "malformed DW_CFA_offset DWARF unwind, reg too big\n"); + return false; +} offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; @@ -682,6 +692,11 @@ break; case DW_CFA_restore: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, + "malformed DW_CFA_restore DWARF unwind, reg too big\n"); + return false; +} results->savedRegisters[reg] = initialState.savedRegisters[reg]; _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n", static_cast(operand)); Index: src/DwarfParser.hpp === --- src/DwarfParser.hpp +++ src/DwarfParser.hpp @@ -605,6 +605,11 @@ break; case DW_CFA_val_offset: reg = addressSpace.getULEB128(p, instructionsEnd); + if (reg > kMaxRegisterNumber) { +fprintf(stderr, +"malformed DW_CFA_val_offset DWARF unwind, reg too big\n"); +return false; + } offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; @@ -668,6 +673,11 @@ switch (opcode & 0xC0) { case DW_CFA_offset: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, + "malformed DW_CFA_offset DWARF unwind, reg too big\n"); + return false; +} offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; @@ -682,6 +692,11 @@ break; case DW_CFA_restore: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, + "malformed DW_CFA_restore DWARF unwind, reg too big\n"); + return false; +} results->savedRegisters[reg] = initialState.savedRegisters[reg]; _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n", static_cast(operand)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39206: [libunwind] Add missing checks for register number
This revision was automatically updated to reflect the committed changes. Closed by commit rL316415: Add missing checks for register number (authored by mstorsjo). Changed prior to commit: https://reviews.llvm.org/D39206?vs=119940&id=120001#toc Repository: rL LLVM https://reviews.llvm.org/D39206 Files: libunwind/trunk/src/DwarfParser.hpp Index: libunwind/trunk/src/DwarfParser.hpp === --- libunwind/trunk/src/DwarfParser.hpp +++ libunwind/trunk/src/DwarfParser.hpp @@ -605,6 +605,13 @@ break; case DW_CFA_val_offset: reg = addressSpace.getULEB128(p, instructionsEnd); + if (reg > kMaxRegisterNumber) { +fprintf(stderr, +"malformed DW_CFA_val_offset DWARF unwind, reg (%" PRIu64 +") out of range\n", +reg); +return false; + } offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; @@ -668,6 +675,12 @@ switch (opcode & 0xC0) { case DW_CFA_offset: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, "malformed DW_CFA_offset DWARF unwind, reg (%" PRIu64 + ") out of range\n", + reg); + return false; +} offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; @@ -682,6 +695,12 @@ break; case DW_CFA_restore: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, "malformed DW_CFA_restore DWARF unwind, reg (%" PRIu64 + ") out of range\n", + reg); + return false; +} results->savedRegisters[reg] = initialState.savedRegisters[reg]; _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n", static_cast(operand)); Index: libunwind/trunk/src/DwarfParser.hpp === --- libunwind/trunk/src/DwarfParser.hpp +++ libunwind/trunk/src/DwarfParser.hpp @@ -605,6 +605,13 @@ break; case DW_CFA_val_offset: reg = addressSpace.getULEB128(p, instructionsEnd); + if (reg > kMaxRegisterNumber) { +fprintf(stderr, +"malformed DW_CFA_val_offset DWARF unwind, reg (%" PRIu64 +") out of range\n", +reg); +return false; + } offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; @@ -668,6 +675,12 @@ switch (opcode & 0xC0) { case DW_CFA_offset: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, "malformed DW_CFA_offset DWARF unwind, reg (%" PRIu64 + ") out of range\n", + reg); + return false; +} offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; @@ -682,6 +695,12 @@ break; case DW_CFA_restore: reg = operand; +if (reg > kMaxRegisterNumber) { + fprintf(stderr, "malformed DW_CFA_restore DWARF unwind, reg (%" PRIu64 + ") out of range\n", + reg); + return false; +} results->savedRegisters[reg] = initialState.savedRegisters[reg]; _LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n", static_cast(operand)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39206: [libunwind] Add missing checks for register number
mstorsjo added a comment. In https://reviews.llvm.org/D39206#904723, @compnerd wrote: > I'd say out of range rather than too big. Ok, pushing with the message changed to out of range, and actually printing the value. Repository: rL LLVM https://reviews.llvm.org/D39206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36111: [COFF, ARM64] Add MS builtins __dmb, __dsb, __isb
mstorsjo abandoned this revision. mstorsjo added a comment. This was updated, finished and merged in https://reviews.llvm.org/D38821. https://reviews.llvm.org/D36111 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling
mstorsjo created this revision. Herald added subscribers: kristof.beyls, aprantl, aemerson. The previous definition of _LIBUNWIND_HIGHEST_DWARF_REGISTER seems to be a copy of the ARM64 value (introduced in SVN r276128); since the code actually hasn't compiled properly for arm in dwarf mode before, this hasn't actually been used. Set it to the correct value based on the UNW_ARM_* enum values. Use the same size for data types unw_word_t as for _LIBUNWIND_ARM_EHABI, to have the struct sizes match. This requires adding casts in a log line, where the data types (unw_word_t) implicitly were assumed be uint64_t. Normally mismatched printf formats aren't fatal (and might go unnoticed), unless a later parameter is interpreted as a string, when it becomes fatal. https://reviews.llvm.org/D39251 Files: include/__libunwind_config.h include/libunwind.h src/Registers.hpp src/UnwindCursor.hpp src/UnwindLevel1.c src/libunwind.cpp Index: src/libunwind.cpp === --- src/libunwind.cpp +++ src/libunwind.cpp @@ -55,7 +55,7 @@ # define REGISTER_KIND Registers_ppc #elif defined(__aarch64__) # define REGISTER_KIND Registers_arm64 -#elif defined(_LIBUNWIND_ARM_EHABI) +#elif defined(__arm__) # define REGISTER_KIND Registers_arm #elif defined(__or1k__) # define REGISTER_KIND Registers_or1k Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -78,8 +78,8 @@ _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "", - (void *)exception_object, pc, frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); + (void *)exception_object, (uint64_t)pc, (uint64_t)frameInfo.start_ip, functionName, + (uint64_t)frameInfo.lsda, (uint64_t)frameInfo.handler); } // If there is a personality routine, ask it if it will want to stop at Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -583,6 +583,12 @@ } #endif +#if defined(_LIBUNWIND_TARGET_ARM) + compact_unwind_encoding_t dwarfEncoding(Registers_arm &) const { +return 0; + } +#endif + #if defined (_LIBUNWIND_TARGET_OR1K) compact_unwind_encoding_t dwarfEncoding(Registers_or1k &) const { return 0; Index: src/Registers.hpp === --- src/Registers.hpp +++ src/Registers.hpp @@ -1326,7 +1326,7 @@ Registers_arm(const void *registers); boolvalidRegister(int num) const; - uint32_tgetRegister(int num); + uint32_tgetRegister(int num) const; voidsetRegister(int num, uint32_t value); boolvalidFloatRegister(int num) const; unw_fpreg_t getFloatRegister(int num); @@ -1339,6 +1339,7 @@ restoreSavedFloatRegisters(); restoreCoreAndJumpTo(); } + static int lastDwarfRegNum() { return 287; } uint32_t getSP() const { return _registers.__sp; } void setSP(uint32_t value) { _registers.__sp = value; } @@ -1473,7 +1474,7 @@ return false; } -inline uint32_t Registers_arm::getRegister(int regNum) { +inline uint32_t Registers_arm::getRegister(int regNum) const { if (regNum == UNW_REG_SP || regNum == UNW_ARM_SP) return _registers.__sp; Index: include/libunwind.h === --- include/libunwind.h +++ include/libunwind.h @@ -72,7 +72,7 @@ typedef struct unw_addr_space *unw_addr_space_t; typedef int unw_regnum_t; -#if defined(_LIBUNWIND_ARM_EHABI) +#if defined(_LIBUNWIND_ARM_EHABI) || defined(__ARM_DWARF_EH__) typedef uint32_t unw_word_t; typedef uint64_t unw_fpreg_t; #else Index: include/__libunwind_config.h === --- include/__libunwind_config.h +++ include/__libunwind_config.h @@ -45,7 +45,7 @@ #define _LIBUNWIND_CONTEXT_SIZE 42 #define _LIBUNWIND_CURSOR_SIZE 49 # endif -# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96 +# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 288 # elif defined(__or1k__) # define _LIBUNWIND_TARGET_OR1K 1 # define _LIBUNWIND_CONTEXT_SIZE 16 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling
mstorsjo added a comment. In https://reviews.llvm.org/D39251#906110, @compnerd wrote: > Whats the motivation for adding DWARF based unwinding on ARM? What > environment is using this? AFAIK NetBSD does. And my actual target is for MinGW/ARM; it seemed to be less effort to make libunwind work for ARM/DWARF than to make the COFF/ARM backend in LLVM output EHABI (but I might have been mistaken). Comment at: src/Registers.hpp:1342 } + static int lastDwarfRegNum() { return 287; } compnerd wrote: > Can we not use `_LIBUNWIND_HIGHEST_DWARF_REGISTER` here? I guess we could - we could do that consistently throughout all the `Registers_*` classes then. Or even omit the method at all and just check `_LIBUNWIND_HIGHEST_DWARF_REGISTER` in the caller? Or perhaps the last part clashes with part of the (incomplete afaik?) intended design to support unwinding foreign systems as well. Comment at: src/UnwindLevel1.c:79 _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "", compnerd wrote: > Please convert these to `%p` instead. The casting and conversion is kinda > ... unnecessary. Using `%p` wouldn't work when on 32 bit systems currently, while most of these fields are defined to be `uint64_t` except for the arm ehabi case. I guess I could look at how hard it would be to switch it to uint64_t for the arm/dwarf case as well. https://reviews.llvm.org/D39251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39280: [libunwind] Use uint64_t for unw_word_t in ARM EHABI
mstorsjo created this revision. Herald added subscribers: kristof.beyls, aprantl, aemerson. This reduces the differences between the EHABI and DWARF cases. This allows getting rid of some casts in _LIBUNWIND_TRACE_API log lines, making them match what's in UnwindLevel1.c for DWARF. The only non-obvious detail is in _Unwind_VRS_Get_Internal (called via _Unwind_VRS_Get), where a void pointer is assumed to be uint32_t or uintptr_t (depending on the caller); this can no longer use unw_word_t directly as before. https://reviews.llvm.org/D39280 Files: include/__libunwind_config.h include/libunwind.h src/Unwind-EHABI.cpp Index: src/Unwind-EHABI.cpp === --- src/Unwind-EHABI.cpp +++ src/Unwind-EHABI.cpp @@ -14,6 +14,7 @@ #if defined(_LIBUNWIND_ARM_EHABI) +#include #include #include #include @@ -468,11 +469,11 @@ unw_word_t pc; unw_get_reg(cursor, UNW_REG_IP, &pc); _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): pc=0x%llX, start_ip=0x%llX, func=%s, " - "lsda=0x%llX, personality=0x%llX", - static_cast(exception_object), (long long)pc, - (long long)frameInfo.start_ip, functionName, - (long long)frameInfo.lsda, (long long)frameInfo.handler); + "unwind_phase1(ex_ojb=%p): pc=0x%" PRIX64 ", start_ip=0x%" PRIX64 " func=%s, " + "lsda=0x" PRIX64 ", personality=0x" PRIX64 "", + static_cast(exception_object), pc, + frameInfo.start_ip, functionName, + frameInfo.lsda, frameInfo.handler); } // If there is a personality routine, ask it if it will want to stop at @@ -584,11 +585,11 @@ (frameInfo.start_ip + offset > frameInfo.end_ip)) functionName = ".anonymous."; _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): start_ip=0x%llX, func=%s, sp=0x%llX, " - "lsda=0x%llX, personality=0x%llX", - static_cast(exception_object), (long long)frameInfo.start_ip, - functionName, (long long)sp, (long long)frameInfo.lsda, - (long long)frameInfo.handler); + "unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIX64 " func=%s, sp=0x%" PRIX64 ", " + "lsda=0x%" PRIX64 ", personality=0x%" PRIX64 "", + static_cast(exception_object), frameInfo.start_ip, + functionName, sp, frameInfo.lsda, + frameInfo.handler); } // If there is a personality routine, tell it we are unwinding. @@ -627,9 +628,9 @@ unw_get_reg(cursor, UNW_REG_IP, &pc); unw_get_reg(cursor, UNW_REG_SP, &sp); _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering " - "user code with ip=0x%llX, sp=0x%llX", + "user code with ip=0x%" PRIX64 ", sp=0x%" PRIX64 "", static_cast(exception_object), - (long long)pc, (long long)sp); + pc, sp); } { @@ -727,8 +728,8 @@ if (unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) result = (uintptr_t)frameInfo.lsda; _LIBUNWIND_TRACE_API( - "_Unwind_GetLanguageSpecificData(context=%p) => 0x%llx", - static_cast(context), (long long)result); + "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIx64 "", + static_cast(context), result); return result; } @@ -765,7 +766,7 @@ if (representation != _UVRSD_UINT32 || regno > 15) return _UVRSR_FAILED; return unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno), - *(unw_word_t *)valuep) == UNW_ESUCCESS + *(uintptr_t *)valuep) == UNW_ESUCCESS ? _UVRSR_OK : _UVRSR_FAILED; case _UVRSC_VFP: @@ -789,7 +790,7 @@ if (representation != _UVRSD_UINT32 || regno > 3) return _UVRSR_FAILED; return unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_WC0 + regno), - *(unw_word_t *)valuep) == UNW_ESUCCESS + *(uintptr_t *)valuep) == UNW_ESUCCESS ? _UVRSR_OK : _UVRSR_FAILED; case _UVRSC_WMMXD: @@ -814,14 +815,18 @@ _Unwind_VRS_DataRepresentation representation, void *valuep) { unw_cursor_t *cursor = (unw_cursor_t *)context; + unw_word_t word; + _Unwind_VRS_Result ret; switch (regclass) { case _UVRSC_CORE: if (representation != _UVRSD_UINT32 || regno > 15) return _UVRSR_FAILED; - return unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno), - (unw_word_t *)valuep) == UNW_ESUCCESS + ret = unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno), + &word) == UNW_ESUCCESS ? _UVRSR_OK : _UVRSR_FAILED; + *(uintptr_t *)valuep = word; +
[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling
mstorsjo added inline comments. Comment at: src/UnwindLevel1.c:79 _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "", mstorsjo wrote: > compnerd wrote: > > Please convert these to `%p` instead. The casting and conversion is kinda > > ... unnecessary. > Using `%p` wouldn't work when on 32 bit systems currently, while most of > these fields are defined to be `uint64_t` except for the arm ehabi case. I > guess I could look at how hard it would be to switch it to uint64_t for the > arm/dwarf case as well. This part can be avoided if we consistently use unw_word_t == uint64_t, as done in D39280. https://reviews.llvm.org/D39251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39281: [libunwind] Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER
mstorsjo created this revision. This avoids having to keep the same information duplicated in multiple places. https://reviews.llvm.org/D39281 Files: src/Registers.hpp Index: src/Registers.hpp === --- src/Registers.hpp +++ src/Registers.hpp @@ -44,7 +44,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 8; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint32_t getSP() const { return _registers.__esp; } void setSP(uint32_t value) { _registers.__esp = value; } @@ -250,7 +250,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 16; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__rsp; } void setSP(uint64_t value) { _registers.__rsp = value; } @@ -500,7 +500,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 112; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__r1; } void setSP(uint32_t value) { _registers.__r1 = value; } @@ -1066,7 +1066,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 95; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__sp; } void setSP(uint64_t value) { _registers.__sp = value; } @@ -1815,7 +1815,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 31; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__r[1]; } void setSP(uint32_t value) { _registers.__r[1] = value; } Index: src/Registers.hpp === --- src/Registers.hpp +++ src/Registers.hpp @@ -44,7 +44,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 8; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint32_t getSP() const { return _registers.__esp; } void setSP(uint32_t value) { _registers.__esp = value; } @@ -250,7 +250,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 16; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__rsp; } void setSP(uint64_t value) { _registers.__rsp = value; } @@ -500,7 +500,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 112; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__r1; } void setSP(uint32_t value) { _registers.__r1 = value; } @@ -1066,7 +1066,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 95; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__sp; } void setSP(uint64_t value) { _registers.__sp = value; } @@ -1815,7 +1815,7 @@ voidsetVectorRegister(int num, v128 value); const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return 31; } + static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; } uint64_t getSP() const { return _registers.__r[1]; } void setSP(uint32_t value) { _registers.__r[1] = value; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling
mstorsjo added inline comments. Comment at: src/Registers.hpp:1342 } + static int lastDwarfRegNum() { return 287; } mstorsjo wrote: > compnerd wrote: > > Can we not use `_LIBUNWIND_HIGHEST_DWARF_REGISTER` here? > I guess we could - we could do that consistently throughout all the > `Registers_*` classes then. Or even omit the method at all and just check > `_LIBUNWIND_HIGHEST_DWARF_REGISTER` in the caller? Or perhaps the last part > clashes with part of the (incomplete afaik?) intended design to support > unwinding foreign systems as well. This gets taken care of for the existing ones in D39281 - if that one goes through I'll update this patch accordingly. https://reviews.llvm.org/D39251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64
mstorsjo updated this revision to Diff 120215. mstorsjo edited the summary of this revision. mstorsjo added a comment. Updated to take care of saving/restoring XMM registers as well. https://reviews.llvm.org/D38819 Files: docs/index.rst include/__libunwind_config.h include/libunwind.h include/unwind.h src/AddressSpace.hpp src/Registers.hpp src/UnwindLevel1.c src/UnwindRegistersRestore.S src/UnwindRegistersSave.S Index: src/UnwindRegistersSave.S === --- src/UnwindRegistersSave.S +++ src/UnwindRegistersSave.S @@ -63,6 +63,43 @@ # thread_state pointer is in rdi # DEFINE_LIBUNWIND_FUNCTION(unw_getcontext) +#if defined(_WIN64) + movq %rax, (%rcx) + movq %rbx, 8(%rcx) + movq %rcx, 16(%rcx) + movq %rdx, 24(%rcx) + movq %rdi, 32(%rcx) + movq %rsi, 40(%rcx) + movq %rbp, 48(%rcx) + movq %rsp, 56(%rcx) + addq $8, 56(%rcx) + movq %r8, 64(%rcx) + movq %r9, 72(%rcx) + movq %r10, 80(%rcx) + movq %r11, 88(%rcx) + movq %r12, 96(%rcx) + movq %r13,104(%rcx) + movq %r14,112(%rcx) + movq %r15,120(%rcx) + movq (%rsp),%rdx + movq %rdx,128(%rcx) # store return address as rip + movdqu %xmm0,168(%rcx) + movdqu %xmm1,184(%rcx) + movdqu %xmm2,200(%rcx) + movdqu %xmm3,216(%rcx) + movdqu %xmm4,232(%rcx) + movdqu %xmm5,248(%rcx) + movdqu %xmm6,264(%rcx) + movdqu %xmm7,280(%rcx) + movdqu %xmm8,296(%rcx) + movdqu %xmm9,312(%rcx) + movdqu %xmm10,328(%rcx) + movdqu %xmm11,344(%rcx) + movdqu %xmm12,360(%rcx) + movdqu %xmm13,376(%rcx) + movdqu %xmm14,392(%rcx) + movdqu %xmm15,408(%rcx) +#else movq %rax, (%rdi) movq %rbx, 8(%rdi) movq %rcx, 16(%rdi) @@ -82,6 +119,7 @@ movq %r15,120(%rdi) movq (%rsp),%rsi movq %rsi,128(%rdi) # store return address as rip +#endif # skip rflags # skip cs # skip fs Index: src/UnwindRegistersRestore.S === --- src/UnwindRegistersRestore.S +++ src/UnwindRegistersRestore.S @@ -65,6 +65,56 @@ # # void libunwind::Registers_x86_64::jumpto() # +#if defined(_WIN64) +# On entry, thread_state pointer is in rcx + + movq 56(%rcx), %rax # rax holds new stack pointer + subq $16, %rax + movq %rax, 56(%rcx) + movq 16(%rcx), %rdx # store new rcx on new stack + movq %rdx, 0(%rax) + movq 128(%rcx), %rdx # store new rip on new stack + movq %rdx, 8(%rax) + # restore all registers + movq0(%rcx), %rax + movq8(%rcx), %rbx + # restore rcx later + movq 24(%rcx), %rdx + movq 32(%rcx), %rdi + movq 40(%rcx), %rsi + movq 48(%rcx), %rbp + # restore rsp later + movq 64(%rcx), %r8 + movq 72(%rcx), %r9 + movq 80(%rcx), %r10 + movq 88(%rcx), %r11 + movq 96(%rcx), %r12 + movq 104(%rcx), %r13 + movq 112(%rcx), %r14 + movq 120(%rcx), %r15 + # skip rflags + # skip cs + # skip fs + # skip gs + movdqu 168(%rcx),%xmm0 + movdqu 184(%rcx),%xmm1 + movdqu 200(%rcx),%xmm2 + movdqu 216(%rcx),%xmm3 + movdqu 232(%rcx),%xmm4 + movdqu 248(%rcx),%xmm5 + movdqu 264(%rcx),%xmm6 + movdqu 280(%rcx),%xmm7 + movdqu 296(%rcx),%xmm8 + movdqu 312(%rcx),%xmm9 + movdqu 328(%rcx),%xmm10 + movdqu 344(%rcx),%xmm11 + movdqu 360(%rcx),%xmm12 + movdqu 376(%rcx),%xmm13 + movdqu 392(%rcx),%xmm14 + movdqu 408(%rcx),%xmm15 + movq 56(%rcx), %rsp # cut back rsp to new location + pop%rcx # rcx was saved here earlier +#else # On entry, thread_state pointer is in rdi movq 56(%rdi), %rax # rax holds new stack pointer @@ -97,6 +147,7 @@ # skip gs movq 56(%rdi), %rsp # cut back rsp to new location pop%rdi # rdi was saved here earlier +#endif ret# rip was saved here Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -86,7 +86,7 @@ // this frame. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase1(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); @@ -181,7 +181,7 @@ // If there is a personality routine, tell it we are unwinding. if (frameInfo.handler != 0) { __personality_routine p = - (__personality_routine)(long)(frameInfo.handler); + (__personality_routine)(uintptr_t)(frameInfo.handler); _Unwind_Action action = _UA_CLEANUP_PHASE; if (sp == exception_object->private_2) { // Tell personality this was the frame it marked in phase 1. Index: src/Registers.hpp === --- src/Registers.hpp +++ src/Registers.hpp @@ -245,12 +245,12 @@ boolvalidFloatRegister(int) const { return false; } double getFloatRegister(int num) const; vo
[PATCH] D50564: Add support for SEH unwinding on Windows.
mstorsjo added a comment. Not much more comments from me. The implementation seems reasonable, and works for one simple test I did (with an earlier revision of the patch at least), and further refinement can happen in-tree I guess. I'd like to have someone else (@rnk @compnerd?) give it a more proper approval though, at least a general ack for the style/structure. Comment at: include/__libunwind_config.h:66 +#if defined(__ARM_WMMX) +# define _LIBUNWIND_CONTEXT_SIZE 61 +#else I don't think the `__ARM_WMMX` case here is relevant; there are no ARM CPUs with WMMX running modern windows on arm, afaik (and the size number here I presume only is a copy from the one below); sorry for not pointing it out earlier. Comment at: src/UnwindCursor.hpp:54 #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" mstorsjo wrote: > This looks like another leftover; there's no `libunwind_ext.h` any longer > here. Sorry I think I misread and looked for `libunwind_ext.h` in the `include` dir only. But in case it isn't really needed here, keep the old `libunwind.h` include at least, in order not to break other potential build configurations that might need it. Comment at: src/UnwindCursor.hpp:1157 +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + pint_t getLastPC() const { /* FIXME: Implement */ return 0; } cdavis5x wrote: > mstorsjo wrote: > > What does this whole block do here? Isn't this within an !SEH ifdef block? > > The same methods are declared for the SEH version of this struct further > > above. > Right now, it doesn't do anything. I added it so @kristina has someplace to > put the code for unwinding with SEH data when we're //not// on Windows and we > //don't// have the `RtlUnwindEx()` function available. You'll note that the > '!SEH' `ifdef` now says: > > ```lang=c++ > #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) > ``` Ah, I see. Maybe a comment clarifying that here as well? Repository: rUNW libunwind https://reviews.llvm.org/D50564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits