Hello, hope it's ok to post this;
I'm toying around with AOT compilation using Cranelift and I've been trying to figure out how to add debug symbols to emitted object files from cranelift-object since I'm otherwise unable to step-through the compiled code as far as I can understand.
I should note that I'm both new to wasmtime/cranelift and unfamiliar with being this hands-on with manipulating code files.
Am I correct in understanding that cranelift currently does not have any functionality for adding debug information to emitted code, or at least not object files? I was hoping that
FunctionStencil.collect_debug_info would help but it doesn't appear to affect my output, so I can only assume that it's intended for JIT-targetted code.
I understand that DWARF information can be inserted into the object before writing to disk, but I've had trouble finding cranelift-specific examples (other than the rustc repository which I will look into soon), and the DWARF specification itself is likewise difficult to parse in order to produce a working example for my own code.
Searching for specific details has been difficult so I'm hoping someone here could help to clarify. I've tried looking into using the DWARF format but I'm having difficulties orienting myself around the specification and how cranelift, gimli and objects interact with each other due to the sparse documentation. Maybe I'm just biting off more than I can chew.
If someone could redirect me to appropriate documentation or some other solution (am I just missing something obvious?) I'd be very appreciative.
All collect_debug_info
does is ensure that any debuginfo you put into the Function
gets preserved and appropriately transformed into the output MachBuffer
. You need to build the actual DWARF debuginfo sections yourself using eg the gimli crate and add them to the object
after module.finalize()
.
Thanks, I hope it's ok that I didn't reply the past week; I'd been meaning to.
That kind of confirms what I suspected but I've been running into an issue trying to write the debug information into the object when using a symbol as an address for linking object files (e.g. I'm currently calling the cranelift-generated code from an entry point in another file).
I've been trying to emulate what the Rust compiler does but I get an "InvalidAddress" error when trying to write the information to the sections. I've tried to track down the source but I haven't been able to find a stack trace from the error.
Do you have any pointers as to what may be causing the error? As I understand it, the Symbols (in gimli) should be able to work just fine with FuncIds and I haven't been able to find anything to help troubleshoot. I can run the generated code just fine.
Last updated: Apr 07 2025 at 19:03 UTC