Skip to content

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

Closed

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

Activity

  1. sbc100 commented on Feb 21, 2024

    @sbc100
    Collaborator

    What is the full link command you are using when you get the symbol exported via --export not found: __cxa_is_pointer_type errors?

    __cxa_is_pointer_type is defined in system/lib/libcxxabi/src/private_typeinfo.cpp which is part of libcxxabi. Which version of libcxxabi is being included at link time?

  2. sbc100 commented on Feb 21, 2024

    @sbc100
    Collaborator

    Regarding the initial addCxaCatch issue, I can't see how that would show up unless perhaps you are linking with emcc and using -sSTRICT mode which mean we don't link as C++ and we don't include library_exceptions.js at all (which is where addCxaCatch is defined).

    If that is the issue then the immediate solution to the undefined symbol would be to link with em++.

  3. curiousdannii commented on Feb 21, 2024

    @curiousdannii
    ContributorAuthor

    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.

  4. sbc100 commented on Feb 21, 2024

    @sbc100
    Collaborator

    Thanks for confirming. I will try to come up with an emscripten fix here so that error message is at least less cryptic!

  5. sbc100 commented on Feb 21, 2024

    @sbc100
    Collaborator

    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_xx function 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?

  6. added 3 commits that reference this issue on Feb 21, 2024
    ec62a30
    a1b3fea
    cd0d15d
  7. curiousdannii commented on Feb 21, 2024

    @curiousdannii
    ContributorAuthor

    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 -fexceptions and -sNO_DISABLE_EXCEPTION_CATCHING:

    emcc: error: '/emsdk/upstream/bin/wasm-ld -o glulxe-core.wasm --wrap=getc --wrap=ungetc 
    CMakeFiles/glulxe-core.dir/glulxe/accel.c.o CMakeFiles/glulxe-core.dir/glulxe/debugger.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/exec.c.o CMakeFiles/glulxe-core.dir/glulxe/files.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/float.c.o CMakeFiles/glulxe-core.dir/glulxe/funcs.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/gestalt.c.o CMakeFiles/glulxe-core.dir/glulxe/glkop.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/heap.c.o CMakeFiles/glulxe-core.dir/glulxe/main.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/operand.c.o CMakeFiles/glulxe-core.dir/glulxe/osdepend.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/profile.c.o CMakeFiles/glulxe-core.dir/glulxe/search.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/serial.c.o CMakeFiles/glulxe-core.dir/glulxe/string.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/vm.c.o CMakeFiles/glulxe-core.dir/glulxe/unixstrt.c.o 
    CMakeFiles/glulxe-core.dir/glulxe/unixautosave.c.o 
    -L/src/remglk/target/wasm32-unknown-emscripten/dev-wasm
    /src/remglk/target/wasm32-unknown-emscripten/dev-wasm/libremglk_capi.a 
    -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lstubs-debug -lc-debug 
    -ldlmalloc -lcompiler_rt -lsockets --fatal-warnings -mllvm -combiner-global-alias-analysis=false 
    -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr 
    /tmp/tmpirb976oelibemscripten_js_symbols.so --export=emscripten_stack_get_end 
    --export=emscripten_stack_get_free --export=emscripten_stack_get_base 
    --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackAlloc 
    --export=stackSave --export=stackRestore --export=__get_temp_ret --export=__set_temp_ret 
    --export=__funcs_on_exit --export=__cxa_is_pointer_type --export=__cxa_can_catch 
    --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount 
    --export=setThrew --export=__cxa_free_exception --export=__wasm_call_ctors --export=malloc 
    --export=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm 
    --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js 
    --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv 
    --export-if-defined=fflush --export-table -z stack-size=65536 --initial-memory=16777216 
    --max-memory=2147483648 --no-entry --stack-first --table-base=1' failed (returned 1)
    
  8. sbc100 commented on Feb 21, 2024

    @sbc100
    Collaborator

    Once #21386 lands you should start seeing a normal undefined symbol error for __cxa_find_matching_catch_xxx instead of the ReferenceError: addCxaCatch error.

    When you can add -Wl,--trace-symbol=__cxa_find_matching_catch_xxx to 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.

  9. curiousdannii commented on Feb 21, 2024

    @curiousdannii
    ContributorAuthor

    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.

  10. added a commit that references this issue on Feb 22, 2024
    52d401b
  11. added a commit that references this issue on Apr 12, 2024
    baa07c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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