Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ jobs:
title: "core3+extras"
test_targets: "
lto2.test_dylink_syslibs_all
lto0.test_exceptions_allowed_uncaught
core3
core2g.test_externref
corez.test_dylink_iostream
Expand Down
3 changes: 2 additions & 1 deletion system/lib/libcxxabi/src/cxa_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace __cxxabiv1 {
struct _LIBCXXABI_HIDDEN __cxa_exception {
size_t referenceCount;
std::type_info *exceptionType;
void (*exceptionDestructor)(void *);
// In wasm, destructors return 'this' as in ARM
void* (*exceptionDestructor)(void *);
Comment on lines +27 to +28
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember adding this years ago... I guess it was somehow lost during library updates. https://github.com/aheejin/emscripten/blob/d57db5bea1719319a680699c50b91fa3d88fa0ec/system/lib/libcxxabi/src/cxa_exception.hpp#L41-L46

By the way, wouldn't it be better to add ifdef as in the old code, in case when we try to upstream our changes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire block is already within #ifdef __USING_EMSCRIPTEN_EXCEPTIONS__.

BTW, is there some way we can undef the destructors return 'this' as in ARM decision, since it makes all these patches needed? Is there some reason we need this behaviour?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? AFAIK @sunfishcode added that way back at the beginning, as a performance optimization. I don't know how much impact it actually has.

uint8_t caught;
uint8_t rethrown;
void *adjustedPtr;
Expand Down
13 changes: 7 additions & 6 deletions system/lib/libcxxabi/src/cxa_exception_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

// Define to enable extra debugging on stderr.
#if EXCEPTIONS_DEBUG
#define DEBUG printf
#include "emscripten/console.h"
#define DEBUG _emscripten_errf
#else
#define DEBUG(...)
#endif
Expand Down Expand Up @@ -48,7 +49,7 @@ inline
__cxa_exception*
cxa_exception_from_thrown_object(void* thrown_object)
{
DEBUG("cxa_exception_from_thrown_object %p -> %p\n",
DEBUG("cxa_exception_from_thrown_object %p -> %p",
thrown_object, static_cast<__cxa_exception*>(thrown_object) - 1);
return static_cast<__cxa_exception*>(thrown_object) - 1;
}
Expand All @@ -60,7 +61,7 @@ inline
void*
thrown_object_from_cxa_exception(__cxa_exception* exception_header)
{
DEBUG("thrown_object_from_cxa_exception %p -> %p\n",
DEBUG("thrown_object_from_cxa_exception %p -> %p",
exception_header, static_cast<void*>(exception_header + 1));
return static_cast<void*>(exception_header + 1);
}
Expand Down Expand Up @@ -118,7 +119,7 @@ __cxa_increment_exception_refcount(void *thrown_object) _NOEXCEPT {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
DEBUG("INC: %p refcnt=%zu\n", thrown_object, exception_header->referenceCount);
DEBUG("INC: %p refcnt=%zu", thrown_object, exception_header->referenceCount);
std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(1));
}
}
Expand All @@ -136,12 +137,12 @@ void __cxa_decrement_exception_refcount(void *thrown_object) _NOEXCEPT {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
DEBUG("DEC: %p refcnt=%zu rethrown=%d\n", thrown_object,
DEBUG("DEC: %p refcnt=%zu rethrown=%d", thrown_object,
exception_header->referenceCount, exception_header->rethrown);
assert(exception_header->referenceCount > 0);
if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0 && !exception_header->rethrown)
{
DEBUG("DEL: %p\n", thrown_object);
DEBUG("DEL: %p (dtor=%p)", thrown_object, exception_header->exceptionDestructor);
if (NULL != exception_header->exceptionDestructor)
exception_header->exceptionDestructor(thrown_object);
__cxa_free_exception(thrown_object);
Expand Down