Stream: cranelift

Topic: Get function as a &[u8] from JitModule


view this post on Zulip marin (Jan 03 2025 at 23:04):

Happy new year everyone :)
It would be useful to get the compiled function from a JITModule as a slice to disassemble it for debugging. Looking at the code, It seems like a straightforward addition. Would you accept a PR adding that feature? Maybe I should open an issue first?

view this post on Zulip Chris Fallin (Jan 03 2025 at 23:06):

That seems like a reasonable API -- happy to look at a PR (@bjorn3 may also have more opinions as one of the more frequent users of/contributors to that code)

view this post on Zulip Chris Fallin (Jan 03 2025 at 23:07):

also, for what it's worth, one can look at disassemblies with either clif-util compile --target ... file.clif (for raw CLIF input) or wasmtime compile file.wasm + objdump -d file.cwasm (for Wasm input)

view this post on Zulip Chris Fallin (Jan 03 2025 at 23:07):

or wasmtime explore for a nice html'ified view

view this post on Zulip bjorn3 (Jan 03 2025 at 23:11):

You can also inspect the compilation result stored in the Context after define_function. If you called the right function before define_function that will even contain the vcode of the function (which is pretty close to the final machine code) already as string.

view this post on Zulip marin (Jan 03 2025 at 23:19):

@Chris Fallin thanks for the tips! I'm not using cranelift in the context of wasm this time though
@bjorn3 that sounds like what I need! So iirc, after I call make_context, I can set the want_disas flag, and then retrieve the asm from the compile code (as vcode)? neat I'll try that ! thanks


Last updated: Jan 24 2025 at 00:11 UTC