Skip to content

Linking a Rust staticlib with panic="abort" still results in exceptions problems #21381

Closed
@curiousdannii

Description

@curiousdannii

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions