Skip to content

Add libc++abi Objective-C exception bridge for WebAssembly - #417

Open
HendrikHuebner wants to merge 1 commit into
gnustep:masterfrom
HendrikHuebner:wasm-exceptions
Open

Add libc++abi Objective-C exception bridge for WebAssembly#417
HendrikHuebner wants to merge 1 commit into
gnustep:masterfrom
HendrikHuebner:wasm-exceptions

Conversation

@HendrikHuebner

@HendrikHuebner HendrikHuebner commented Aug 19, 2026

Copy link
Copy Markdown

This PR is the counterpart to llvm/llvm-project#215562.

For native WebAssembly exceptions, Clang emits references to the personality function __gxx_wasm_personality_v0.
In order to support Objective-C exception semantics for WASM targets, we could either define our own personality function, or box Objective-C exceptions inside of C++ exceptions and rely on emscriptens libc++abi / exception runtime to handle those correctly for us.

To support Objective-C catch semantics, we need to supply our own type info objects which override the can_catch method of libc++abi's internal __shim_type_info.

For now, this PR is Apple compatible but does not implement the non-compatible mode.

I'll leave this as future work. I'm not sure whether AppleCompatibleMode is currently implemented as it was originally intended, since disabling compatibility would affect both @catch and C++ catch handler semantics as it is currently written, making them both use static-type matching instead of dynamic-type matching.

@davidchisnall

Copy link
Copy Markdown
Member

This looks very similar to the code in objcxx_eh_mingw, which also wraps C++ exceptions. Is there a reason to have an entirely new parallel implementation for WAsm?

@HendrikHuebner

HendrikHuebner commented Aug 19, 2026

Copy link
Copy Markdown
Author

Conceptually its doing the same thing as objcxx_eh_private.h by wrapping Objective-C exceptions in C++ exceptions.

The problem is that both rely on internal implementation details from different standard libraries.

For targetting emscripten we need our type infos to be subclasses of libc++abi's __shim_type_info, which is itself a subclass of std::type_info.

The existing implementation relies on gcc/libsupc++ implementation details instead, where the std::type_info already contains the __do_catch member and whatever else we need to override.

I don't think these implementations can be merged, sadly.

Edit: maybe some things could be reused, such as the implementation of __do_catch/can_catch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants