-
Notifications
You must be signed in to change notification settings - Fork 238
enable exception support for shared libraries #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexcrichton
merged 1 commit into
WebAssembly:main
from
dicej:shared-library-exceptions-v2
Oct 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| diff --git a/libcxxabi/src/cxa_personality.cpp b/libcxxabi/src/cxa_personality.cpp | ||
| index c5050e46c0e8..da2d8b2599d9 100644 | ||
| --- a/libcxxabi/src/cxa_personality.cpp | ||
| +++ b/libcxxabi/src/cxa_personality.cpp | ||
| @@ -1011,9 +1011,7 @@ static inline void get_landing_pad(__cxa_catch_temp_type &dest, | ||
| #endif | ||
| } | ||
|
|
||
| -#ifdef __WASM_EXCEPTIONS__ | ||
| -_Unwind_Reason_Code __gxx_personality_wasm0 | ||
| -#elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) | ||
| +#if (defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)) || defined(__WASM_EXCEPTIONS__) | ||
| static _Unwind_Reason_Code __gxx_personality_imp | ||
| #else | ||
| _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code | ||
| @@ -1114,6 +1112,22 @@ __gxx_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame, | ||
| } | ||
| #endif | ||
|
|
||
| +#ifdef __WASM_EXCEPTIONS__ | ||
| +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. | ||
| + 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*)context); | ||
| +} | ||
| +#endif | ||
| + | ||
| #else | ||
|
|
||
| extern "C" _Unwind_Reason_Code __gnu_unwind_frame(_Unwind_Exception*, _Unwind_Context*); | ||
| diff --git a/libunwind/include/unwind.h b/libunwind/include/unwind.h | ||
| index b1775d3a3dec..93a9d92f327d 100644 | ||
| --- a/libunwind/include/unwind.h | ||
| +++ b/libunwind/include/unwind.h | ||
| @@ -61,6 +61,10 @@ typedef struct _Unwind_Context _Unwind_Context; // opaque | ||
| #include <unwind_itanium.h> | ||
| #endif | ||
|
|
||
| +#if defined(__WASM_EXCEPTIONS__) | ||
| +#include <unwind_wasm.h> | ||
| +#endif | ||
| + | ||
| typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) | ||
| (int version, | ||
| _Unwind_Action actions, | ||
| diff --git a/libunwind/include/unwind_wasm.h b/libunwind/include/unwind_wasm.h | ||
| new file mode 100644 | ||
| index 000000000000..66d1792919ab | ||
| --- /dev/null | ||
| +++ b/libunwind/include/unwind_wasm.h | ||
| @@ -0,0 +1,28 @@ | ||
| +//===----------------------------------------------------------------------===// | ||
| +// | ||
| +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| +// See https://llvm.org/LICENSE.txt for license information. | ||
| +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| +// | ||
| +//===----------------------------------------------------------------------===// | ||
| + | ||
| +#ifndef __WASM_UNWIND_H__ | ||
| +#define __WASM_UNWIND_H__ | ||
| + | ||
| +struct _Unwind_LandingPadContext { | ||
| + // Input information to personality function | ||
| + uintptr_t lpad_index; // landing pad index | ||
| + uintptr_t lsda; // LSDA address | ||
| + | ||
| + // Output information computed by personality function | ||
| + uintptr_t selector; // selector value | ||
| +}; | ||
| + | ||
| +// Communication channel between compiler-generated user code and personality | ||
| +// function | ||
| +#ifdef __cplusplus | ||
| +extern "C" | ||
| +#endif | ||
| + struct _Unwind_LandingPadContext *_Unwind_GetWasmLPadContext(void); | ||
| + | ||
| +#endif // __WASM_UNWIND_H__ | ||
| diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c | ||
| index 2e949d005b8f..f17eeb27e97b 100644 | ||
| --- a/libunwind/src/Unwind-wasm.c | ||
| +++ b/libunwind/src/Unwind-wasm.c | ||
| @@ -19,45 +19,11 @@ | ||
| #include "unwind.h" | ||
| #include <threads.h> | ||
|
|
||
| -_Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions, | ||
| - uint64_t exceptionClass, | ||
| - _Unwind_Exception *unwind_exception, | ||
| - _Unwind_Context *context); | ||
| - | ||
| -struct _Unwind_LandingPadContext { | ||
| - // Input information to personality function | ||
| - uintptr_t lpad_index; // landing pad index | ||
| - uintptr_t lsda; // LSDA address | ||
| - | ||
| - // Output information computed by personality function | ||
| - uintptr_t selector; // selector value | ||
| -}; | ||
| - | ||
| -// Communication channel between compiler-generated user code and personality | ||
| -// function | ||
| thread_local struct _Unwind_LandingPadContext __wasm_lpad_context; | ||
|
|
||
| -/// Calls to this function are in landing pads in compiler-generated user code. | ||
| -/// In other EH schemes, stack unwinding is done by libunwind library, which | ||
| -/// calls the personality function for each frame it lands. On the other hand, | ||
| -/// WebAssembly stack unwinding process is performed by a VM, and the | ||
| -/// personality function cannot be called from there. So the compiler inserts a | ||
| -/// call to this function in landing pads in the user code, which in turn calls | ||
| -/// the personality function. | ||
| -_Unwind_Reason_Code _Unwind_CallPersonality(void *exception_ptr) { | ||
| - struct _Unwind_Exception *exception_object = | ||
| - (struct _Unwind_Exception *)exception_ptr; | ||
| - _LIBUNWIND_TRACE_API("_Unwind_CallPersonality(exception_object=%p)", | ||
| - (void *)exception_object); | ||
| - | ||
| - // Reset the selector. | ||
| - __wasm_lpad_context.selector = 0; | ||
| - | ||
| - // Call personality function. Wasm does not have two-phase unwinding, so we | ||
| - // only do the search phase. | ||
| - return __gxx_personality_wasm0( | ||
| - 1, _UA_SEARCH_PHASE, exception_object->exception_class, exception_object, | ||
| - (struct _Unwind_Context *)&__wasm_lpad_context); | ||
| +_LIBUNWIND_EXPORT struct _Unwind_LandingPadContext * | ||
| +_Unwind_GetWasmLPadContext(void) { | ||
| + return &__wasm_lpad_context; | ||
| } | ||
|
|
||
| /// Called by __cxa_throw. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to avoid manually splitting/merging
*.patchfiles? I've historically attempted to keep the patch files as literal output ofcurl https://github.com/llvm/llvm-project/pull/208597.diff -L -o ./src/llvm-pr-208597.patchfor example which makes it a bit easier to maintain over time. I couldn't do that for some versions in the past when things conflicted, however.Another way to put this: if literal
*.patchfiles-from-prs don't work, could you expand on why? (also the rationale for the sysroot/toolchain split)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few reasons:
git difffor each PR doesn't apply to LLVM 23 due to other changes which have happened on LLVMmain, so I had to edit them it as part of the backportwasi-sdk-toolchain.cmakeor only inwasi-sdk-sysroot.cmake, but only the other one is built, then it won't have the required changes, hence the split.git diff ... -R --checkwas erroring when they were two separate files. I later saw your reverse-the-list trick in thewasi-sdk-toolchain.cmakehistory which might address that, though..llfiles weren't relevant, so I stripped them outHappy to revisit any of that if there's a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I kind of figure it was something like that but wanted to double check, yeah, and it's ok to land as-is just wanted to have some written-down rationale as well