Skip to content

Commit 68e3bb0

Browse files
authored
Move __cxa_allocate_exception to native code. NFC (#18292)
1 parent 6d6344d commit 68e3bb0

33 files changed

+46
-71
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,6 @@ def check_memory_setting(setting):
26202620
settings.USE_WEBGPU or \
26212621
settings.OFFSCREENCANVAS_SUPPORT or \
26222622
settings.LEGACY_GL_EMULATION or \
2623-
not settings.DISABLE_EXCEPTION_CATCHING or \
26242623
settings.ASYNCIFY or \
26252624
settings.WASMFS or \
26262625
settings.DEMANGLE_SUPPORT or \
@@ -2646,6 +2645,7 @@ def check_memory_setting(setting):
26462645
# setThrew(). We cannot handle this using deps_info as the invokes are not
26472646
# emitted because of library function usage, but by codegen itself.
26482647
'setThrew',
2648+
'__cxa_free_exception',
26492649
]
26502650

26512651
if settings.ASYNCIFY:

src/library_exceptions.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,6 @@ var LibraryExceptions = {
163163
}
164164
},
165165

166-
// Exceptions
167-
__cxa_allocate_exception__sig: 'pp',
168-
__cxa_allocate_exception: function(size) {
169-
// Thrown object is prepended by exception metadata block
170-
return _malloc(size + {{{ C_STRUCTS.__cxa_exception.__size__ }}}) + {{{ C_STRUCTS.__cxa_exception.__size__ }}};
171-
},
172-
173-
__cxa_free_exception__deps: ['$ExceptionInfo'],
174-
__cxa_free_exception__sig: 'vp',
175-
__cxa_free_exception: function(ptr) {
176-
#if ABORTING_MALLOC || ASSERTIONS
177-
try {
178-
#endif
179-
return _free(new ExceptionInfo(ptr).ptr);
180-
#if ABORTING_MALLOC || ASSERTIONS
181-
} catch(e) {
182-
#if ASSERTIONS
183-
err('exception during __cxa_free_exception: ' + e);
184-
#endif
185-
}
186-
#endif
187-
},
188-
189166
__cxa_increment_exception_refcount__deps: ['$exception_addRef', '$ExceptionInfo'],
190167
__cxa_increment_exception_refcount__sig: 'vp',
191168
__cxa_increment_exception_refcount: function(ptr) {

system/lib/libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ __gxx_personality_v0(int version,
3232
}
3333
#endif // !defined(__USING_WASM_EXCEPTIONS__)
3434

35-
#if defined(__USING_EMSCRIPTEN_EXCEPTIONS__) || \
36-
defined(__USING_WASM_EXCEPTIONS__)
37-
3835
using namespace __cxxabiv1;
3936

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

50+
#if defined(__USING_EMSCRIPTEN_EXCEPTIONS__) || \
51+
defined(__USING_WASM_EXCEPTIONS__)
52+
5353
// Get the exception object from the unwind pointer.
5454
// Relies on the structure layout, where the unwind pointer is right in
5555
// front of the user's exception object
@@ -130,3 +130,21 @@ char* __get_exception_terminate_message(void* thrown_object) {
130130
}
131131

132132
#endif // __USING_EMSCRIPTEN_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
133+
134+
#ifndef __USING_WASM_EXCEPTIONS__
135+
136+
namespace __cxxabiv1 {
137+
138+
void* __cxa_allocate_exception(size_t size) _NOEXCEPT {
139+
// Thrown object is prepended by exception metadata block
140+
__cxa_exception* ex = (__cxa_exception*)malloc(size + sizeof(__cxa_exception));
141+
return thrown_object_from_cxa_exception(ex);
142+
}
143+
144+
void __cxa_free_exception(void *thrown_object) _NOEXCEPT {
145+
free(cxa_exception_from_thrown_object(thrown_object));
146+
}
147+
148+
}
149+
150+
#endif // !__USING_WASM_EXCEPTIONS__

test/other/metadce/test_metadce_cxx_ctors1.exports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dynCall_iiiiijj
88
dynCall_jiji
99
dynCall_viijii
1010
main
11-
malloc
1211
memory
1312
stackAlloc
1413
stackRestore

test/other/metadce/test_metadce_cxx_ctors1.imports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
env.__cxa_allocate_exception
21
env.__cxa_throw
32
env.abort
43
env.emscripten_memcpy_big
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26638
1+
26496

test/other/metadce/test_metadce_cxx_ctors1.sent

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
__cxa_allocate_exception
21
__cxa_throw
32
abort
43
emscripten_memcpy_big
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
123215
1+
123176

test/other/metadce/test_metadce_cxx_ctors2.exports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dynCall_iiiiijj
77
dynCall_jiji
88
dynCall_viijii
99
main
10-
malloc
1110
memory
1211
stackAlloc
1312
stackRestore

test/other/metadce/test_metadce_cxx_ctors2.imports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
env.__cxa_allocate_exception
21
env.__cxa_throw
32
env.abort
43
env.emscripten_memcpy_big

0 commit comments

Comments
 (0)