I have a question about unwinding:
I'm JIT-compiling code (directly with frontend
and codegen
, without using jit
and module
) and the generated code calls a Rust-defined function in the current process. This function throws a panic, and the panic is supposed to be caught by the Rust code calling the JIT-compiled code. Roughly like this:
extern "C-unwind" fn called_from_jit_code() {
panic!("in Rust code");
}
...
let addr_value = builder.ins().iconst(I64, called_from_jit_code as i64);
builder.ins().call_indirect(sig_ref, addr_value, &[]);
...
std::panic::catch_unwind(|| {
jit_compiled_function();
});
Is this possible with the unwind info created by Cranelift?
Nothing needs to be cleaned up within the JIT-compiled code, I just want to pass the panic through to the surrounding Rust code.
We do emit unwind info (you will need to make sure you're registering it properly when you load/publish the JIT code). So in that sense anything that works with a Rust->C++->Rust stack (for example) should work with CL-compiled code in the middle as well, I think
(modulo unwind-info bugs; if you find issues please do let us know)
What isn't supported yet however is catching exceptions or handling cleanup (running destructors, etc) for exceptions in Cranelift compilrd functions.
Last updated: Feb 27 2025 at 23:03 UTC