Skip to content

Commit

Permalink
Avoid calling addCxaCatch when not linking as C++
Browse files Browse the repository at this point in the history
For the test I was unable to figure out a way to generate a call to
`__cxa_find_matching_catch` withing hand coding it like this.

This doesn't fix #21381 but it makes the error message way less
confusing.
  • Loading branch information
sbc100 committed Feb 21, 2024
1 parent 3319a31 commit ec62a30
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function(${args}) {
// the number specifies the number of arguments. In Emscripten, route all
// these to a single function 'findMatchingCatch' that takes an array
// of argument.
if (!WASM_EXCEPTIONS && symbol.startsWith('__cxa_find_matching_catch_')) {
if (LINK_AS_CXX && !WASM_EXCEPTIONS && symbol.startsWith('__cxa_find_matching_catch_')) {
if (DISABLE_EXCEPTION_THROWING) {
error('DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but exception catching code appears. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-except (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.');
return;
Expand All @@ -329,8 +329,6 @@ function(${args}) {
const num = +symbol.split('_').slice(-1)[0];
addCxaCatch(num);
}
// Continue, with the code below emitting the proper JavaScript based on
// what we just added to the library.
}

function addFromLibrary(symbol, dependent, force = false) {
Expand Down
11 changes: 11 additions & 0 deletions test/other/test_exceptions_c_linker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

__attribute__((import_name("__cxa_find_matching_catch_1")))
void __cxa_find_matching_catch_1();

int main() {
__cxa_find_matching_catch_1();
printf("done");
return 0;
}

6 changes: 6 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8796,6 +8796,12 @@ def test_wasm_nope(self):
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
self.assertContained('no native wasm support detected', out)

def test_exceptions_c_linker(self):
# Test that we don't try to create __cxa_find_matching_catch_xx function automatically
# when not linking as C++.
stderr = self.expect_fail([EMCC, '-sSTRICT', test_file('other/test_exceptions_c_linker.c')])
self.assertContained('error: undefined symbol: __cxa_find_matching_catch_1', stderr)

@parameterized({
'': (False,),
'wasm': (True,),
Expand Down

0 comments on commit ec62a30

Please sign in to comment.