Skip to content

Commit a1b3fea

Browse files
committed
Avoid calling addCxaCatch when not linking as C++
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.
1 parent 3319a31 commit a1b3fea

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/jsifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function(${args}) {
319319
// the number specifies the number of arguments. In Emscripten, route all
320320
// these to a single function 'findMatchingCatch' that takes an array
321321
// of argument.
322-
if (!WASM_EXCEPTIONS && symbol.startsWith('__cxa_find_matching_catch_')) {
322+
if (LINK_AS_CXX && !WASM_EXCEPTIONS && symbol.startsWith('__cxa_find_matching_catch_')) {
323323
if (DISABLE_EXCEPTION_THROWING) {
324324
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.');
325325
return;

test/other/test_exceptions_c_linker.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
__attribute__((import_name("__cxa_find_matching_catch_1")))
4+
void __cxa_find_matching_catch_1();
5+
6+
int main() {
7+
__cxa_find_matching_catch_1();
8+
printf("done");
9+
return 0;
10+
}
11+

test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8796,6 +8796,12 @@ def test_wasm_nope(self):
87968796
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
87978797
self.assertContained('no native wasm support detected', out)
87988798

8799+
def test_exceptions_c_linker(self):
8800+
# Test that we don't try to create __cxa_find_matching_catch_xx function automatically
8801+
# when not linking as C++.
8802+
stderr = self.expect_fail([EMCC, '-sSTRICT', test_file('other/test_exceptions_c_linker.c')])
8803+
self.assertContained('error: undefined symbol: __cxa_find_matching_catch_1', stderr)
8804+
87998805
@parameterized({
88008806
'': (False,),
88018807
'wasm': (True,),

0 commit comments

Comments
 (0)