[PATCH] D50412: Fix pointer-to-integer cast warnings on LLP64.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk, compnerd, smeenai. Herald added subscribers: cfe-commits, christof. `long` is too short on LLP64. We have to use `intptr_t` to avoid truncating pointers. Repository: rUNW libunwind https://reviews.llvm.org/D50412 Files: src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -287,7 +287,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)(intptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -33,9 +33,9 @@ (void *)exception_object, (long)exception_object->unwinder_cache.reserved1); #else - _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld", + _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR, (void *)exception_object, - (long)exception_object->private_1); + (intptr_t)exception_object->private_1); #endif #if defined(_LIBUNWIND_ARM_EHABI) @@ -92,9 +92,9 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) -return (void *)(long) info.start_ip; +return (void *)(intptr_t) info.start_ip; else return NULL; } @@ -190,14 +190,14 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); unw_get_proc_info(&cursor, &info); bases->tbase = (uintptr_t)info.extra; bases->dbase = 0; // dbase not used on Mac OS X bases->func = (uintptr_t)info.start_ip; _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc, - (void *)(long) info.unwind_info); - return (void *)(long) info.unwind_info; + (void *)(intptr_t) info.unwind_info); + return (void *)(intptr_t) info.unwind_info; } /// Returns the CFA (call frame area, or stack pointer at start of function) Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -287,7 +287,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)(intptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -33,9 +33,9 @@ (void *)exception_object, (long)exception_object->unwinder_cache.reserved1); #else - _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld", + _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR, (void *)exception_object, - (long)exception_object->private_1); + (intptr_t)exception_object->private_1); #endif #if defined(_LIBUNWIND_ARM_EHABI) @@ -92,9 +92,9 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) -return (void *)(long) info.start_ip; +return (void *)(intptr_t) info.start_ip; else return NULL; } @@ -190,14 +190,14 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); unw_get_proc_info(&cursor, &info); bases->tbase = (uintptr_t)info.extra; bases->dbase = 0; // dbase not used on Mac OS X bases->func = (uintptr_t)info.start_ip; _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc, - (void *)(long) info.unwind_info)
[PATCH] D50412: Fix pointer-to-integer cast warnings on LLP64.
cdavis5x updated this revision to Diff 159607. cdavis5x added a comment. Rebasing against HEAD. Repository: rUNW libunwind https://reviews.llvm.org/D50412 Files: src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -287,7 +287,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)(intptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -33,9 +33,9 @@ (void *)exception_object, (long)exception_object->unwinder_cache.reserved1); #else - _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld", + _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR, (void *)exception_object, - (long)exception_object->private_1); + (intptr_t)exception_object->private_1); #endif #if defined(_LIBUNWIND_ARM_EHABI) @@ -92,9 +92,9 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) -return (void *)(long) info.start_ip; +return (void *)(intptr_t) info.start_ip; else return NULL; } @@ -190,14 +190,14 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); unw_get_proc_info(&cursor, &info); bases->tbase = (uintptr_t)info.extra; bases->dbase = 0; // dbase not used on Mac OS X bases->func = (uintptr_t)info.start_ip; _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc, - (void *)(long) info.unwind_info); - return (void *)(long) info.unwind_info; + (void *)(intptr_t) info.unwind_info); + return (void *)(intptr_t) info.unwind_info; } /// Returns the CFA (call frame area, or stack pointer at start of function) Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -287,7 +287,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)(intptr_t)(frameInfo.handler); _LIBUNWIND_TRACE_UNWINDING( "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", (void *)exception_object, (void *)(uintptr_t)p); Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -33,9 +33,9 @@ (void *)exception_object, (long)exception_object->unwinder_cache.reserved1); #else - _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld", + _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR, (void *)exception_object, - (long)exception_object->private_1); + (intptr_t)exception_object->private_1); #endif #if defined(_LIBUNWIND_ARM_EHABI) @@ -92,9 +92,9 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) -return (void *)(long) info.start_ip; +return (void *)(intptr_t) info.start_ip; else return NULL; } @@ -190,14 +190,14 @@ unw_proc_info_t info; unw_getcontext(&uc); unw_init_local(&cursor, &uc); - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc); + unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc); unw_get_proc_info(&cursor, &info); bases->tbase = (uintptr_t)info.extra; bases->dbase = 0; // dbase not used on Mac OS X bases->func = (uintptr_t)info.start_ip; _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc, - (void *)(long) info.unwind_info); - return (void *)(long) info.unwind_info; + (void *)(intptr_t) info.unwind_info); + return (void *)(intptr_t)
[PATCH] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk, compnerd, smeenai. Herald added subscribers: cfe-commits, chrib, christof, krytarowski. Add these declarations which should be present in ``, but aren't. Not that it matters, since most of the time we'll be using Clang's `` anyway. Repository: rUNW libunwind https://reviews.llvm.org/D50413 Files: include/unwind.h Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -25,6 +25,26 @@ #define LIBUNWIND_UNAVAIL #endif +typedef uintptr_t _Unwind_Word; +typedef intptr_t _Unwind_Sword; +typedef uintptr_t _Unwind_Internal_Ptr; +typedef uint64_t _Unwind_Exception_Class; + +typedef intptr_t _sleb128_t; +typedef uintptr_t _uleb128_t; + +#if _LIBUNWIND_ARM_EHABI +#if defined(__FreeBSD__) +typedef void *_Unwind_Ptr; +#elif defined(__linux__) +typedef unsigned long *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif +#else +typedef uintptr_t _Unwind_Ptr; +#endif + typedef enum { _URC_NO_REASON = 0, _URC_OK = 0, @@ -107,10 +127,11 @@ _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); +typedef _Unwind_Personality_Fn __personality_routine; #else struct _Unwind_Context; // opaque struct _Unwind_Exception; // forward declaration @@ -142,12 +163,13 @@ struct _Unwind_Context* context, void* stop_parameter ); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); +typedef _Unwind_Personality_Fn __personality_routine; #endif #ifdef __cplusplus Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -25,6 +25,26 @@ #define LIBUNWIND_UNAVAIL #endif +typedef uintptr_t _Unwind_Word; +typedef intptr_t _Unwind_Sword; +typedef uintptr_t _Unwind_Internal_Ptr; +typedef uint64_t _Unwind_Exception_Class; + +typedef intptr_t _sleb128_t; +typedef uintptr_t _uleb128_t; + +#if _LIBUNWIND_ARM_EHABI +#if defined(__FreeBSD__) +typedef void *_Unwind_Ptr; +#elif defined(__linux__) +typedef unsigned long *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif +#else +typedef uintptr_t _Unwind_Ptr; +#endif + typedef enum { _URC_NO_REASON = 0, _URC_OK = 0, @@ -107,10 +127,11 @@ _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); +typedef _Unwind_Personality_Fn __personality_routine; #else struct _Unwind_Context; // opaque struct _Unwind_Exception; // forward declaration @@ -142,12 +163,13 @@ struct _Unwind_Context* context, void* stop_parameter ); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); +typedef _Unwind_Personality_Fn __personality_routine; #endif #ifdef __cplusplus ___ 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 .
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk, compnerd, smeenai. Herald added subscribers: cfe-commits, chrib, christof. Make the `_Unwind_Exception` struct correct under SEH. Add a declaration of `_GCC_specific_handler()`, which is used by SEH versions of Itanium personality handlers to do common setup. Roughly corresponds to Clang's https://reviews.llvm.org/D50380. Repository: rUNW libunwind https://reviews.llvm.org/D50414 Files: include/unwind.h Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -19,6 +19,10 @@ #include #include +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +#include +#endif + #if defined(__APPLE__) #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable )) #else @@ -120,13 +124,17 @@ uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code reason, _Unwind_Exception *exc); +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) + uintptr_t private_[6]; +#else uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use +#endif #if __SIZEOF_POINTER__ == 4 // The implementation of _Unwind_Exception uses an attribute mode on the // above fields which has the side effect of causing this whole struct to - // round up to 32 bytes in size. To be more explicit, we add pad fields - // added for binary compatibility. + // round up to 32 bytes in size (48 with SEH). To be more explicit, we add + // pad fields added for binary compatibility. uint32_t reserved[3]; #endif // The Itanium ABI requires that _Unwind_Exception objects are "double-word @@ -369,6 +377,24 @@ extern void *__deregister_frame_info_bases(const void *fde) LIBUNWIND_UNAVAIL; +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +// This is the common wrapper for GCC-style personality functions with SEH. +#ifdef __x86_64__ +// The DISPATCHER_CONTEXT struct is only defined on x64. +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, + PCONTEXT ctx, + PDISPATCHER_CONTEXT disp, + _Unwind_Personality_Fn pers); +#else +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, + PCONTEXT ctx, + PVOID disp, + _Unwind_Personality_Fn pers); +#endif +#endif + #ifdef __cplusplus } #endif Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -19,6 +19,10 @@ #include #include +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +#include +#endif + #if defined(__APPLE__) #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable )) #else @@ -120,13 +124,17 @@ uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code reason, _Unwind_Exception *exc); +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) + uintptr_t private_[6]; +#else uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use +#endif #if __SIZEOF_POINTER__ == 4 // The implementation of _Unwind_Exception uses an attribute mode on the // above fields which has the side effect of causing this whole struct to - // round up to 32 bytes in size. To be more explicit, we add pad fields - // added for binary compatibility. + // round up to 32 bytes in size (48 with SEH). To be more explicit, we add + // pad fields added for binary compatibility. uint32_t reserved[3]; #endif // The Itanium ABI requires that _Unwind_Exception objects are "double-word @@ -369,6 +377,24 @@ extern void *__deregister_frame_info_bases(const void *fde) LIBUNWIND_UNAVAIL; +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +// This is the common wrapper for GCC-style personality functions with SEH. +#ifdef __x86_64__ +// The DISPATCHER_CONTEXT struct is only defined on x64. +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, + PCONTEXT ctx, + PDISPATCHER_CONTEXT disp, + _Unwind_Personality_Fn pers); +#else +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, +
[PATCH] D50414: [libunwind][include] Add SEH declarations to .
cdavis5x added a comment. In https://reviews.llvm.org/D50414#1191834, @mstorsjo wrote: > 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. Probably. I believe it's present in GCC's ``, too. > Do you plan on implementing these SEH specific bits in libunwind, Already have. Patch forthcoming. 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] D50414: [libunwind][include] Add SEH declarations to .
cdavis5x updated this revision to Diff 159722. cdavis5x added a comment. - Remove unneeded preprocessor condition. Repository: rUNW libunwind https://reviews.llvm.org/D50414 Files: include/unwind.h Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -19,6 +19,10 @@ #include #include +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +#include +#endif + #if defined(__APPLE__) #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable )) #else @@ -120,13 +124,17 @@ uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code reason, _Unwind_Exception *exc); +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) + uintptr_t private_[6]; +#else uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use +#endif #if __SIZEOF_POINTER__ == 4 // The implementation of _Unwind_Exception uses an attribute mode on the // above fields which has the side effect of causing this whole struct to - // round up to 32 bytes in size. To be more explicit, we add pad fields - // added for binary compatibility. + // round up to 32 bytes in size (48 with SEH). To be more explicit, we add + // pad fields added for binary compatibility. uint32_t reserved[3]; #endif // The Itanium ABI requires that _Unwind_Exception objects are "double-word @@ -369,6 +377,15 @@ extern void *__deregister_frame_info_bases(const void *fde) LIBUNWIND_UNAVAIL; +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +// This is the common wrapper for GCC-style personality functions with SEH. +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, + PCONTEXT ctx, + PDISPATCHER_CONTEXT disp, + _Unwind_Personality_Fn pers); +#endif + #ifdef __cplusplus } #endif Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -19,6 +19,10 @@ #include #include +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +#include +#endif + #if defined(__APPLE__) #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable )) #else @@ -120,13 +124,17 @@ uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code reason, _Unwind_Exception *exc); +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) + uintptr_t private_[6]; +#else uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use +#endif #if __SIZEOF_POINTER__ == 4 // The implementation of _Unwind_Exception uses an attribute mode on the // above fields which has the side effect of causing this whole struct to - // round up to 32 bytes in size. To be more explicit, we add pad fields - // added for binary compatibility. + // round up to 32 bytes in size (48 with SEH). To be more explicit, we add + // pad fields added for binary compatibility. uint32_t reserved[3]; #endif // The Itanium ABI requires that _Unwind_Exception objects are "double-word @@ -369,6 +377,15 @@ extern void *__deregister_frame_info_bases(const void *fde) LIBUNWIND_UNAVAIL; +#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) +// This is the common wrapper for GCC-style personality functions with SEH. +extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc, + PVOID frame, + PCONTEXT ctx, + PDISPATCHER_CONTEXT disp, + _Unwind_Personality_Fn pers); +#endif + #ifdef __cplusplus } #endif ___ 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 .
cdavis5x added inline comments. Comment at: include/unwind.h:46 +typedef uintptr_t _Unwind_Ptr; +#endif + mstorsjo wrote: > 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. Where //did// I get those from...? These seem to be for ARM EHABI, but I can't find them anymore in the GCC source. They aren't in Clang's header, either. I wrote this a while ago... did something change in the meantime? I could probably get away with removing those special cases if we don't really need them. 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] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x marked an inline comment as done. cdavis5x added a comment. In https://reviews.llvm.org/D50413#1191726, @krytarowski wrote: > NetBSD uses `typedef void *_Unwind_Ptr;` unconditionally in its > ``... if that has to be matched. Done. > Additionally: `typedef long _Unwind_Word;`. Done. 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] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x updated this revision to Diff 159731. cdavis5x added a comment. - Add NetBSD-specific definitions. - Pull out common declaration of `__personality_routine`. Repository: rUNW libunwind https://reviews.llvm.org/D50413 Files: include/unwind.h Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -29,6 +29,32 @@ #define LIBUNWIND_UNAVAIL #endif +#if defined(__NetBSD__) +typedef long _Unwind_Word; +#else +typedef uintptr_t _Unwind_Word; +#endif +typedef intptr_t _Unwind_Sword; +typedef uintptr_t _Unwind_Internal_Ptr; +typedef uint64_t _Unwind_Exception_Class; + +typedef intptr_t _sleb128_t; +typedef uintptr_t _uleb128_t; + +#if _LIBUNWIND_ARM_EHABI +#if defined(__FreeBSD__) +typedef void *_Unwind_Ptr; +#elif defined(__linux__) +typedef unsigned long *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif +#elif defined(__NetBSD__) +typedef void *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif + typedef enum { _URC_NO_REASON = 0, _URC_OK = 0, @@ -111,7 +137,7 @@ _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); @@ -150,13 +176,14 @@ struct _Unwind_Context* context, void* stop_parameter ); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); #endif +typedef _Unwind_Personality_Fn __personality_routine; #ifdef __cplusplus extern "C" { Index: include/unwind.h === --- include/unwind.h +++ include/unwind.h @@ -29,6 +29,32 @@ #define LIBUNWIND_UNAVAIL #endif +#if defined(__NetBSD__) +typedef long _Unwind_Word; +#else +typedef uintptr_t _Unwind_Word; +#endif +typedef intptr_t _Unwind_Sword; +typedef uintptr_t _Unwind_Internal_Ptr; +typedef uint64_t _Unwind_Exception_Class; + +typedef intptr_t _sleb128_t; +typedef uintptr_t _uleb128_t; + +#if _LIBUNWIND_ARM_EHABI +#if defined(__FreeBSD__) +typedef void *_Unwind_Ptr; +#elif defined(__linux__) +typedef unsigned long *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif +#elif defined(__NetBSD__) +typedef void *_Unwind_Ptr; +#else +typedef uintptr_t _Unwind_Ptr; +#endif + typedef enum { _URC_NO_REASON = 0, _URC_OK = 0, @@ -111,7 +137,7 @@ _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); @@ -150,13 +176,14 @@ struct _Unwind_Context* context, void* stop_parameter ); -typedef _Unwind_Reason_Code (*__personality_routine) +typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); #endif +typedef _Unwind_Personality_Fn __personality_routine; #ifdef __cplusplus extern "C" { ___ 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.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk, compnerd, smeenai. Herald added subscribers: cfe-commits, chrib, christof, kristof.beyls, mgorny. Herald added a reviewer: javed.absar. 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. ARM still remains to be implemented (@compnerd?). 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.) 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. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,11 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +38,43 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #if defined(__x86_64__) && !defined(__MINGW64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} DISPATCHER_CONTEXT; + #elif defined(__arm__) +typedef struct _DISPATCHER_CONTEXT { + ULONG ControlPc; + ULONG ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG EstablisherFrame; + ULONG TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG ControlPcIsUnwound; + PKNONVOLATILE_CONTEXT_POINTERS NonVolatileRegisters; + ULONG VirtualVfpHead; +} DISPATCHER_CONTEXT; + #endif +extern int _unw_init_seh(unw_cursor_t *cursor, CONTEXT *ctx); +extern DISPATCHER_CONTEXT *_unw_seh_get_disp_ctx(unw_cursor_t *cursor); +extern void _unw_seh_set_disp_ctx(unw_cursor_t *cursor, DISPATCHER_CONTEXT *disp); +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#if !_LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,40 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +# ifdef _LIBUNWIND_TARGET_X86_64 +struct UNWIND_INFO { + BYTE Version : 3; + BYTE Flags : 5; + BYTE SizeOfProlog; + BYTE CountOfCodes; + BYTE FrameRegister : 4; + BYTE FrameOffset : 4; + WORD UnwindCodes[2]; +}; +# endif + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception
[PATCH] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x added a comment. In https://reviews.llvm.org/D50413#1195101, @mstorsjo wrote: > @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? Sounds reasonable. 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.
cdavis5x added inline comments. Comment at: src/libunwind_ext.h:43 + #if defined(__x86_64__) && !defined(__MINGW64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; mstorsjo wrote: > What's this all about? winnt.h (from both MSVC and mingw-w64) should define > this struct, no? Not my copy of `` from the Win7 SDK. Dunno about WIn8 and WIn10. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x added inline comments. Comment at: src/Unwind-seh.cpp:53 + +/// Exception cleanup routine used by \c __libunwind_frame_consolidate to +/// regain control after handling an SEH exception. mstorsjo wrote: > I don't see any `__libunwind_frame_consolidate` anywhere, is this comment > outdated? Why yes it is. Comment at: src/UnwindLevel1.c:35 +#if !_LIBUNWIND_SUPPORT_SEH_UNWIND + mstorsjo wrote: > This probably works, but isn't `#if !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)` > more of the common form? I think I wrote this before the change to make that so took place, and I forgot to update this. Good catch. 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); mstorsjo wrote: > These are all both defined and called from Unwind-seh.cpp, so couldn't they > just be static functions within there? Probably. Done. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 160195. cdavis5x added a comment. - Fix outdated comment. - Make preprocessor conditional more consistent. - Make some private functions used only in a single file static. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,11 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +38,40 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #if defined(__x86_64__) && !defined(__MINGW64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} DISPATCHER_CONTEXT; + #elif defined(__arm__) +typedef struct _DISPATCHER_CONTEXT { + ULONG ControlPc; + ULONG ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG EstablisherFrame; + ULONG TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG ControlPcIsUnwound; + PKNONVOLATILE_CONTEXT_POINTERS NonVolatileRegisters; + ULONG VirtualVfpHead; +} DISPATCHER_CONTEXT; + #endif +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,40 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +# ifdef _LIBUNWIND_TARGET_X86_64 +struct UNWIND_INFO { + BYTE Version : 3; + BYTE Flags : 5; + BYTE SizeOfProlog; + BYTE CountOfCodes; + BYTE FrameRegister : 4; + BYTE FrameOffset : 4; + WORD UnwindCodes[2]; +}; +# endif + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" #include "CompactUnwinder.hpp" #include "config.h" #include "DwarfInstructions.hpp" #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" #include "RWMutex.hpp" #include "Unwind-EHABI.h" @@ -412,6 +434,525 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public:
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. In https://reviews.llvm.org/D50564#1195794, @mstorsjo wrote: > > 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 can't seem to find it either. I wonder if it's vanished from the Internet. Maybe the IA will have something. 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] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x added a comment. Ping. 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.
cdavis5x added a comment. Could somebody verify that the `DISPATCHER_CONTEXT` struct is defined in `` for the Win8 and Win10 SDKs? I can't install them right now. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. In https://reviews.llvm.org/D50564#1195985, @cdavis5x wrote: > In https://reviews.llvm.org/D50564#1195794, @mstorsjo wrote: > > > > 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 can't seem to find it either. I wonder if it's vanished from the Internet. > Maybe the IA will have something. Found it: http://www.nynaeve.net/?p=99. Interestingly, a reference to that was in the MinGW headers--I think that's how I found it in the first place. I'll update the description. In https://reviews.llvm.org/D50564#1199311, @zturner wrote: > 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 > > # if defined(__x86_64__) > > typedef struct _DISPATCHER_CONTEXT { ... } DISPATCHER_CONTEXT; > > # elif defined(__arm__) > > typedef struct _DISPATCHER_CONTEXT { ... } DISPATCHER_CONTEXT; > > # endif > > #endif > > > > > > Does that seem right? I'm not super familiar with SDK version detection, so > > I might have the wrong macros. > > > I believe you need to check `VER_PRODUCTBUILD` from `` if you are > looking for the version of the Windows SDK that is being used to build the > current application. Thanks, @rnk and @zturner. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 160638. cdavis5x marked 3 inline comments as done. cdavis5x edited the summary of this revision. cdavis5x added a comment. - Update checks for DISPATCHER_CONTEXT definition. - Add link to KJK::Hyperion's articles on SEH. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,12 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #include + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +39,44 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 + #if defined(__x86_64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} DISPATCHER_CONTEXT; + #elif defined(__arm__) +typedef struct _DISPATCHER_CONTEXT { + ULONG ControlPc; + ULONG ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG EstablisherFrame; + ULONG TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG ControlPcIsUnwound; + PKNONVOLATILE_CONTEXT_POINTERS NonVolatileRegisters; + ULONG VirtualVfpHead; +} DISPATCHER_CONTEXT; + #endif +typedef DISPATCHER_CONTEXT* PDISPATCHER_CONTEXT; +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,40 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +# ifdef _LIBUNWIND_TARGET_X86_64 +struct UNWIND_INFO { + BYTE Version : 3; + BYTE Flags : 5; + BYTE SizeOfProlog; + BYTE CountOfCodes; + BYTE FrameRegister : 4; + BYTE FrameOffset : 4; + WORD UnwindCodes[2]; +}; +# endif + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" #include "CompactUnwinder.hpp" #include "config.h" #include "DwarfInstructions.hpp" #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" #include "RWMutex.hpp" #include "Unwind-EHABI.h" @@ -412,6 +434,525 @@ #endif }; +#if defined(_LIBUNWIND_SU
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. Marked some comments as done. (Phab won't let me post an empty comment, so...) 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. ...And it turns out Phab marked the comments as done when I uploaded the new change. I didn't know it would do that. That's useful to know. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 160660. cdavis5x added a comment. - Get rid of DISPATCHER_CONTEXT def for ARM. We only support ARM on Win8+ anyway. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,12 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + #include + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +39,28 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 + #if defined(__x86_64__) +typedef struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +} DISPATCHER_CONTEXT; + #endif +typedef DISPATCHER_CONTEXT* PDISPATCHER_CONTEXT; +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,40 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +# ifdef _LIBUNWIND_TARGET_X86_64 +struct UNWIND_INFO { + BYTE Version : 3; + BYTE Flags : 5; + BYTE SizeOfProlog; + BYTE CountOfCodes; + BYTE FrameRegister : 4; + BYTE FrameOffset : 4; + WORD UnwindCodes[2]; +}; +# endif + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" #include "CompactUnwinder.hpp" #include "config.h" #include "DwarfInstructions.hpp" #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" #include "RWMutex.hpp" #include "Unwind-EHABI.h" @@ -412,6 +434,525 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public: + UnwindCursor(unw_context_t *context, A &as); + UnwindCursor(CONTEXT *context, A &as); + UnwindCursor(A &as, void *threadArg); + virtual ~UnwindCursor() {} + virtual boolvalidReg(int); + virtual unw_wor
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. Ping. 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] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x added a comment. Ping. 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] D50413: [libunwind][include] Add some missing definitions to .
cdavis5x added a comment. Ping. Are y'all waiting for me to do something? 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.
cdavis5x added a comment. Ping... 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. 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. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. In https://reviews.llvm.org/D50564#1207493, @kristina wrote: > In https://reviews.llvm.org/D50564#1206393, @mstorsjo wrote: > > > 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. > > > That still makes the underlying assumption that SEH is exclusive to Windows > (and by that virtue PE/COFF) which doesn't necessarily hold true. There is > also the issue of generic names like `_LIBUNWIND_SUPPORT_SEH_UNWIND` to guard > includes of Windows specific headers which ties into my previous point. Would > it be possible to somehow abstract away the Windows runtime function call and > Windows specific header includes, even if it's via CMake options. > > I'm raising this issue as there are other implementations of SEH that share > the same (or extremely similar, depending on SDK versions) structures, but > would not have the Windows headers available when compiling libunwind, and > while the runtime function call to the `Rtl*` API is easy to change later on, > separating rest of it from Windows headers is slightly messier. > > Would it, at very least, be possible to decouple most of it from a dependency > on Windows headers and if possible use things like `void*` in place of > `PVOID` or anything that's `stdint.h/inttypes.h` friendly? It's an excellent > patch regardless but loosening the Windows SDK dependencies a bit would make > it a lot better. > > Would be much appreciated, as I'm going through a backlog of patches I'd like > to put up for review one of which includes SEH for x86_64 Linux (ELF) > implemented using RT signals and additional compiler runtime glue code, > currently residing within compiler-rt builtins (one of the issues I want to > address before). It's quite a wonky ABI since I tried to keep as much > compatible with 64-bit Windows SEH (`.xdata` variation) in terms of frame > lowering etc, but run-time mechanisms differ vastly for obvious reasons. > Having it interop with libunwind smoothly without rewriting much of existing > code in this patch would be nice, or even worse resorting to a million > preprocessor guards to cover all the cases. Very well, then. I'll see what I can do. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 161807. cdavis5x added a comment. - Make a bit more friendly to non-Windows. - Fix bits that depend on https://reviews.llvm.org/D50413. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h include/unwind.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,12 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + #include + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +39,30 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 + #ifdef _WIN32 +#if defined(__x86_64__) +struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +}; +#endif + #endif +typedef DISPATCHER_CONTEXT* PDISPATCHER_CONTEXT; +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,40 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +# ifdef _LIBUNWIND_TARGET_X86_64 +struct UNWIND_INFO { + uint8_t Version : 3; + uint8_t Flags : 5; + uint8_t SizeOfProlog; + uint8_t CountOfCodes; + uint8_t FrameRegister : 4; + uint8_t FrameOffset : 4; + uint16_t UnwindCodes[2]; +}; +# endif + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, uint64_t, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" #include "CompactUnwinder.hpp" #include "config.h" #include "DwarfInstructions.hpp" #include "EHHeaderParser.hpp" -#include "libunwind.h" +#include "libunwind_ext.h" #include "Registers.hpp" #include "RWMutex.hpp" #include "Unwind-EHABI.h" @@ -412,6 +434,487 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public: + UnwindCursor(unw_context_t *context, A &as); + UnwindCursor(CONTEXT *context, A &as); + UnwindCursor(A &as, void *threadArg); + virtual
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. OK, I've removed some of the dependencies on Windows-specific types. The code in `Unwind-seh.cpp` is very Windows-specific, though, so I left it alone. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 162250. cdavis5x marked 7 inline comments as done. cdavis5x added a comment. - Remove unnecessary code. - Guard against rogue personality functions returning wrong values. - Add a comment clarifying the purpose of the `new_ctx` variable. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h include/unwind.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,12 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + #include + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +39,30 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 + #ifdef _WIN32 +#if defined(__x86_64__) +struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +}; +#endif + #endif +typedef DISPATCHER_CONTEXT* PDISPATCHER_CONTEXT; +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,18 +18,37 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +struct UNWIND_INFO { + uint8_t Version : 3; + uint8_t Flags : 5; + uint8_t SizeOfProlog; + uint8_t CountOfCodes; + uint8_t FrameRegister : 4; + uint8_t FrameOffset : 4; + uint16_t UnwindCodes[2]; +}; + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, uint64_t, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" #include "CompactUnwinder.hpp" #include "config.h" #include "DwarfInstructions.hpp" #include "EHHeaderParser.hpp" -#include "libunwind.h" #include "Registers.hpp" #include "RWMutex.hpp" #include "Unwind-EHABI.h" @@ -412,6 +431,472 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public: + UnwindCursor(unw_context_t *context, A &as); + UnwindCursor(CONTEXT *context, A &as); + UnwindCursor(A &as,
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x marked 2 inline comments as done. cdavis5x 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]); mstorsjo wrote: > 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? We should only hit this point if we're in phase 2 (i.e. `IS_UNWINDING(exc->ExceptionFlags)` is true). But you've now got me worried about the potential for a rogue personality function surreptitiously returning this to exploit libunwind. I've added a check here. 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"); mstorsjo wrote: > Who will get this new uninitialized CONTEXT here, and will they try to use it > for something? It won't be uninitialized. `RtlUnwindEx()` always starts unwinding from the current frame; it fills in the passed in `CONTEXT` and passes its address to any handlers it encounters along the way. In other words, it's there so `RtlUnwindEx()` has a place to keep track of the unwind context. Comment at: src/UnwindCursor.hpp:1157 +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) + pint_t getLastPC() const { /* FIXME: Implement */ return 0; } 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) ``` 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)) { kristina wrote: > mstorsjo wrote: > > 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. > This primarily deals with the SEH exceptions re-purposed as a C++ exception > mechanism on x86_64 (if I understood this right), it's possible to set a > custom filter using a runtime call so I suspect GCC does that or defines a > translation function (also via a runtime call) which acts as a filter for > "true" SEH exceptions behind the scenes deep within the runtime. Typially > "true" SEH exceptions don't, outside of runtime magic, play nicely with C++ > exceptions, with the `__C_specific_handler` ones being a completely different > paradigm that falls far outside the scope of libunwind (those ones being the > "true"/explicit SEH exceptions). > > (Don't take my word for it, it's been a while and I only implemented the > "true" variation for 64-bit Linux by reserving some RT signals and using that > to invoke additional runtime glue that would then do the unwinding, > completely ignoring DWARF since CFI exceptions and SEH exceptions really > don't mix especially on platforms that are not Windows-like) Actually, it's just to implement the lower-level `libunwind` APIs--specifically, `unw_get_info()`. The code @kristina is talking about is all in Unwind-seh.cpp. 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] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 162441. cdavis5x marked 8 inline comments as done. cdavis5x added a comment. - Remove case we'll never realistically hit. - Add back include I removed earlier. - Add a comment clarifying that some environments use SEH without Windows runtime support. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h include/unwind.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h src/libunwind_ext.h Index: src/libunwind_ext.h === --- src/libunwind_ext.h +++ src/libunwind_ext.h @@ -17,6 +17,12 @@ #include #include +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + #include + #include + #include +#endif + #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 @@ -33,6 +39,30 @@ extern void _unw_add_dynamic_fde(unw_word_t fde); extern void _unw_remove_dynamic_fde(unw_word_t fde); +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 + #ifdef _WIN32 +#if defined(__x86_64__) +struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +}; +#endif + #endif +typedef DISPATCHER_CONTEXT* PDISPATCHER_CONTEXT; +#endif + #if defined(_LIBUNWIND_ARM_EHABI) extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,10 +18,30 @@ #include #include +#ifdef _WIN32 + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +struct UNWIND_INFO { + uint8_t Version : 3; + uint8_t Flags : 5; + uint8_t SizeOfProlog; + uint8_t CountOfCodes; + uint8_t FrameRegister : 4; + uint8_t FrameOffset : 4; + uint16_t UnwindCodes[2]; +}; + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, uint64_t, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" @@ -412,6 +432,472 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public: + UnwindCursor(unw_context_t *context, A &as); + UnwindCursor(CONTEXT *context, A &as); + UnwindCursor(A &as, void *threadArg); + virtual ~UnwindCursor() {} + virtual boolvalidReg(int); + virtual unw_word_t getReg(int); + virtual voidsetReg(int, unw_word_t); + virtual bool
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x updated this revision to Diff 162509. cdavis5x added a comment. - Move `DISPATCHER_CONTEXT` definition into UnwindCursor.hpp. Repository: rUNW libunwind https://reviews.llvm.org/D50564 Files: include/__libunwind_config.h include/unwind.h src/AddressSpace.hpp src/CMakeLists.txt src/Unwind-seh.cpp src/UnwindCursor.hpp src/UnwindLevel1-gcc-ext.c src/UnwindLevel1.c src/config.h Index: src/config.h === --- src/config.h +++ src/config.h @@ -38,7 +38,11 @@ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 #endif #elif defined(_WIN32) - #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #ifdef __SEH__ +#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1 + #else +#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 + #endif #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 Index: src/UnwindLevel1.c === --- src/UnwindLevel1.c +++ src/UnwindLevel1.c @@ -32,6 +32,8 @@ #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) +#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND + static _Unwind_Reason_Code unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { unw_init_local(cursor, uc); @@ -449,6 +451,7 @@ return result; } +#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND /// Called by personality handler during phase 2 if a foreign exception // is caught. Index: src/UnwindLevel1-gcc-ext.c === --- src/UnwindLevel1-gcc-ext.c +++ src/UnwindLevel1-gcc-ext.c @@ -25,6 +25,10 @@ #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +#define private_1 private_[0] +#endif + /// Called by __cxa_rethrow(). _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { Index: src/UnwindCursor.hpp === --- src/UnwindCursor.hpp +++ src/UnwindCursor.hpp @@ -18,10 +18,51 @@ #include #include +#ifdef _WIN32 + #include + #include +#endif #ifdef __APPLE__ #include #endif +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) +// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and +// earlier) SDKs. +// MinGW-w64 has always provided this struct. + #if defined(_WIN32) && defined(_LIBUNWIND_TARGET_X86_64) && \ + !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000 +struct _DISPATCHER_CONTEXT { + ULONG64 ControlPc; + ULONG64 ImageBase; + PRUNTIME_FUNCTION FunctionEntry; + ULONG64 EstablisherFrame; + ULONG64 TargetIp; + PCONTEXT ContextRecord; + PEXCEPTION_ROUTINE LanguageHandler; + PVOID HandlerData; + PUNWIND_HISTORY_TABLE HistoryTable; + ULONG ScopeIndex; + ULONG Fill0; +}; + #endif + +struct UNWIND_INFO { + uint8_t Version : 3; + uint8_t Flags : 5; + uint8_t SizeOfProlog; + uint8_t CountOfCodes; + uint8_t FrameRegister : 4; + uint8_t FrameOffset : 4; + uint16_t UnwindCodes[2]; +}; + +extern "C" _Unwind_Reason_Code __libunwind_seh_personality( +int, _Unwind_Action, uint64_t, _Unwind_Exception *, +struct _Unwind_Context *); + +#endif + #include "config.h" #include "AddressSpace.hpp" @@ -412,6 +453,472 @@ #endif }; +#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32) + +/// \c UnwindCursor contains all state (including all register values) during +/// an unwind. This is normally stack-allocated inside a unw_cursor_t. +template +class UnwindCursor : public AbstractUnwindCursor { + typedef typename A::pint_t pint_t; +public: + UnwindCursor(unw_context_t *context, A &as); + UnwindCursor(CONTEXT *context, A &as); + UnwindCursor(A &as, void *threadArg); + virtual ~UnwindCursor() {} + virtual boolvalidReg(int); + virtual unw_word_t getReg(int); + virtual voidsetReg(int, unw_word_t); + virtual boolvalidFloatReg(int); + virtual unw_fpreg_t getFloatReg(int); + virtual voidsetFloatReg(int, unw_fpreg_t); + virtual int step(); + virtual voidgetInfo(unw_proc_info_t *); + virtual voidjumpto(); + virtual boolisSignalFrame(); + virtual boolgetFunctionName(char *buf, size_t len, unw_word_t *off); + virtual voidsetInfoBasedOnIPRegister(bool isReturnAddress = false); + virtual const char *getRegisterName(int num); +#ifdef __arm__ + virtual voidsaveVFPAsX(); +#endif + + DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; } + void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; } + +private: + + pint_t getLastPC() const { return _dispContext.ControlPc; } + void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; } + RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) { +_dispContext.Functio
[PATCH] D50564: Add support for SEH unwinding on Windows.
cdavis5x added a comment. Ping. 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] D51508: Export public functions implemented in assembly on Windows.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk. Herald added subscribers: cfe-commits, christof. By default, symbols aren't visible outside of the module that defines them. To make them visible, they must be exported. The easiest way to do that is to embed an `-export:symname` directive into the object file. Repository: rUNW libunwind https://reviews.llvm.org/D51508 Files: src/assembly.h Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -44,6 +44,7 @@ #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE @@ -54,6 +55,7 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ @@ -70,6 +72,11 @@ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define EXPORT_SYMBOL2(name) \ + .section .drectve,"yn" SEPARATOR\ + .ascii "-export:", #name, "\0" SEPARATOR\ + .text +#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) #define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE @@ -82,6 +89,7 @@ #define DEFINE_LIBUNWIND_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ + EXPORT_SYMBOL(name) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_NAME(name): Index: src/assembly.h === --- src/assembly.h +++ src/assembly.h @@ -44,6 +44,7 @@ #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .private_extern name #define NO_EXEC_STACK_DIRECTIVE @@ -54,6 +55,7 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#define EXPORT_SYMBOL(name) #define HIDDEN_SYMBOL(name) .hidden name #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ @@ -70,6 +72,11 @@ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef +#define EXPORT_SYMBOL2(name) \ + .section .drectve,"yn" SEPARATOR\ + .ascii "-export:", #name, "\0" SEPARATOR\ + .text +#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) #define HIDDEN_SYMBOL(name) #define NO_EXEC_STACK_DIRECTIVE @@ -82,6 +89,7 @@ #define DEFINE_LIBUNWIND_FUNCTION(name) \ .globl SYMBOL_NAME(name) SEPARATOR \ + EXPORT_SYMBOL(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] D51509: [AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk. Herald added subscribers: cfe-commits, christof. That attribute has no effect on Windows anyway--classes are hidden by default. Repository: rUNW libunwind https://reviews.llvm.org/D51509 Files: src/AddressSpace.hpp Index: src/AddressSpace.hpp === --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -180,7 +180,7 @@ /// LocalAddressSpace is used as a template parameter to UnwindCursor when /// unwinding a thread in the same process. The wrappers compile away, /// making local unwinds fast. -class __attribute__((visibility("hidden"))) LocalAddressSpace { +class _LIBUNWIND_HIDDEN LocalAddressSpace { public: typedef uintptr_t pint_t; typedef intptr_t sint_t; Index: src/AddressSpace.hpp === --- src/AddressSpace.hpp +++ src/AddressSpace.hpp @@ -180,7 +180,7 @@ /// LocalAddressSpace is used as a template parameter to UnwindCursor when /// unwinding a thread in the same process. The wrappers compile away, /// making local unwinds fast. -class __attribute__((visibility("hidden"))) LocalAddressSpace { +class _LIBUNWIND_HIDDEN LocalAddressSpace { public: typedef uintptr_t pint_t; typedef intptr_t sint_t; ___ 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 .
cdavis5x abandoned this revision. cdavis5x added a comment. Consensus seems clear to me. Patch abandoned. 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] D51508: Export public functions implemented in assembly on Windows.
cdavis5x added inline comments. Comment at: src/assembly.h:76-78 + .section .drectve,"yn" SEPARATOR\ + .ascii "-export:", #name, "\0" SEPARATOR\ + .text rnk wrote: > Maybe .pushsection / .popsection is better than assuming you were in .text. I initially wanted to do that, but those directives aren't supported by COFF. Neither, by the way, is `.previous`. Perhaps this needs to be fixed in LLVM. Repository: rUNW libunwind https://reviews.llvm.org/D51508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51644: [CMake] Remove variable reference that isn't used.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk. Herald added subscribers: cfe-commits, christof, mgorny. This variable is never defined, so its value is always empty. Since `libunwind` is needed to build the C++ ABI library in the first place, it should never be linked to the C++ ABI library anyway. Repository: rUNW libunwind https://reviews.llvm.org/D51644 Files: src/CMakeLists.txt Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -51,7 +51,7 @@ ${LIBUNWIND_ASM_SOURCES}) # Generate library list. -set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES}) +set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) append_if(libraries LIBUNWIND_HAS_DL_LIB dl) Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -51,7 +51,7 @@ ${LIBUNWIND_ASM_SOURCES}) # Generate library list. -set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES}) +set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) append_if(libraries LIBUNWIND_HAS_DL_LIB dl) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51644: [CMake] Remove variable reference that isn't used.
cdavis5x added inline comments. Comment at: src/CMakeLists.txt:54 # Generate library list. -set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES}) +set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) mstorsjo wrote: > Is there any point in this line at all now, or can it be removed altogether? I think `list(APPEND)` can fail if the variable doesn't exist. Repository: rUNW libunwind https://reviews.llvm.org/D51644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51645: [CMake] Don't use -rtlib=compiler-rt with -nodefaultlibs.
cdavis5x created this revision. cdavis5x added reviewers: mstorsjo, rnk. Herald added subscribers: cfe-commits, christof, mgorny, dberris. This switch only has an effect at link time. It changes the default compiler support library to `compiler-rt`. With `-nodefaultlibs`, this library won't get linked anyway; Clang actually warns about that. Repository: rUNW libunwind https://reviews.llvm.org/D51645 Files: CMakeLists.txt cmake/config-ix.cmake Index: cmake/config-ix.cmake === --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -23,7 +23,6 @@ list(APPEND CMAKE_REQUIRED_LIBRARIES c) endif () if (LIBUNWIND_USE_COMPILER_RT) -list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt) find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY) list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}") elseif (LIBUNWIND_HAS_GCC_S_LIB) Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -234,7 +234,7 @@ # Configure compiler. include(config-ix) -if (LIBUNWIND_USE_COMPILER_RT) +if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt") endif() Index: cmake/config-ix.cmake === --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -23,7 +23,6 @@ list(APPEND CMAKE_REQUIRED_LIBRARIES c) endif () if (LIBUNWIND_USE_COMPILER_RT) -list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt) find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY) list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}") elseif (LIBUNWIND_HAS_GCC_S_LIB) Index: CMakeLists.txt === --- CMakeLists.txt +++ CMakeLists.txt @@ -234,7 +234,7 @@ # Configure compiler. include(config-ix) -if (LIBUNWIND_USE_COMPILER_RT) +if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt") endif() ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51657: [CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.
cdavis5x created this revision. cdavis5x added a reviewer: beanz. Herald added subscribers: cfe-commits, chrib, christof, mgorny, dberris. If `-nodefaultlibs` is given, we weren't actually linking to it. This was true irrespective of passing `-rtlib=compiler-rt` (see previous patch). Now we explicitly link it to handle that case. I wonder if we should be linking these libraries only if we're using `-nodefaultlibs`... Repository: rUNW libunwind https://reviews.llvm.org/D51657 Files: src/CMakeLists.txt Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -53,7 +53,12 @@ # Generate library list. set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) -append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) +if (LIBUNWIND_USE_COMPILER_RT) + list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}") +else() + append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) + list(APPEND libraries gcc) +endif() append_if(libraries LIBUNWIND_HAS_DL_LIB dl) if (LIBUNWIND_ENABLE_THREADS) append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread) Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -53,7 +53,12 @@ # Generate library list. set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) -append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) +if (LIBUNWIND_USE_COMPILER_RT) + list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}") +else() + append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) + list(APPEND libraries gcc) +endif() append_if(libraries LIBUNWIND_HAS_DL_LIB dl) if (LIBUNWIND_ENABLE_THREADS) append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51657: [CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.
cdavis5x added a comment. Ping. Repository: rUNW libunwind https://reviews.llvm.org/D51657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50199: [MinGW] Predefine UNICODE if -municode is specified during compilation
cdavis5x added a comment. Are you sure this shouldn't also define `_UNICODE`? //looks// Hmm... GCC doesn't define it. I wonder if we should anyway. A user who set `-municode` may also be using ``, and thus may want those macros set to their Unicode counterparts. I actually believe this is supposed to have one other effect: it sets the entry point to `wmainCRTStartup()`/`wWinMainCRTStartup()`, making the user entry point `wmain()`/`wWinMain()`, which take wide arguments: int wmain(int argc, wchar_t **argv); int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPWSTR pwszCmdLine, int nCmdShow); But that's a link-time effect. I believe it has no bearing on @rnk's comment. ...Actually, that suggests that we may want to warn if the user defines `main()` or `WinMain()` instead of their Unicode counterparts when `-municode` is given--which means we may want to pass it to the frontend after all. https://reviews.llvm.org/D50199 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51657: [CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.
cdavis5x added a comment. Ping. Repository: rUNW libunwind https://reviews.llvm.org/D51657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51657: [CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.
cdavis5x updated this revision to Diff 168687. cdavis5x added a comment. - Detect libgcc. Repository: rUNW libunwind https://reviews.llvm.org/D51657 Files: cmake/config-ix.cmake src/CMakeLists.txt Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -53,7 +53,12 @@ # Generate library list. set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) -append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) +if (LIBUNWIND_USE_COMPILER_RT) + list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}") +else() + append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) + append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc) +endif() append_if(libraries LIBUNWIND_HAS_DL_LIB dl) if (LIBUNWIND_ENABLE_THREADS) append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread) Index: cmake/config-ix.cmake === --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -7,6 +7,7 @@ if (NOT LIBUNWIND_USE_COMPILER_RT) check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB) + check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB) endif() # libunwind is built with -nodefaultlibs, so we want all our checks to also @@ -25,8 +26,13 @@ if (LIBUNWIND_USE_COMPILER_RT) find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY) list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}") - elseif (LIBUNWIND_HAS_GCC_S_LIB) -list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) + else () +if (LIBUNWIND_HAS_GCC_S_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) +endif () +if (LIBUNWIND_HAS_GCC_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc) +endif () endif () if (MINGW) # Mingw64 requires quite a few "C" runtime libraries in order for basic Index: src/CMakeLists.txt === --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -53,7 +53,12 @@ # Generate library list. set(libraries) append_if(libraries LIBUNWIND_HAS_C_LIB c) -append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) +if (LIBUNWIND_USE_COMPILER_RT) + list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}") +else() + append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s) + append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc) +endif() append_if(libraries LIBUNWIND_HAS_DL_LIB dl) if (LIBUNWIND_ENABLE_THREADS) append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread) Index: cmake/config-ix.cmake === --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -7,6 +7,7 @@ if (NOT LIBUNWIND_USE_COMPILER_RT) check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB) + check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB) endif() # libunwind is built with -nodefaultlibs, so we want all our checks to also @@ -25,8 +26,13 @@ if (LIBUNWIND_USE_COMPILER_RT) find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY) list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}") - elseif (LIBUNWIND_HAS_GCC_S_LIB) -list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) + else () +if (LIBUNWIND_HAS_GCC_S_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) +endif () +if (LIBUNWIND_HAS_GCC_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc) +endif () endif () if (MINGW) # Mingw64 requires quite a few "C" runtime libraries in order for basic ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D20449: [Basic] Change x86_64-windows-macho targets to use Windows-style va_lists.
cdavis5x added a comment. Extremely belated ping. https://reviews.llvm.org/D20449 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits