-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[Old EH] JS stack unwinding support corrupts some floats #22743
Comments
Hmm, the integer here is turned into a NaN by The NaN gets canonicalized at the JS boundary, I believe (calling We could in theory fix this by making |
Well anyone who uses rust is stuck with the old error handling until someone updates the rust try intrinsic to emit ir compatible with the new error handling: |
@hoodmane is that an issue on the Rust side, or LLVM? (the link is to an Emscripten issue, but I'm not sure I understood from it where the underlying problem is) In general, getting Rust to emit IR compatible with new wasm EH sounds very important for any Rust/C++ combination, Emscripten or otherwise. Is there a Rust issue for that? With all that said, I wouldn't be opposed to fixing float invokes for old EH, using the approach I mentioned above, if someone has time for it. |
Yeah I would love to switch Pyodide to use the new wasm EH and this is the only blocker. The issue is in the rust compiler. Specifically, the |
The tracking issue for WebAssembly EH in Rust is at rust-lang/rust#118168. Looking at PR rust-lang/rust#111322, I'm unsure why it was conditionally excluded for Emscripten: Could you try to remove the |
Thanks @kleisauke ! @walkingeyerobot fyi, the last comment has some details that might be relevant for future Rust/Emscripten work. |
Well using that is good progress. I can get it to link with the new codegen and the try intrinsic looks perfect, but there are problems elsewhere in |
Looks like catchpad:
%tok = catchpad within %cs [null]
%ptr = call @llvm.wasm.get.exception(token %tok)
%sel = call @llvm.wasm.get.ehselector(token %tok)
call %catch_func(%data, %ptr)
catchret from %tok to label %caught Was catch $tag0
local.set $var4
local.get $var3
global.set $__stack_pointer
local.get $var1
local.get $var4
local.get $var2
call_indirect (param i32 i32)
i32.const 1
local.set $var5
local.get $var5
end and the |
Indeed
https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/WasmEHPrepare.cpp?plain=1#L13-L33 I wonder if I can get llvm to print the result of this pass... |
After the WasmEHPrepare pass the ir looks like: catchpad: ; preds = %catchswitch
%catchpad2 = catchpad within %catchswitch1 [ptr null]
%exn = call ptr @llvm.wasm.catch(i32 0)
call void %2(ptr %1, ptr %exn) [ "funclet"(token %catchpad2) ]
catchret from %catchpad2 to label %caught It seems we took that // In case it is a catchpad with single catch (...) or a cleanuppad, we don't
// need to call personality function because we don't need a selector.
if (!NeedPersonality) {
if (GetSelectorCI) {
assert(GetSelectorCI->use_empty() &&
"wasm.get.ehselector() still has uses!");
GetSelectorCI->eraseFromParent();
}
return;
} So as the comment says, this would normally happen in C++ when there is a blanket |
Adding the call to |
Right, the ldsa would be initialized in the ir injected by __wasm_lpad_context.lpad_index = index;
__wasm_lpad_context.lsda = wasm.lsda(); |
Have you already tried using The former implementation is also used by |
Nope, trying that now thanks. |
FWIW, you may also need to adjust the following: --- a/library/unwind/src/lib.rs
+++ b/library/unwind/src/lib.rs
@@ -4,10 +4,7 @@
#![feature(staged_api)]
#![feature(strict_provenance)]
#![cfg_attr(not(target_env = "msvc"), feature(libc))]
-#![cfg_attr(
- all(target_family = "wasm", not(target_os = "emscripten")),
- feature(simd_wasm64, wasm_exception_handling_intrinsics)
-)]
+#![cfg_attr(target_family = "wasm", feature(simd_wasm64, wasm_exception_handling_intrinsics))]
#![allow(internal_features)]
// Force libc to be included even if unused. This is required by many platforms. |
Yup that works. Only missing thing is debug info. Emscripten has this code to attach more information to the error in debug releases: |
Well it seems like |
main.c++
helper.c++
Running it
Compile and run with
it prints:
On the other hand, if we compile and run with
-fwasm-exceptions
:It prints the expected output:
Emscripten version
The text was updated successfully, but these errors were encountered: