[compiler-rt] [WebAssembly] Define llvm-internal WasmEH tags in compiler-rt (PR #160959)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 15:28:33 PDT 2025


https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/160959

The `__c_longjmp` and `__cpp_exceptions` tags are used internally by llvm to implement setjmp/longjmp and C++ exception handling respectively.

These symbols were previously defined weakly in each object file but were recently converted to external references in #159143.  They now need to be defined somewhere in the runtime libraries.  I think compiler-rt is likely the most sensible place for them.

>From cd5939be4a28ae9459f4a058a195914440e780c7 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Mon, 15 Sep 2025 17:13:02 -0700
Subject: [PATCH] [WebAssembly] Define llvm-internal WasmEH tags in compiler-rt

The `__c_longjmp` and `__cpp_exceptions` tags are used internally by
llvm to implement setjmp/longjmp and C++ exception handling
respectively.

These symbols were previously defined weakly in each object file but
were recently converted to external references in #159143.  They now
need to be defined somewhere in the runtime libraries.  I think
compiler-rt is likely the most sensible place for them.
---
 compiler-rt/lib/builtins/CMakeLists.txt       | 11 ++++----
 compiler-rt/lib/builtins/wasm/__c_longjmp.S   | 26 +++++++++++++++++++
 .../lib/builtins/wasm/__cpp_exception.S       | 26 +++++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)
 create mode 100644 compiler-rt/lib/builtins/wasm/__c_longjmp.S
 create mode 100644 compiler-rt/lib/builtins/wasm/__cpp_exception.S

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 0d7fc65cfd3e9..9095b056ae782 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -816,14 +816,15 @@ set(s390x_SOURCES
   ${GENERIC_TF_SOURCES}
 )
 
-set(wasm32_SOURCES
-  ${GENERIC_TF_SOURCES}
-  ${GENERIC_SOURCES}
-)
-set(wasm64_SOURCES
+
+set(wasm_SOURCES
+  wasm/__c_longjmp.S
+  wasm/__cpp_exceptions.S
   ${GENERIC_TF_SOURCES}
   ${GENERIC_SOURCES}
 )
+set(wasm32_SOURCES ${wasm_SOURCES})
+set(wasm64_SOURCES ${wasm_SOURCES})
 
 set(ve_SOURCES
   ve/grow_stack.S
diff --git a/compiler-rt/lib/builtins/wasm/__c_longjmp.S b/compiler-rt/lib/builtins/wasm/__c_longjmp.S
new file mode 100644
index 0000000000000..d130862fd5c41
--- /dev/null
+++ b/compiler-rt/lib/builtins/wasm/__c_longjmp.S
@@ -0,0 +1,26 @@
+//===-- __c_longjmp.S - Implement __c_longjmp -----------------------------===//
+//
+// 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 __c_longjmp which LLVM uses to implenmet setjmp/longjmp
+// when Wasm EH is enabled.
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef __wasm_exception_handling__
+
+#ifdef __wasm64__
+#define PTR i64
+#else
+#define PTR i32
+#endif
+
+.globl __c_longjmp
+.tagtype __c_longjmp PTR
+__c_longjmp:
+
+#endif // !__wasm_exception_handling__
diff --git a/compiler-rt/lib/builtins/wasm/__cpp_exception.S b/compiler-rt/lib/builtins/wasm/__cpp_exception.S
new file mode 100644
index 0000000000000..d805b79abfada
--- /dev/null
+++ b/compiler-rt/lib/builtins/wasm/__cpp_exception.S
@@ -0,0 +1,26 @@
+//===-- __cpp_exception.S - Implement __cpp_exception.S -------------------===//
+//
+// 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__



More information about the llvm-commits mailing list