Skip to content

Commit 4ec07a2

Browse files
authored
Revert "Make JS exception catching code conditional. NFC (#22380)" (#22426)
This reverts commit eb4d36d. The change caused a regression when building some parts of the llvm testsuite. In particular, when code is linked that was build with -fexceptions, but -fexceptions was not given at link time. In addition to the revered change I also had to move `__cxa_get_exception_ptr` to `private_typeinfo.cpp`. This was converted to native function in #22421, but, when combined with this change/revert it also needs to be available in the `-noexcept` version of libc++abi. See the comment in `private_typeinfo.cpp`
1 parent 95e2146 commit 4ec07a2

File tree

8 files changed

+49
-62
lines changed

8 files changed

+49
-62
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ jobs:
543543
test_targets: "
544544
lto2.test_dylink_syslibs_all
545545
lto2.test_float_builtins
546-
lto2.test_emscripten_lazy_load_code_unconditional
547546
lto0.test_exceptions_allowed_uncaught
548547
lto0.test_longjmp_standalone_standalone
549548
lto0.test_embind_i64_val

src/library_exceptions.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ var LibraryExceptions = {
125125

126126
llvm_eh_typeid_for: (type) => type,
127127

128-
#if !DISABLE_EXCEPTION_CATCHING
129128
__cxa_begin_catch__deps: ['$exceptionCaught', '__cxa_increment_exception_refcount',
130129
'__cxa_get_exception_ptr',
131130
'$uncaughtExceptionCount'],
@@ -257,17 +256,7 @@ var LibraryExceptions = {
257256
{{{ makeThrow('exceptionLast') }}}
258257
},
259258

260-
$incrementExceptionRefcount__deps: ['__cxa_increment_exception_refcount'],
261-
$incrementExceptionRefcount: (ptr) => ___cxa_increment_exception_refcount(ptr),
262-
263-
$decrementExceptionRefcount__deps: ['__cxa_decrement_exception_refcount'],
264-
$decrementExceptionRefcount: (ptr) => ___cxa_decrement_exception_refcount(ptr),
265-
266-
$getExceptionMessage__deps: ['$getExceptionMessageCommon'],
267-
$getExceptionMessage: (ptr) => getExceptionMessageCommon(ptr),
268-
#endif // !DISABLE_EXCEPTION_CATCHING
269-
#endif // !WASM_EXCEPTIONS
270-
259+
#endif
271260
#if WASM_EXCEPTIONS || !DISABLE_EXCEPTION_CATCHING
272261
$getExceptionMessageCommon__deps: ['__get_exception_message', 'free', '$stackSave', '$stackRestore', '$stackAlloc'],
273262
$getExceptionMessageCommon: (ptr) => {
@@ -342,23 +331,19 @@ var LibraryExceptions = {
342331
var ptr = getCppExceptionThrownObjectFromWebAssemblyException(ex);
343332
return getExceptionMessageCommon(ptr);
344333
},
345-
#endif // WASM_EXCEPTIONS
346-
};
347334

348-
function addStub(name) {
349-
LibraryManager.library[name] = function() { abort(); };
350-
LibraryManager.library[`${name}__sig`] = '';
351-
#if !INCLUDE_FULL_LIBRARY
352-
LibraryManager.library[`${name}__deps`] = [function() {
353-
error(`DISABLE_EXCEPTION_CATCHING was set, which means no C++ exception catching support code is linked in, but such support is required by symbol '${name}'. Either set DISABLE_EXCEPTION_CATCHING=0 (if you do want exception catching) or compile all source files with DISABLE_EXCEPTION_CATCHING=1.`);
354-
}];
355-
#endif
356-
}
335+
#elif !DISABLE_EXCEPTION_CATCHING
336+
$incrementExceptionRefcount__deps: ['__cxa_increment_exception_refcount'],
337+
$incrementExceptionRefcount: (ptr) => ___cxa_increment_exception_refcount(ptr),
338+
339+
$decrementExceptionRefcount__deps: ['__cxa_decrement_exception_refcount'],
340+
$decrementExceptionRefcount: (ptr) => ___cxa_decrement_exception_refcount(ptr),
341+
342+
$getExceptionMessage__deps: ['$getExceptionMessageCommon'],
343+
$getExceptionMessage: (ptr) => getExceptionMessageCommon(ptr),
357344

358-
#if DISABLE_EXCEPTION_CATCHING
359-
addStub('__cxa_begin_catch');
360-
addStub('__cxa_end_catch');
361345
#endif
346+
};
362347

363348
#if !WASM_EXCEPTIONS
364349
// In LLVM, exceptions generate a set of functions of form
@@ -367,9 +352,6 @@ addStub('__cxa_end_catch');
367352
// a single function '__cxa_find_matching_catch' that variadically processes all
368353
// of these functions using JS 'arguments' object.
369354
addCxaCatch = (n) => {
370-
#if DISABLE_EXCEPTION_CATCHING
371-
addStub(`__cxa_find_matching_catch_${n}`);
372-
#else
373355
const args = [];
374356
// Confusingly, the actual number of asrgument is n - 2. According to the llvm
375357
// code in WebAssemblyLowerEmscriptenEHSjLj.cpp:
@@ -386,7 +368,6 @@ addCxaCatch = (n) => {
386368
LibraryManager.library[`__cxa_find_matching_catch_${n}__sig`] = sig;
387369
LibraryManager.library[`__cxa_find_matching_catch_${n}__deps`] = ['$findMatchingCatch'];
388370
LibraryManager.library[`__cxa_find_matching_catch_${n}`] = eval(`(${args}) => findMatchingCatch([${argString}])`);
389-
#endif
390371
};
391372

392373
// Add the first 2-5 catch handlers preemptively. Others get added on demand in

system/lib/libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,6 @@ void __cxa_free_exception(void *thrown_object) throw() {
114114
__aligned_free_with_fallback((void *)raw_buffer);
115115
}
116116

117-
void *__cxa_get_exception_ptr(void *thrown_object) throw() {
118-
// Get pointer which is expected to be received by catch clause in C++ code.
119-
// It may be adjusted when the pointer is casted to some of the exception
120-
// object base classes (e.g. when virtual inheritance is used). When a pointer
121-
// is thrown this method should return the thrown pointer itself.
122-
// Work around a fastcomp bug, this code is still included for some reason in
123-
// a build without exceptions support.
124-
__cxa_exception* ex = cxa_exception_from_thrown_object(thrown_object);
125-
bool is_pointer = !!dynamic_cast<__pointer_type_info*>(ex->exceptionType);
126-
void* rtn;
127-
if (is_pointer)
128-
rtn = *(void**)thrown_object;
129-
else if (ex->adjustedPtr)
130-
rtn = ex->adjustedPtr;
131-
else
132-
rtn = ex;
133-
DEBUG("__cxa_get_exception_ptr %p -> %p\n", thrown_object, rtn);
134-
return rtn;
135-
}
136-
137117
/*
138118
If thrown_object is not null, atomically increment the referenceCount field
139119
of the __cxa_exception header associated with the thrown object referred to

system/lib/libcxxabi/src/private_typeinfo.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,11 +1530,17 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
15301530
not_public_path,
15311531
use_strcmp);
15321532
}
1533+
} // __cxxabiv1
15331534

1534-
// XXX EMSCRIPTEN
15351535

1536+
// XXX EMSCRIPTEN
15361537
#ifndef __WASM_EXCEPTIONS__
15371538

1539+
#include "cxa_exception.h"
1540+
1541+
namespace __cxxabiv1
1542+
{
1543+
15381544
// These functions are used by the emscripten-style exception handling
15391545
// mechanism.
15401546
// Note that they need to be included even in the `-noexcept` build of
@@ -1555,7 +1561,33 @@ int __cxa_can_catch(__shim_type_info* catchType, __shim_type_info* excpType, voi
15551561
return ret;
15561562
}
15571563

1564+
static
1565+
inline
1566+
__cxa_exception*
1567+
cxa_exception_from_thrown_object(void* thrown_object)
1568+
{
1569+
return static_cast<__cxa_exception*>(thrown_object) - 1;
1570+
}
1571+
1572+
void *__cxa_get_exception_ptr(void *thrown_object) throw() {
1573+
// Get pointer which is expected to be received by catch clause in C++ code.
1574+
// It may be adjusted when the pointer is casted to some of the exception
1575+
// object base classes (e.g. when virtual inheritance is used). When a pointer
1576+
// is thrown this method should return the thrown pointer itself.
1577+
// Work around a fastcomp bug, this code is still included for some reason in
1578+
// a build without exceptions support.
1579+
__cxa_exception* ex = cxa_exception_from_thrown_object(thrown_object);
1580+
bool is_pointer = !!dynamic_cast<__pointer_type_info*>(ex->exceptionType);
1581+
if (is_pointer)
1582+
return *(void**)thrown_object;
1583+
if (ex->adjustedPtr)
1584+
return ex->adjustedPtr;
1585+
return ex;
1586+
}
1587+
15581588
}
1559-
#endif // __EMSCRIPTEN_EXCEPTIONS__
15601589

15611590
} // __cxxabiv1
1591+
1592+
#endif // !__WASM_EXCEPTIONS__
1593+

test/other/metadce/test_metadce_cxx_lto.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__cxa_increment_exception_refcount
12
__indirect_function_table
23
__wasm_call_ctors
34
_emscripten_stack_alloc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
128959
1+
129045

test/test_other.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11590,12 +11590,12 @@ def test_fignore_exceptions(self):
1159011590
# enabling exceptions at link and compile works
1159111591
'on': (['-fexceptions'], ['-fexceptions'], True),
1159211592
# just compile isn't enough as the JS runtime lacks support
11593-
'compile_only': (['-fexceptions'], [], False, True),
11593+
'compile_only': (['-fexceptions'], [], False),
1159411594
# just link isn't enough as codegen didn't emit exceptions support
1159511595
'link_only': ([], ['-fexceptions'], False),
1159611596
'standalone': (['-fexceptions'], ['-fexceptions', '-sSTANDALONE_WASM', '-sWASM_BIGINT'], True),
1159711597
})
11598-
def test_f_exception(self, compile_flags, link_flags, expect_caught, expect_link_failure=False):
11598+
def test_f_exception(self, compile_flags, link_flags, expect_caught):
1159911599
create_file('src.cpp', r'''
1160011600
#include <stdio.h>
1160111601
int main () {
@@ -11608,11 +11608,6 @@ def test_f_exception(self, compile_flags, link_flags, expect_caught, expect_link
1160811608
}
1160911609
''')
1161011610
self.run_process([EMXX, 'src.cpp', '-c', '-o', 'src.o'] + compile_flags)
11611-
if expect_link_failure:
11612-
err = self.expect_fail([EMXX, 'src.o'] + link_flags)
11613-
self.assertContained("error: DISABLE_EXCEPTION_CATCHING was set, which means no C++ exception catching support code is linked in, but such support is required by symbol '__cxa_begin_catch'", err)
11614-
return
11615-
1161611611
self.run_process([EMXX, 'src.o'] + link_flags)
1161711612
result = self.run_js('a.out.js', assert_returncode=0 if expect_caught else NON_ZERO)
1161811613
if not expect_caught:

tools/maint/gen_sig_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ def extract_sig_info(sig_info, extra_settings=None, extra_cflags=None, cxx=False
295295
# Enable as many settings as we can here to ensure the maximum number
296296
# of JS symbols are included.
297297
'STACK_OVERFLOW_CHECK': 1,
298-
'DISABLE_EXCEPTION_CATCHING': 0,
299298
'USE_SDL': 1,
300299
'USE_GLFW': 0,
301300
'FETCH': 1,

0 commit comments

Comments
 (0)