-
Notifications
You must be signed in to change notification settings - Fork 3.4k
ReferenceError: _setThrew is not defined when linking as C++ #22227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The fact that this The Lines 1000 to 1006 in 7b466b4
emscripten/src/library_exceptions.js Line 168 in 7b466b4
I'm guessing your program does import either of those, but is still somehow depending on Can you try adding adding Line 1277 in 7b466b4
|
Can you find the object file that is referencing |
It's happening during/after a Rust panic. I'm not sure if that means it's using a longjmp or exception. Ah, in debug mode I do get an assertion saying "Exception thrown, but exception catching is not enabled. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch." It comes from a fairly simple Rust function
Which is just turning a I added that line to link.py. Because I'm using Docker it seemed the easiest way was just to patch the file and then copy it over the top. However the file in the git tag of 3.1.63 includes the recent StackIR changes, which the emsdk 3.1.63 version doesn't know about ("Unknown option '--no-stack-ir'"). I had to grap the link.py from 150af6e instead. Seems like a tagging mismatch? Can confirm that adding that line fixes I'll continue digging... |
IIUC the |
I think this is Rust's panic implementation? https://github.com/rust-lang/rust/blob/1.77.0/library/panic_unwind/src/emcc.rs It does call However I'm not sure if I'm actually using the unwind panic or the abort panic... |
So Can you try linking with |
Just noticed Debug build:
Release build:
|
So in the release build Can you trace the |
Release build:
Maybe it thinks the call to |
Do you know which source file resulted in |
Rust makes object files per crate, not per source files, so that's not an easy question. But I did put breakpoints on the invoke_ functions, and they get called from I'm not compiling it with any manual |
I tried again with a debug build, and the invoke_ functions are being called by things like these:
These functions are often very simple. Here's the Iterator::fold one for example: https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2591 And here's the map::map_fold: Are the invoke_ functions just being called for indirect function calls? |
So the only place the invoke_ wrappers are ever generated is during the Somehow with C++ EH and with setjmp/longjmp these always get generated alongside calls to either I'm guess that the rust compiler is generating some kind of EH usage or setjmp/longjmp usage that is different to the C++ compiler. @aheejin any ideas here? |
My guess is that rust is generating invokes but without the corresponding catches that call While we should fix this... I also wonder if we can find a way to eliminate those invokes... since calling out the JS for the As a temporary workaround I assume you can build with |
Yes, setting (I wish there was a After the |
You can just do We are trying to find a way to make additive settings work: #19938 |
I am not familiar with how Rust exceptions are compiled; more precisely, how Rust is using our JS libraries written for C++. Can you provide an .ll file and a command to |
remglk deps.zip I'm not sure what you meant by "a command to |
Sorry for the late reply. Yeah your bitcode files contain a bunch of Edit: I pasted incorrect set of flags for the condition, so I fixed them |
@aheejin I'm not manually setting any flags, so yeah just the default flags. I'm not sure what they are, but just found these: |
This happens because Rust programs that use LLVM Itanium EH IR may not use A similar thing happened for Emscritpen SjLj so we added Lines 1010 to 1017 in 8c81cac
But it's tricky to do a similar thing here because we don't have a JS function that is always included in case of EH. ( getTempRet0 seems to be always included but it is an assembly function) __resumeException can be one target but it is only included when LLVM IR's resume instruction is used, which is not always the case for all EH programs.
@sbc100 Do you think we can add Also, I think I used to see many additions to |
That seems reasonable as long as
I think you will find these now in |
Thanks! Where am I supposed to add |
I haven't manually set |
In emcc + C++, if you set I'm not familiar with Rust toolchain's workflow. How does it work with |
I'm compiling my Rust code into a static library for the wasm32-unknown-emscripten target. Emcc is not involved yet. Then I link it into my app using emcmake (which calls emcc). So it seems like this is the cause? https://github.com/rust-lang/rust/blob/aa877bc71c8c8082122bee23d17c8669f30f275d/compiler/rustc_codegen_llvm/src/llvm_util.rs#L111 I'm guessing that I have to link with @tlively You originally added that flag in rust-lang/rust@62c3443 Do you remember anything about it? Any suggestions on what the best way to get Rust and Emcc to play nicely together here is? |
If you don't use |
Yes I set that in cmake/emcc. It's just the Rust staticlib that's compiled without emcc. (Directly, I mean. Rust might be calling |
Uh oh!
There was an error while loading. Please reload this page.
Version of emscripten/emsdk:
emscripten/emsdk:3.1.56 (a little behind I know, but I couldn't see any recent changes that looked relevant. I will try updating soon.)
I think this is a follow up to #21381. I have no compilation errors, but despite the
invoke_
functions depending on_setThrew
, it isn't defined.I suspect this may be happening because I've set
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX)
in CMake, but there are no actual C++ files being linked in? (We previously determined that my project needs to be linked as CXX because it's using Rust.)The text was updated successfully, but these errors were encountered: