Stream: git-wasmtime

Topic: wasmtime / issue #6677 JIT: Return both size and pointer ...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 21:30):

wareya opened issue #6677:

Feature

I want get_finalized_function in cranelift_jit's JITModule to return both the pointer and size to JIT'd functions, like get_finalized_data does for data object.

Benefit

This would allow me to disassemble individual compiled functions without having to guess at their size, making it easier for me to debug my compiler. Right now I dump them to standard output one byte at a time until my test program segfaults and manually locate the true end of the function code, which is unsustainable.

Implementation

get_finalized_data already works this way and seems to deal with the same type (CompiledBlob), so it should basically amount to copying that.

Alternatives

Adding a second function for getting the size would also work, but then the API would be inconsistent with itself.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 21:36):

cfallin commented on issue #6677:

cc @bjorn3 for more thoughts, but on the surface this seems totally reasonable to me...

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 21:49):

bjorn3 commented on issue #6677:

Right after calling .define_function() you can use context.compiled_code().unwrap().disassemble() to get a disassembled version of the function. You can also use context.compiled_code().unwrap().code_info().total_size to get the function length if you want to disassemble yourself.

If that isn't enough for your use case, adding a length return value to get_finalized_function should be fine I guess. It would just be a bit noisy for the common case as you almost never need to know the size of a function. Just the address where you can call it.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 23:00):

wareya commented on issue #6677:

That works, thank you. It's strange, though, I wouldn't have been able to figure that out on my own - I can't find CompiledCodeBase in the documentation, neither on docs.rs nor on docs.wasmtime.dev. Is something keeping it from showing up?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 23:04):

bjorn3 commented on issue #6677:

While CompiledCodeBase is marked as public, it is in a private module and not directly re-exported, so rustdoc doesn't render it.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 30 2023 at 23:05):

wareya commented on issue #6677:

Makes sense. Thanks!


Last updated: Dec 23 2024 at 12:05 UTC