-
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
Using rust with wasm error handling #19612
Comments
I tried to work on this here: Detailsdefine i32 @rust_try(
ptr nocapture noundef readonly %try_func,
ptr noundef %data,
ptr nocapture noundef readonly %catch_func
)
personality ptr @__gxx_wasm_personality_v0
{
invoke void %try_func(ptr noundef %data)
to label %normal unwind label %catchswitch
normal:
ret i32 0
catchswitch:
%cs = catchswitch within none [label %catchpad_all] unwind to caller
catchpad_all:
%funclet = catchpad within %cs [ptr @_ZTI10rust_panic, ptr null]
%ptr = tail call ptr @llvm.wasm.get.exception(token %funclet)
%selector = tail call i32 @llvm.wasm.get.ehselector(token %funclet)
%rust_typeid = tail call i32 @llvm.eh.typeid.for(ptr nonnull @_ZTI10rust_panic)
%is_rust_panic = icmp eq i32 %selector, %rust_typeid
%adjusted_ptr = call ptr @__cxa_begin_catch(ptr %ptr) #3 [ "funclet"(token %funclet) ]
br i1 %is_rust_panic, label %caught_rust, label %caught_foreign
caught_rust:
call void %catch_func(ptr noundef %data, ptr noundef %adjusted_ptr) #3 [ "funclet"(token %funclet) ]
call void @__cxa_end_catch() #3 [ "funclet"(token %funclet) ]
catchret from %funclet to label %caught
caught_foreign:
call void %catch_func(ptr noundef %data, ptr noundef null) #3 [ "funclet"(token %funclet) ]
call void @__cxa_end_catch() #3 [ "funclet"(token %funclet) ]
catchret from %funclet to label %caught
caught:
ret i32 1
} I don't know how to build quite this IR since the rust IR Builder gives |
cc @aheejin, does that LLVM look correct for Wasm EH? |
If I pass In other cases, the generated wasm has no |
We process If you use our Wasm backend, running I don't know Rust so I really don't have any idea on what your rust code does. I think I can help more if you give me the LLVM IR generated from it (which you did too).
I'm not sure what this means. What's the actual command line are you running? I am not very familiar with Rust Wasm toolchain. For C++, And what's the command line for that? Can you give me an input ll file and a command that crashes? |
I've been working on getting rust panics to work with wasm error handling. It is possible to compile the rust code and get valid generated code, but panics cannot be caught with
catch_unwind
. My best guess is that the problem is that the Rust compilertry
intrinsic is wrong. The generated wasm has athrow
instruction but notry
orcatch
.@aheejin
I am compiling rust code with the following environment variables:
my rust library looks like:
The
try
intrinsic is here:https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs#L683-L707
it seems to be missing at least calls to
__cxa_begin_catch
and__cxa_end_catch
, and thelandingpad
looks like it's specific to js exception handling.The text was updated successfully, but these errors were encountered: