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
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,6 @@ def check_memory_setting(setting):
settings.USE_PTHREADS or \
settings.OFFSCREENCANVAS_SUPPORT or \
settings.LEGACY_GL_EMULATION or \
not settings.DISABLE_EXCEPTION_CATCHING or \
settings.ASYNCIFY or \
settings.WASMFS or \
settings.DEMANGLE_SUPPORT or \
Expand All @@ -2647,6 +2646,7 @@ def check_memory_setting(setting):
# setThrew(). We cannot handle this using deps_info as the invokes are not
# emitted because of library function usage, but by codegen itself.
'setThrew',
'__cxa_free_exception',
]

if settings.ASYNCIFY:
Expand Down
23 changes: 0 additions & 23 deletions src/library_exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,6 @@ var LibraryExceptions = {
}
},

// Exceptions
__cxa_allocate_exception__sig: 'pp',
__cxa_allocate_exception: function(size) {
// Thrown object is prepended by exception metadata block
return _malloc(size + {{{ C_STRUCTS.__cxa_exception.__size__ }}}) + {{{ C_STRUCTS.__cxa_exception.__size__ }}};
},

__cxa_free_exception__deps: ['$ExceptionInfo'],
__cxa_free_exception__sig: 'vp',
__cxa_free_exception: function(ptr) {
#if ABORTING_MALLOC || ASSERTIONS
try {
#endif
return _free(new ExceptionInfo(ptr).ptr);
#if ABORTING_MALLOC || ASSERTIONS
} catch(e) {
#if ASSERTIONS
err('exception during __cxa_free_exception: ' + e);
#endif
}
#endif
},

__cxa_increment_exception_refcount__deps: ['$exception_addRef', '$ExceptionInfo'],
__cxa_increment_exception_refcount__sig: 'vp',
__cxa_increment_exception_refcount: function(ptr) {
Expand Down
24 changes: 21 additions & 3 deletions system/lib/libcxxabi/src/cxa_exception_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ __gxx_personality_v0(int version,
}
#endif // !defined(__USING_WASM_EXCEPTIONS__)

#if defined(__USING_EMSCRIPTEN_EXCEPTIONS__) || \
defined(__USING_WASM_EXCEPTIONS__)

using namespace __cxxabiv1;

// Some utility routines are copied from cxa_exception.cpp
Expand All @@ -50,6 +47,9 @@ thrown_object_from_cxa_exception(__cxa_exception* exception_header) {
return static_cast<void*>(exception_header + 1);
}

#if defined(__USING_EMSCRIPTEN_EXCEPTIONS__) || \
defined(__USING_WASM_EXCEPTIONS__)

Comment thread
sbc100 marked this conversation as resolved.
// Get the exception object from the unwind pointer.
// Relies on the structure layout, where the unwind pointer is right in
// front of the user's exception object
Expand Down Expand Up @@ -130,3 +130,21 @@ char* __get_exception_terminate_message(void* thrown_object) {
}

#endif // __USING_EMSCRIPTEN_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__

#ifndef __USING_WASM_EXCEPTIONS__

namespace __cxxabiv1 {

void* __cxa_allocate_exception(size_t size) _NOEXCEPT {
// Thrown object is prepended by exception metadata block
__cxa_exception* ex = (__cxa_exception*)malloc(size + sizeof(__cxa_exception));
Comment thread
sbc100 marked this conversation as resolved.
return thrown_object_from_cxa_exception(ex);
}

void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
free(cxa_exception_from_thrown_object(thrown_object));
}
Comment thread
sbc100 marked this conversation as resolved.

}

#endif // !__USING_WASM_EXCEPTIONS__
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.exports
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dynCall_iiiiijj
dynCall_jiji
dynCall_viijii
main
malloc
memory
stackAlloc
stackRestore
Expand Down
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.imports
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
env.__cxa_allocate_exception
env.__cxa_throw
env.abort
env.emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26638
26496
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.sent
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__cxa_allocate_exception
__cxa_throw
abort
emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors1.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123215
123176
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.exports
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ dynCall_iiiiijj
dynCall_jiji
dynCall_viijii
main
malloc
memory
stackAlloc
stackRestore
Expand Down
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.imports
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
env.__cxa_allocate_exception
env.__cxa_throw
env.abort
env.emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26602
26460
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.sent
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__cxa_allocate_exception
__cxa_throw
abort
emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_ctors2.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123129
123082
3 changes: 1 addition & 2 deletions test/other/metadce/test_metadce_cxx_except.exports
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__cxa_can_catch
__cxa_free_exception
__cxa_is_pointer_type
__errno_location
__indirect_function_table
Expand All @@ -9,10 +10,8 @@ dynCall_iiiiijj
dynCall_jiiii
dynCall_jiji
dynCall_viijii
free
getTempRet0
main
malloc
memory
setTempRet0
setThrew
Expand Down
2 changes: 0 additions & 2 deletions test/other/metadce/test_metadce_cxx_except.imports
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
env.__cxa_allocate_exception
env.__cxa_begin_catch
env.__cxa_end_catch
env.__cxa_find_matching_catch_2
env.__cxa_find_matching_catch_3
env.__cxa_free_exception
env.__cxa_rethrow
env.__cxa_throw
env.__cxa_uncaught_exceptions
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31469
31300
2 changes: 0 additions & 2 deletions test/other/metadce/test_metadce_cxx_except.sent
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
__cxa_allocate_exception
__cxa_begin_catch
__cxa_end_catch
__cxa_find_matching_catch_2
__cxa_find_matching_catch_3
__cxa_free_exception
__cxa_rethrow
__cxa_throw
__cxa_uncaught_exceptions
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
164691
164662
3 changes: 0 additions & 3 deletions test/other/metadce/test_metadce_cxx_except_wasm.exports
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ dynCall_iiiiij
dynCall_iiiiijj
dynCall_jiji
dynCall_viijii
free
main
malloc
memory
setThrew
stackAlloc
stackRestore
stackSave
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26200
25974
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136628
136567
1 change: 1 addition & 0 deletions test/other/metadce/test_metadce_cxx_mangle.exports
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__cxa_can_catch
__cxa_demangle
__cxa_free_exception
__cxa_is_pointer_type
__errno_location
__indirect_function_table
Expand Down
2 changes: 0 additions & 2 deletions test/other/metadce/test_metadce_cxx_mangle.imports
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
env.__cxa_allocate_exception
env.__cxa_begin_catch
env.__cxa_end_catch
env.__cxa_find_matching_catch_2
env.__cxa_find_matching_catch_3
env.__cxa_free_exception
env.__cxa_rethrow
env.__cxa_throw
env.__cxa_uncaught_exceptions
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31568
31544
2 changes: 0 additions & 2 deletions test/other/metadce/test_metadce_cxx_mangle.sent
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
__cxa_allocate_exception
__cxa_begin_catch
__cxa_end_catch
__cxa_find_matching_catch_2
__cxa_find_matching_catch_3
__cxa_free_exception
__cxa_rethrow
__cxa_throw
__cxa_uncaught_exceptions
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_mangle.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
219853
219840
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.exports
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dynCall_iiiiijj
dynCall_jiji
dynCall_viijii
main
malloc
memory
stackAlloc
stackRestore
Expand Down
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.imports
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
env.__cxa_allocate_exception
env.__cxa_throw
env.abort
env.emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26638
26496
1 change: 0 additions & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.sent
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__cxa_allocate_exception
__cxa_throw
abort
emscripten_memcpy_big
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_noexcept.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125959
125909
15 changes: 9 additions & 6 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,10 @@ def test_exceptions_allowed(self):
if '-fsanitize=leak' not in self.emcc_args:
self.assertGreater(size - empty_size, 0.01 * size)
# full disable can remove a little bit more
self.assertLess(disabled_size, fake_size)
# For some reason this no longer holds true at high optimizations
# levels: https://github.com/emscripten-core/emscripten/issues/18312
if not any(o in self.emcc_args for o in ('-O3', '-Oz', '-Os')):
self.assertLess(disabled_size, fake_size)

@no_wasm64('MEMORY64 does not yet support exceptions')
def test_exceptions_allowed_2(self):
Expand Down Expand Up @@ -1649,7 +1652,7 @@ def test_EXPORT_EXCEPTION_HANDLING_HELPERS(self):
self.emcc_args.append('-D__USING_EMSCRIPTEN_EXCEPTION__')

self.maybe_closure()
src = '''
create_file('main.cpp', '''
#include <emscripten.h>
#include <exception>
#include <stdexcept>
Expand Down Expand Up @@ -1702,7 +1705,7 @@ class myexception : public exception {
}
});
}
'''
''')
expected = '''\
int,
char,
Expand All @@ -1711,7 +1714,7 @@ class myexception : public exception {
char const*,
'''

self.do_run(src, expected)
self.do_runf('main.cpp', expected)

@with_both_eh_sjlj
def test_bad_typeid(self):
Expand Down Expand Up @@ -4700,8 +4703,8 @@ def test_dylink_postsets_chunking(self):
@parameterized({
'libcxx': ('libc,libc++,libmalloc,libc++abi',),
'all': ('1',),
'missing': ('libc,libmalloc', False, False, False),
'missing_assertions': ('libc,libmalloc', False, False, True),
'missing': ('libc,libmalloc,libc++abi', False, False, False),
'missing_assertions': ('libc,libmalloc,libc++abi', False, False, True),
})
def test_dylink_syslibs(self, syslibs, expect_pass=True, need_reverse=True, assertions=True):
# one module uses libcxx, need to force its inclusion when it isn't the main
Expand Down
5 changes: 1 addition & 4 deletions tools/deps_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
'SDL_PushEvent': ['malloc', 'free'],
'SDL_free': ['free'],
'SDL_malloc': ['malloc', 'free'],
'__cxa_allocate_exception': ['malloc'],
'__cxa_end_catch': ['setThrew', 'free'],
'__cxa_free_exception': ['free'],
'_embind_register_class': ['free'],
'_embind_register_enum_value': ['free'],
'_embind_register_function': ['free'],
Expand Down Expand Up @@ -194,7 +191,7 @@

def get_deps_info():
if not settings.WASM_EXCEPTIONS and settings.LINK_AS_CXX:
_deps_info['__cxa_begin_catch'] = ['__cxa_is_pointer_type']
_deps_info['__cxa_begin_catch'] = ['__cxa_is_pointer_type', '__cxa_free_exception']
_deps_info['__cxa_throw'] = ['__cxa_is_pointer_type']
_deps_info['__cxa_find_matching_catch'] = ['__cxa_can_catch', 'setTempRet0']
_deps_info['__cxa_find_matching_catch_1'] = ['__cxa_can_catch', 'setTempRet0']
Expand Down