From b05e16c48b4f11394be08919ab249c11bcab96d5 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 14 Apr 2023 15:48:13 -0700 Subject: [PATCH] Add a stub cxa_free_exception cxa_noexception.cpp In some cases cxa_free_exception can be called by compiler-generated code, which may cause linkage failure in emscripten's default mode which allows throwing but not catching. This PR adds a "stub" __cxa_free_exception to go along with __cxa_allocate_exception. --- system/lib/libcxxabi/src/cxa_noexception.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/system/lib/libcxxabi/src/cxa_noexception.cpp b/system/lib/libcxxabi/src/cxa_noexception.cpp index 1097f75866983..1ef53bf79f243 100644 --- a/system/lib/libcxxabi/src/cxa_noexception.cpp +++ b/system/lib/libcxxabi/src/cxa_noexception.cpp @@ -58,6 +58,22 @@ void *__cxa_allocate_exception(size_t thrown_size) _NOEXCEPT { char* allocation = (char*)malloc(thrown_size + sizeof(__cxa_exception)); return allocation + sizeof(__cxa_exception); } + +static +inline +__cxa_exception* +cxa_exception_from_thrown_object(void* thrown_object) +{ + return static_cast<__cxa_exception*>(thrown_object) - 1; +} + +// Free a __cxa_exception object allocated with __cxa_allocate_exception. +void __cxa_free_exception(void *thrown_object) _NOEXCEPT { + // Compute the size of the padding before the header. + char *raw_buffer = + ((char *)cxa_exception_from_thrown_object(thrown_object)); + free((void *)raw_buffer); +} #endif } // extern "C"