I can't find how to generate and use stack maps. Does anyone have any examples?
You first need to set the enable_safepoints
flag when creating the TargetIsa
. To then get the stackmap you can't use cranelift-simplejit, cranelift-faerie or cranelift-object, as they don't have support for it. Instead you have manually call context.compile_and_emit
and pass a StackmapSink
. This does mean that you will have to do everything from allocating memory (for a jit) / writing an object file (for aot compilation) to handling all relocations. It is probably easier to add stackmap support to cranelift-simplejit, cranelift-faerie or cranelift-object.
Hmm, this is unfortunate.. Is there an open issue about adding stack maps to cranelift-object
? Perhaps I can help with that.
Is there any other way (even if hacky) to get live variables from cranelift backend somehow?
osa1 said:
Hmm, this is unfortunate.. Is there an open issue about adding stack maps to
cranelift-object
? Perhaps I can help with that.
Not that I know.
osa1 said:
Is there any other way (even if hacky) to get live variables from cranelift backend somehow?
What do you need it for?
Garbage collection
Does any of the backends have stack map support currently? Which one(s)?
How do wasm people do GC?
Wasmtime doesn't use the cranelift-module
interface at all. Instead it uses context.compile_and_emit
. Also Wasmtime doesn't have GC support yet. The current stackmap implementation is basically only used by the (disabled by default) Cranelift based WASM backend for Spidermonkey (js engine of firefox)
Thanks @bjorn3 . How hard do you think it would be to implement stackmap support to cranelift-module/cranelift-object? Also, do you think it would be merged if implemented?
I'm only a user now, but I may have some time next week to work on this
module.define_function
already takes a TrapSink
argument. A new StackmapSink
would work, but maybe both should be bundled together into one argument to avoid having many arguments. (others may have another opinion about this) I think this will likely be merged given that TrapSink
is already an argument.
I have no idea what TrapSink
is ... where do I start reading if I wanted to implement this?
Both TrapSink
and StackmapSink
are defined in cranelift_codegen::binemit
. TrapSink
basically records for every instruction that can trap the position and what the trap code is.
So just to make sure I get this right, currently cranlift correctly calls add_stackmap
, but we don't have a StackmapSink
implementation other than the null one for the object code backend?
Yes
Last updated: Dec 23 2024 at 12:05 UTC