diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 6c27f6d4d529..f0570a9092f4 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 0496e1dbf615..000000000000 --- 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 2f4498c3f398..c0ca9b775d24 100644 --- a/libunwind/src/Unwind-wasm.c +++ b/libunwind/src/Unwind-wasm.c @@ -69,6 +69,21 @@ _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/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/sources.gni index 2ac71aa8e836..c9eeede16e3e 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", ] }