Hi there - I'm currently a little stuck working out how to generate / work with unwind information and the cranelift JIT. From this blog post by Nick Fitzgerald it seems like doing so is possible, when I call this function from Cranelift code though I don't see Cranelift frames in the backtrace. Is there documentation somewhere about how this is supposed to work or an example of getting unwind information working?
You need to create and register an unwind table with the stack unwinder.
https://github.com/bjorn3/rustc_codegen_cranelift/blob/40dd3e2b7089b5e96714e064b731f6dbf17c61a9/src/debuginfo/unwind.rs is a bare bone example. It also handles aot compilation, but never unregisters the unwind table.
https://github.com/bytecodealliance/wasmtime/blob/40d546c420c1e6c4909fc80e048dd1854fda1cd6/crates/jit/src/unwind/systemv.rs is the wasmtime implementation which does support unregistering.
@Zeke Medley
Thanks a bunch for the info @bjorn3 . After moving your example code over from rustc_codegen_cranelift
into my JIT and calling add_function
/register_jit
after function definition and jit.finalize_definitions
respectively I'm still not seeing Cranelift stack frames in my backtrace. Is there anything specific about how I call Backtrace::new
or configure the JIT that I should to be doing here?
More generally here my goal is to be able to walk the call stack at runtime to find live roots for garbage collection. If there is a better way to do that I'd also be open to a different approach.
After __register_frame stack unwinding will work.
You will separately need to store the stackmap to use during root tracing.
Interesting - I must be doing something wrong then :) do you know if there is somewhere I can find documentation on how __register_frame
works? Googling around didn't yield much
Phew - my issue was that I wasn't registering builtin function. Working as expected now. Thanks so much for the help @bjorn3 !
glad it works now
Last updated: Dec 23 2024 at 12:05 UTC