Skip to content

Build compiler-rt with C++ exception tag definition#603

Closed
kketch wants to merge 1 commit intoWebAssembly:mainfrom
kketch:compiler-rt-wasm-eh-tag
Closed

Build compiler-rt with C++ exception tag definition#603
kketch wants to merge 1 commit intoWebAssembly:mainfrom
kketch:compiler-rt-wasm-eh-tag

Conversation

@kketch
Copy link

@kketch kketch commented Mar 11, 2026

I tried compiling wasi-sdk's sysroot to build a C++ library for wasm32-wasip1 by following these instructions: https://github.com/WebAssembly/wasi-sdk/blob/main/CppExceptions.md.

However when running the resulting WASM module it tries to import a non existent exception tag: __cpp_exception.

I found out that LLVM's compiler-rt also needs to be built with -fwasm-exceptions otherwise the compiled object does not define the __cpp_exception tag used for C++ exceptions.

@kketch kketch changed the title Build compiler_rt with C++ exception tag definition Build compiler-rt with C++ exception tag definition Mar 11, 2026
necesary at runtime when wasm eh is enabled
@kketch kketch force-pushed the compiler-rt-wasm-eh-tag branch from 32e856a to 7dc9143 Compare March 11, 2026 11:11
@alexcrichton
Copy link
Collaborator

Thanks for the PR! I was just digging into this myself yesterday and there's been a few updates on this in the meantime. The problem here is that the exceptions-testing in CI is done with LLVM prior to 22, and this change you're running into happened in LLVM 22. This means that the exceptions-support for wasi-sdk is broken with LLVM 22, which is what the submodule in this repository contains.

The "true fix" here is a PR I sent yesterday upstream to LLVM -- llvm/llvm-project#185770 -- which moves the definition of __cpp_exception to libunwind rather than compiler-rt. I say "true fix" here because long-term I'd like to be able to support a single sysroot which both does and doesn't support C++ exceptions. This change, however, would prevent that from happening because compiler-rt is target-specific and doesn't get a chance to have multiple versions.

That's all basically a long way of saying -- thanks for the PR, I agree this is broken, but if you wouldn't mind I'd prefer to not land this solution. I'll try to follow-up with some submodule-patches today to get exceptions working once wasi-sdk-31 is released.

@kketch
Copy link
Author

kketch commented Mar 11, 2026

Thanks, after opening this PR I noticed the exceptions test was failing locally but not on CI, that makes more sense now.

@kketch kketch closed this Mar 11, 2026
@alexcrichton
Copy link
Collaborator

#606 is the PR I wanted to make, and that should fix exceptions with LLVM 22 by including upstream patches.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants