Stream: cranelift

Topic: Generating / using unwind information with the cranelift JIT


view this post on Zulip Zeke Medley (May 31 2021 at 19:30):

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?

A lisp compiler and interpreter I've been working on - ZekeMedley/lust

view this post on Zulip bjorn3 (May 31 2021 at 20:52):

You need to create and register an unwind table with the stack unwinder.

view this post on Zulip bjorn3 (May 31 2021 at 20:54):

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.

Cranelift based backend for rustc. Contribute to bjorn3/rustc_codegen_cranelift development by creating an account on GitHub.

view this post on Zulip bjorn3 (May 31 2021 at 20:56):

https://github.com/bytecodealliance/wasmtime/blob/40d546c420c1e6c4909fc80e048dd1854fda1cd6/crates/jit/src/unwind/systemv.rs is the wasmtime implementation which does support unregistering.

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip bjorn3 (May 31 2021 at 20:56):

@Zeke Medley

view this post on Zulip Zeke Medley (Jun 12 2021 at 19:03):

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?

view this post on Zulip Zeke Medley (Jun 12 2021 at 19:04):

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.

view this post on Zulip bjorn3 (Jun 12 2021 at 19:23):

After __register_frame stack unwinding will work.

view this post on Zulip bjorn3 (Jun 12 2021 at 19:24):

You will separately need to store the stackmap to use during root tracing.

view this post on Zulip Zeke Medley (Jun 12 2021 at 21:18):

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

view this post on Zulip Zeke Medley (Jun 12 2021 at 23:25):

Phew - my issue was that I wasn't registering builtin function. Working as expected now. Thanks so much for the help @bjorn3 !

view this post on Zulip bjorn3 (Jun 13 2021 at 05:57):

glad it works now


Last updated: Oct 23 2024 at 20:03 UTC