Skip to content

[WebAssembly] Move __cpp_exception to libunwind - #185770

Merged
sbc100 merged 1 commit into
llvm:mainfrom
alexcrichton:wasm-exceptions-libunwind
Mar 11, 2026
Merged

sbc100 merged 1 commit into
llvm:mainfrom
alexcrichton:wasm-exceptions-libunwind

Conversation

@alexcrichton

@alexcrichton alexcrichton commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

The __cpp_exception symbol is now defined in libunwind instead of
compiler-rt. This is moved for a few reasons, but the primary reason is
that compiler-rt is linked duplicate-ly into all shared objects meaning
that it's not suitable for define-once symbols such as
__cpp_exception. By moving the definition to the user of the symbol,
libunwind itself, that guarantees that the symbol should be defined
exactly once and only when appropriate. A secondary reason for this
movement is that it avoids the need to compile compiler-rt twice: once
with exception and once without, and instead the same build can be used
for both exceptions-and-not.

@llvmbot

llvmbot commented Mar 10, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-libunwind

Author: Alex Crichton (alexcrichton)

Changes

This commit is an extension of some work in [wasi-sdk] to get C++ exceptions working on WASI targets. This is intended to complement the work in #168449 and together is enough to get C++ exceptions working within wasi-sdk. The changes here are:

  • The __cpp_exception symbol is now defined in libunwind instead of compiler-rt. This is moved for a few reasons, but the primary reason is that compiler-rt is linked duplicate-ly into all shared objects meaning that it's not suitable for define-once symbols such as __cpp_exception. By moving the definition to the user of the symbol, libunwind itself, that guarantees that the symbol should be defined exactly once and only when appropriate. A secondary reason for this movement is that it avoids the need to compile compiler-rt twice: once with exception and once without, and instead the same build can be used for both exceptions-and-not.

  • A minor compile error is fixed in libunwind's assembly.h. Without this the preexisting sources fail to compile, so this is along the lines of #168449 in terms of getting the in-tree sources to compile for wasm exceptions.


Full diff: https://github.com/llvm/llvm-project/pull/185770.diff

5 Files Affected:

  • (modified) compiler-rt/lib/builtins/CMakeLists.txt (-1)
  • (removed) compiler-rt/lib/builtins/wasm/__cpp_exception.S (-26)
  • (modified) libunwind/src/Unwind-wasm.c (+17)
  • (modified) libunwind/src/assembly.h (+3)
  • (modified) llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni (-1)
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 6c27f6d4d529e..f0570a9092f40 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -891,7 +891,6 @@ set(s390x_SOURCES
 
 set(wasm_SOURCES
   wasm/__c_longjmp.S
-  wasm/__cpp_exception.S
   ${GENERIC_TF_SOURCES}
   ${GENERIC_SOURCES}
 )
diff --git a/compiler-rt/lib/builtins/wasm/__cpp_exception.S b/compiler-rt/lib/builtins/wasm/__cpp_exception.S
deleted file mode 100644
index 0496e1dbf6158..0000000000000
--- a/compiler-rt/lib/builtins/wasm/__cpp_exception.S
+++ /dev/null
@@ -1,26 +0,0 @@
-//===-- __cpp_exception.S - Implement __cpp_exception ---------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements __cpp_exception which LLVM uses to implement exception
-// handling when Wasm EH is enabled.
-//
-//===----------------------------------------------------------------------===//
-
-#ifdef __wasm_exception_handling__
-
-#ifdef __wasm64__
-#define PTR i64
-#else
-#define PTR i32
-#endif
-
-.globl __cpp_exception
-.tagtype __cpp_exception PTR
-__cpp_exception:
-
-#endif // !__wasm_exception_handling__
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 2f4498c3f3989..44d284ba85b8f 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -69,6 +69,23 @@ _Unwind_RaiseException(_Unwind_Exception *exception_object) {
   __builtin_wasm_throw(0, exception_object);
 }
 
+// Define the `__cpp_exception` symbol which `__builtin_wasm_throw` above will
+// reference. This is defined here in `libunwind` as the single canonical
+// definition for this API and it's required for users to ensure that there's
+// only one copy of `libunwind` within a wasm module to ensure this is only
+// defined once and exactly once.
+__asm__(
+".globl __cpp_exception\n"
+#if defined(__wasm32__)
+".tagtype __cpp_exception i32\n"
+#elif defined(__wasm64__)
+".tagtype __cpp_exception i64\n"
+#else
+# error "Unsupported Wasm architecture"
+#endif
+"__cpp_exception:\n"
+);
+
 /// Called by __cxa_end_catch.
 _LIBUNWIND_EXPORT void
 _Unwind_DeleteException(_Unwind_Exception *exception_object) {
diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
index 84c9d526f1d75..2167326605b8a 100644
--- a/libunwind/src/assembly.h
+++ b/libunwind/src/assembly.h
@@ -253,6 +253,9 @@ aliasname:                                                                     \
 #define WEAK_ALIAS(name, aliasname)
 #define NO_EXEC_STACK_DIRECTIVE
 
+#elif defined(__wasm__)
+#define NO_EXEC_STACK_DIRECTIVE
+
 // clang-format on
 #else
 
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni
index 2ac71aa8e8367..c9eeede16e3eb 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni
@@ -539,7 +539,6 @@ if (current_cpu == "ve") {
 if (current_cpu == "wasm") {
   builtins_sources += [
     "wasm/__c_longjmp.S",
-    "wasm/__cpp_exception.S",
   ]
 }
 

@alexcrichton

Copy link
Copy Markdown
Contributor Author

@sbc100 would you be up for reviewing this?

also, while I've got you here, are there any blockers to merging #168449 with it being approved now?

@github-actions

github-actions Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@sbc100

sbc100 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

__cpp_exception changes LGTM.

Regarding the assembly.h change, do you know why we haven't need that in emscripten? @aheejin have you run into issues with assembly.h before?

@sbc100

sbc100 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Oh I see, libunwind/src/assembly.h is only used by libunwind/src/UnwindRegistersRestore.S and libunwind/src/UnwindRegistersSave.S which themselves should be no-op under wasm and we just don't compile those in emscripten.

I wonder if we should instead widen the #if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) guard on those assembly files to include the entire file? It seems like they should be 100% no-op in those cases?

@alexcrichton
alexcrichton force-pushed the wasm-exceptions-libunwind branch from e4ba5cd to 07b8ce3 Compare March 11, 2026 00:18
@alexcrichton

Copy link
Copy Markdown
Contributor Author

Oh good catch, turns out that #162581 already made these files "conditional enough" to the point that there's no need for that change any more. I've updated the commit message and backed out the assembly.h change as it's no longer needed.

@alexcrichton alexcrichton changed the title Fix compiling/using libunwind for wasm targets [WebAssembly] Move __cpp_exception to libunwind Mar 11, 2026
@sbc100

sbc100 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Do we still need the first paragraph of the PR description? Paragraph 2 seems like good description of the change on its own?

The `__cpp_exception` symbol is now defined in libunwind instead of
compiler-rt. This is moved for a few reasons, but the primary reason is
that compiler-rt is linked duplicate-ly into all shared objects meaning
that it's not suitable for define-once symbols such as
`__cpp_exception`. By moving the definition to the user of the symbol,
libunwind itself, that guarantees that the symbol should be defined
exactly once and only when appropriate. A secondary reason for this
movement is that it avoids the need to compile compiler-rt twice: once
with exception and once without, and instead the same build can be used
for both exceptions-and-not.
@alexcrichton
alexcrichton force-pushed the wasm-exceptions-libunwind branch from 07b8ce3 to d702761 Compare March 11, 2026 00:24
@alexcrichton

Copy link
Copy Markdown
Contributor Author

Good point yeah, and sounds reasonable to me, removed from both the PR and the commit

@sbc100

sbc100 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

We should probably link to #160959 where add these symbols to compiler-rt (which it turns out was the wrong place for them).

@sbc100

sbc100 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

I wonder if we should also move __c_longjmp out of compiler-rt?

@sbc100
sbc100 enabled auto-merge (squash) March 11, 2026 00:28
@sbc100
sbc100 merged commit a3f2823 into llvm:main Mar 11, 2026
13 checks passed
@alexcrichton
alexcrichton deleted the wasm-exceptions-libunwind branch March 11, 2026 00:45
@alexcrichton

Copy link
Copy Markdown
Contributor Author

Agreed yeah, I suspect that longjmp/setjmp in wasi-libc are probably broken since the change awhile back to avoid adding a weak definition of __c_longjmp to all objects. The main motivation of this PR was fixing wasi-sdk with LLVM 22 and since I needed to add the symbol to libunwind I figured I'd go ahead and move it. I'll test out what's needed for setjmp/longjmp in wasi-libc and I'll report back here with a follow-up to probably just delete the symbol in compiler-rt.

@llvm-ci

llvm-ci commented Mar 11, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder fuchsia-x86_64-linux running on fuchsia-debian-64-us-central1-a-1 while building compiler-rt,libunwind,llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/35499

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
  Passed           : 49585 (97.01%)
  Expectedly Failed:    24 (0.05%)
[1524/1526] Linking CXX executable unittests/Frontend/LLVMFrontendTests
[1525/1526] Running the LLVM regression tests
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using ld.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/ld.lld
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using lld-link: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/lld-link
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using ld64.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/ld64.lld
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using wasm-ld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/wasm-ld
-- Testing: 64055 tests, 60 workers --
Testing:  0.
FAIL: LLVM :: CodeGen/AArch64/fence-singlethread.ll (4180 of 64055)
******************** TEST 'LLVM :: CodeGen/AArch64/fence-singlethread.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-linux-gnu /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=LINUX
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-linux-gnu /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o -
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=LINUX
# RUN: at line 2
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o -
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# RUN: at line 3
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - -global-isel | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - -global-isel
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# RUN: at line 4
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64 /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -filetype=obj -o /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64 /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -filetype=obj -o /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# RUN: at line 5
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llvm-objdump -d /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=OBJ
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llvm-objdump -d /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=OBJ
# .---command stderr------------
# | /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll:7:12: error: OBJ-NOT: excluded string found in input
# | ; OBJ-NOT: dmb
# |            ^
# | <stdin>:2:61: note: found here
# | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp: file format elf64-littleaarch64
# |                                                             ^~~
# | 
# | Input file: <stdin>
# | Check file: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
Step 7 (check) failure: check (failure)
...
  Passed           : 49585 (97.01%)
  Expectedly Failed:    24 (0.05%)
[1524/1526] Linking CXX executable unittests/Frontend/LLVMFrontendTests
[1525/1526] Running the LLVM regression tests
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using ld.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/ld.lld
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using lld-link: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/lld-link
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using ld64.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/ld64.lld
llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:569: note: using wasm-ld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/wasm-ld
-- Testing: 64055 tests, 60 workers --
Testing:  0.
FAIL: LLVM :: CodeGen/AArch64/fence-singlethread.ll (4180 of 64055)
******************** TEST 'LLVM :: CodeGen/AArch64/fence-singlethread.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-linux-gnu /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=LINUX
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-linux-gnu /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o -
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=LINUX
# RUN: at line 2
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o -
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# RUN: at line 3
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - -global-isel | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64-apple-ios /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -o - -global-isel
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=IOS
# RUN: at line 4
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64 /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -filetype=obj -o /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llc -mtriple=aarch64 /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll -filetype=obj -o /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# RUN: at line 5
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llvm-objdump -d /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=OBJ
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/llvm-objdump -d /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp
# executed command: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/bin/FileCheck /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll --check-prefix=OBJ
# .---command stderr------------
# | /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll:7:12: error: OBJ-NOT: excluded string found in input
# | ; OBJ-NOT: dmb
# |            ^
# | <stdin>:2:61: note: found here
# | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-jovedmbu/test/CodeGen/AArch64/Output/fence-singlethread.ll.tmp: file format elf64-littleaarch64
# |                                                             ^~~
# | 
# | Input file: <stdin>
# | Check file: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/test/CodeGen/AArch64/fence-singlethread.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:

sbc100 pushed a commit that referenced this pull request Mar 11, 2026
This is similar to #185770 where it removes an
exception-handling-related symbol from `compiler-rt` in favor of having
definitions elsewhere. The compiler-rt library is linked into all shared
objects, for example, which can result in duplicate definitions of a
symbol where this tag wants to have one unique definition. The intention
behind this commit is to defer the definition of this symbol to
downstream libraries, such as the definition of `longjmp` itself. An
example of this is WebAssembly/wasi-libc#772 where the responsibility of
defining this symbol now lies with wasi-libc.
alexcrichton added a commit to alexcrichton/wasi-sdk that referenced this pull request Mar 11, 2026
This commit collects together some LLVM PRs, some changes in the build
configuration here, and some thoughts from WebAssembly#565 and related issues.
Specifically the changes here are:

* The patch for llvm/llvm-project#168449 is updated to its upstream
  (unlanded) form.
* Patches for the (landed) llvm/llvm-project#185770 and
  llvm/llvm-project#185775 are added.
* The `WASI_SDK_EXCEPTIONS` configuration is now either `ON`, `OFF`, or
  `DUAL`. The default depends on the version of Clang in use, where
  23.0.0+ (which isn't released officially yet) will be `DUAL` and
  otherwise it's `OFF`. CI for our custom-built patched toolchain
  defaults to `DUAL`.
* In `DUAL` mode libcxx is built twice into two different directories,
  once with exceptions and once without. This is supported by LLVM
  patches and means that Clang will select the right set of libraries
  based on compiler flags.

The end result here is that the produced toolchain from this repository,
by default, supports C++ exceptions. Additionally if exceptions-related
flags are not passed then the final binary will not use C++ exceptions
nor require the wasm exception-handling proposal.

There's still follow-up work from WebAssembly#565, such as:

* Subjectively it feels wordy to pass `-fwasm-exceptions` vs
  `-fexceptions`.
* Personally I think `-mllvm -wasm-use-legacy-eh=false` should become
  the default upstream.
* Subjectively I don't think that `-lunwind` should be necessary and it
  should be injected automatically with `-fwasm-exceptions` (or
  `-fexceptions`).
* Shared libraries for exceptions remain disabled due to build errors I
  do not personally know how to resolve.

I'll file follow-up issues for these once this has landed since they're
more minor compared to the main body of "anything works".

Closes WebAssembly#334
Closes WebAssembly#565
alexcrichton added a commit to alexcrichton/wasi-sdk that referenced this pull request Mar 30, 2026
This commit collects together some LLVM PRs, some changes in the build
configuration here, and some thoughts from WebAssembly#565 and related issues.
Specifically the changes here are:

* The patch for llvm/llvm-project#168449 is updated to its upstream
  (unlanded) form.
* Patches for the (landed) llvm/llvm-project#185770 and
  llvm/llvm-project#185775 are added.
* The `WASI_SDK_EXCEPTIONS` configuration is now either `ON`, `OFF`, or
  `DUAL`. The default depends on the version of Clang in use, where
  23.0.0+ (which isn't released officially yet) will be `DUAL` and
  otherwise it's `OFF`. CI for our custom-built patched toolchain
  defaults to `DUAL`.
* In `DUAL` mode libcxx is built twice into two different directories,
  once with exceptions and once without. This is supported by LLVM
  patches and means that Clang will select the right set of libraries
  based on compiler flags.

The end result here is that the produced toolchain from this repository,
by default, supports C++ exceptions. Additionally if exceptions-related
flags are not passed then the final binary will not use C++ exceptions
nor require the wasm exception-handling proposal.

There's still follow-up work from WebAssembly#565, such as:

* Subjectively it feels wordy to pass `-fwasm-exceptions` vs
  `-fexceptions`.
* Personally I think `-mllvm -wasm-use-legacy-eh=false` should become
  the default upstream.
* Subjectively I don't think that `-lunwind` should be necessary and it
  should be injected automatically with `-fwasm-exceptions` (or
  `-fexceptions`).
* Shared libraries for exceptions remain disabled due to build errors I
  do not personally know how to resolve.

I'll file follow-up issues for these once this has landed since they're
more minor compared to the main body of "anything works".

Closes WebAssembly#334
Closes WebAssembly#565
alexcrichton added a commit to WebAssembly/wasi-sdk that referenced this pull request Apr 8, 2026
This commit collects together some LLVM PRs, some changes in the build
configuration here, and some thoughts from #565 and related issues.
Specifically the changes here are:

* The patch for llvm/llvm-project#168449 is updated to its upstream
(unlanded) form.
* Patches for the (landed) llvm/llvm-project#185770 and
llvm/llvm-project#185775 are added.
* The `WASI_SDK_EXCEPTIONS` configuration is now either `ON`, `OFF`, or
`DUAL`. The default depends on the version of Clang in use, where
23.0.0+ (which isn't released officially yet) will be `DUAL` and
otherwise it's `OFF`. CI for our custom-built patched toolchain defaults
to `DUAL`.
* In `DUAL` mode libcxx is built twice into two different directories,
once with exceptions and once without. This is supported by LLVM patches
and means that Clang will select the right set of libraries based on
compiler flags.

The end result here is that the produced toolchain from this repository,
by default, supports C++ exceptions. Additionally if exceptions-related
flags are not passed then the final binary will not use C++ exceptions
nor require the wasm exception-handling proposal.

There's still follow-up work from #565, such as:

* Subjectively it feels wordy to pass `-fwasm-exceptions` vs
`-fexceptions`.
* Personally I think `-mllvm -wasm-use-legacy-eh=false` should become
the default upstream.
* Subjectively I don't think that `-lunwind` should be necessary and it
should be injected automatically with `-fwasm-exceptions` (or
`-fexceptions`).
* Shared libraries for exceptions remain disabled due to build errors I
do not personally know how to resolve.

I'll file follow-up issues for these once this has landed since they're
more minor compared to the main body of "anything works".

Closes #334
Closes #565

---------

Co-authored-by: Joel Dice <[email protected]>
sbc100 pushed a commit to emscripten-core/emscripten that referenced this pull request Aug 10, 2026
#27496)

This makes `-fwasm-exceptions` link the Wasm EH runtime independently of
C++ linking.

Wasm EH objects can be produced by non-C++ frontends - notably rustc,
whose precompiled std uses Wasm exceptions for unwinding and which
invokes `emcc` (not `em++`) as its linker. Since `DEFAULT_TO_CXX` was
disabled by default in #27469, any rust-driven emcc link now fails with:

```
wasm-ld: error: libstd-*.rlib: undefined symbol: __cpp_exception
wasm-ld: error: libpanic_unwind-*.rlib: undefined symbol: _Unwind_RaiseException
```

because both libunwind and the `__cpp_exception` tag (previously defined
in libc++abi) were only linked under `LINK_AS_CXX`. The tag and the
unwinding runtime are language-agnostic runtime support for the Wasm EH
LLVM lowering, not part of the C++ ABI surface.

This PR now includes #27498 as its base, which provides the same
`_Unwind_*` linkability for the non-Wasm-EH modes on the JS side.

What's implemented:

* The `__cpp_exception` tag definition moves from libc++abi
(`__cpp_exception.S`) into libunwind's `Unwind-wasm.c` as inline asm,
matching upstream llvm/llvm-project#185770.
* libunwind is linked whenever `WASM_EXCEPTIONS` is enabled, rather than
only when linking as C++.

Test coverage extends `test_libunwind` from #27498 with `wasm_eh` and
`wasm_legacy_eh` variants (completing its TODO), and adds
`test_cpp_exception_tag` linking an asm object that throws the tag
directly from a C caller - the same reference pattern as rustc-generated
catch/throw sites - which fails to link without this change. The
now-unneeded `DEFAULT_TO_CXX` workaround is dropped from
`test_wasi_with_sjlj`. Existing C++ Wasm EH coverage
(`core0.test_exceptions_*`) passes unchanged.

_Made with AI assistance under my review_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants