diff --git a/system/lib/libcxxabi/src/cxa_personality.cpp b/system/lib/libcxxabi/src/cxa_personality.cpp index f77c5393795ca..5cc7809385d5d 100644 --- a/system/lib/libcxxabi/src/cxa_personality.cpp +++ b/system/lib/libcxxabi/src/cxa_personality.cpp @@ -1126,13 +1126,15 @@ __gxx_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame, extern "C" _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code __gxx_wasm_personality_v0(void* exception_ptr) { struct _Unwind_Exception* exception_object = (struct _Unwind_Exception*)exception_ptr; + struct _Unwind_LandingPadContext* context = _Unwind_GetWasmLPadContext(); + // Reset the selector. - __wasm_lpad_context.selector = 0; + context->selector = 0; // Call personality function. Wasm does not have two-phase unwinding, so we // only do the search phase. - return __gxx_personality_imp(1, _UA_SEARCH_PHASE, exception_object->exception_class, exception_object, - (struct _Unwind_Context*)&__wasm_lpad_context); + return __gxx_personality_imp( + 1, _UA_SEARCH_PHASE, exception_object->exception_class, exception_object, (struct _Unwind_Context*)context); } #endif diff --git a/system/lib/libunwind/include/unwind_wasm.h b/system/lib/libunwind/include/unwind_wasm.h index 7bf3f30562bd8..f06e646b296ac 100644 --- a/system/lib/libunwind/include/unwind_wasm.h +++ b/system/lib/libunwind/include/unwind_wasm.h @@ -22,6 +22,9 @@ struct _Unwind_LandingPadContext { // Communication channel between compiler-generated user code and personality // function -extern thread_local struct _Unwind_LandingPadContext __wasm_lpad_context; +#ifdef __cplusplus +extern "C" +#endif + struct _Unwind_LandingPadContext *_Unwind_GetWasmLPadContext(void); #endif // __WASM_UNWIND_H__ diff --git a/system/lib/libunwind/src/Unwind-wasm.c b/system/lib/libunwind/src/Unwind-wasm.c index 6ee4b1fd36ee4..f85985e2db1d7 100644 --- a/system/lib/libunwind/src/Unwind-wasm.c +++ b/system/lib/libunwind/src/Unwind-wasm.c @@ -19,9 +19,14 @@ #include "unwind.h" #include -_LIBUNWIND_EXPORT thread_local struct _Unwind_LandingPadContext +thread_local struct _Unwind_LandingPadContext __wasm_lpad_context; +_LIBUNWIND_EXPORT struct _Unwind_LandingPadContext * +_Unwind_GetWasmLPadContext(void) { + return &__wasm_lpad_context; +} + /// Called by __cxa_throw. _LIBUNWIND_EXPORT _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *exception_object) { diff --git a/tools/system_libs.py b/tools/system_libs.py index f73efe18d6eaf..0c4b682414008 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1732,8 +1732,8 @@ class libcxx(ExceptionLibrary, MTLibrary, DebugLibrary): class libunwind(ExceptionLibrary, MTLibrary): name = 'libunwind' - # Because calls to _Unwind_CallPersonality are generated during LTO, libunwind - # can't currently be part of LTO. + # Because calls to _Unwind_GetWasmLPadContext are generated during LTO, + # libunwind can't currently be part of LTO. # See https://bugs.llvm.org/show_bug.cgi?id=44353 force_object_files = True