[libunwind] [libunwind] Move wasm definition of `__cpp_exception` (PR #195681)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 09:05:01 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libunwind

Author: Alex Crichton (alexcrichton)

<details>
<summary>Changes</summary>

This moves the definition of `__cpp_exception` from an inline assembly definition in the `Unwind-wasm.c` file of libunwind to a dedicated `*.S` external file, for now called `__cpp_exception.S` to match Emscripten. This is done due to a bug in LTO, #<!-- -->195311, where the inline assembly definition means that compiling with LTO leads to linking failures. This is intended to be a temporary workaround until the true underlying issue is fixed.

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


3 Files Affected:

- (modified) libunwind/src/CMakeLists.txt (+1) 
- (modified) libunwind/src/Unwind-wasm.c (-15) 
- (added) libunwind/src/__cpp_exception.S (+34) 


``````````diff
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 6e947039fb0d5..52dfe81fef6c1 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -30,6 +30,7 @@ set_source_files_properties(${LIBUNWIND_C_SOURCES}
 set(LIBUNWIND_ASM_SOURCES
     UnwindRegistersRestore.S
     UnwindRegistersSave.S
+    __cpp_exception.S
     )
 
 set(LIBUNWIND_HEADERS
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index c0ca9b775d244..2f4498c3f3989 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -69,21 +69,6 @@ _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/__cpp_exception.S b/libunwind/src/__cpp_exception.S
new file mode 100644
index 0000000000000..6e35a5e1f6103
--- /dev/null
+++ b/libunwind/src/__cpp_exception.S
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#if !defined(__wasm__)
+
+#include "assembly.h"
+
+NO_EXEC_STACK_DIRECTIVE
+
+#endif // !defined(__wasm__)
+
+#ifdef __WASM_EXCEPTIONS__
+
+// Define the `__cpp_exception` symbol which `__builtin_wasm_throw` 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.
+.globl __cpp_exception
+#if defined(__wasm32__)
+.tagtype __cpp_exception i32
+#elif defined(__wasm64__)
+.tagtype __cpp_exception i64
+#else
+#error "Unsupported Wasm architecture"
+#endif
+__cpp_exception:
+
+#endif // defined(__WASM_EXCEPTIONS__)

``````````

</details>


https://github.com/llvm/llvm-project/pull/195681


More information about the cfe-commits mailing list