Repository navigation
Description
Emscripten version: 3.1.53
Rust version: 1.76.0
I'm trying to link a Rust staticlib (target=wasm32-unknown-emscripten) into an Emscripten app. I have set panic = "abort" on the Rust staticlib. But this still results in one error:
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "ReferenceError: addCxaCatch is not defined
at symbolHandler (/emsdk/upstream/emscripten/src/jsifier.js:313:9)
at runJSify (/emsdk/upstream/emscripten/src/jsifier.js:670:5)
at file:///emsdk/upstream/emscripten/src/compiler.mjs:108:3
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
emcc: error: '/emsdk/node/16.20.0_64bit/bin/node /emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpbgmjza1m.json' failed (returned 1)
If instead I don't set panic = "abort" then I get these undefined symbols (which makes sense):
wasm-ld: error: /src/remglk/target/wasm32-unknown-emscripten/dev-wasm/libremglk_capi.a(panic_unwind-3ad5b75c252c058f.panic_unwind.96ff97a480fa31b3-cgu.0.rcgu.o): undefined symbol: __cxa_allocate_exception
wasm-ld: error: /src/remglk/target/wasm32-unknown-emscripten/dev-wasm/libremglk_capi.a(panic_unwind-3ad5b75c252c058f.panic_unwind.96ff97a480fa31b3-cgu.0.rcgu.o): undefined symbol: __cxa_throw
wasm-ld: error: /src/remglk/target/wasm32-unknown-emscripten/dev-wasm/libremglk_capi.a(panic_unwind-3ad5b75c252c058f.panic_unwind.96ff97a480fa31b3-cgu.0.rcgu.o): undefined symbol: vtable for __cxxabiv1::__class_type_info
If I then set -fexceptions and -sNO_DISABLE_EXCEPTION_CATCHING, I get these missing symbols, in addition to the previous ones:
wasm-ld: error: symbol exported via --export not found: __cxa_is_pointer_type
wasm-ld: error: symbol exported via --export not found: __cxa_can_catch
wasm-ld: error: symbol exported via --export not found: __cxa_increment_exception_refcount
wasm-ld: error: symbol exported via --export not found: __cxa_decrement_exception_refcount
wasm-ld: error: symbol exported via --export not found: __cxa_free_exception
-fwasm-exceptions doesn't make much different either (except that it warns me it's incompatible with ASYNCIFY.)
I think I'd really prefer just to abort on panic. I can live without stack traces. But what can I do to stop the addCxaCatch is not defined error? Should I manually link library_exceptions.js even though I don't want to use it?
Edit: manually linking library_exceptions.js results in these errors, so doesn't seem a viable option either:
wasm-ld: error: /tmp/tmpnuul4vfelibemscripten_js_symbols.so: undefined symbol: __cxa_can_catch. Required by __cxa_find_matching_catch_4
wasm-ld: error: /tmp/tmpnuul4vfelibemscripten_js_symbols.so: undefined symbol: __cxa_is_pointer_type. Required by __cxa_find_matching_catch_4
wasm-ld: error: /tmp/tmpnuul4vfelibemscripten_js_symbols.so: undefined symbol: __cxa_can_catch. Required by __cxa_find_matching_catch_2
wasm-ld: error: /tmp/tmpnuul4vfelibemscripten_js_symbols.so: undefined symbol: __cxa_is_pointer_type. Required by __cxa_find_matching_catch_2
Activity
sbc100 commentedon Feb 21, 2024
What is the full link command you are using when you get the
symbol exported via --export not found: __cxa_is_pointer_typeerrors?__cxa_is_pointer_typeis defined insystem/lib/libcxxabi/src/private_typeinfo.cppwhich is part of libcxxabi. Which version of libcxxabi is being included at link time?sbc100 commentedon Feb 21, 2024
Regarding the initial
addCxaCatchissue, I can't see how that would show up unless perhaps you are linking withemccand using-sSTRICTmode which mean we don't link as C++ and we don't include library_exceptions.js at all (which is whereaddCxaCatchis defined).If that is the issue then the immediate solution to the undefined symbol would be to link with
em++.curiousdannii commentedon Feb 21, 2024
I am using STRICT, so you're probably right there.
I'm using CMake, and the app is only C, so it's probably not linking any C++ libraries. I'll try setting the compiler to em++ and report back. And also get the full link command.
sbc100 commentedon Feb 21, 2024
Thanks for confirming. I will try to come up with an emscripten fix here so that error message is at least less cryptic!
sbc100 commentedon Feb 21, 2024
I'm struggling to reproduce this issue because it seems like your program (one of the object files) refers to the a
__cxa_find_matching_catch_xxfunction but not to any of the other exception catching functions such as__cxa_end_catch.I can't seem to make an object file that does that. Can you find out which object is referring to the
__cxa_find_matching_catch_xx? How did you build that object and can you maybe attach it here?Avoid calling addCxaCatch when not linking as C++
Avoid calling addCxaCatch when not linking as C++
Avoid calling addCxaCatch when not linking as C++
curiousdannii commentedon Feb 21, 2024
Here's my staticlib. It's very big, because Rust.
libremglk_capi.zip
If it would help, you could try building my project. I think running src/build.sh should be enough.
https://github.com/curiousdannii/emglken/tree/remglk-rs
Here's the link command when trying to build with
-fexceptionsand-sNO_DISABLE_EXCEPTION_CATCHING:sbc100 commentedon Feb 21, 2024
Once #21386 lands you should start seeing a normal undefined symbol error for
__cxa_find_matching_catch_xxxinstead of theReferenceError: addCxaCatcherror.When you can add
-Wl,--trace-symbol=__cxa_find_matching_catch_xxxto find out which of your object files contains that reference. My guess is that that object is somehow being built wrong. It should not be referencing that symbol if exception catching is disabled.curiousdannii commentedon Feb 21, 2024
Using
set_target_properties(glulxe-core PROPERTIES LINKER_LANGUAGE CXX)does let it compile without errors! Too early to say if it is actually working yet though, I have a lot more to do.Avoid calling addCxaCatch when not linking as C++ (#21386)
Merge upstream 3.1.56 (#64)