Open ia0 opened 1 year ago
Interesting thought. You can try to patch defmt-decoder
to enable the wasm
feature in object
. Then just use this patched version with defmt-print
and it might already work. Please report how that goes!
Thanks, I'll try it when I'll get some time (might be in a few months) and report here.
adding WebAssembly support to defmt-print would be a great addition! It's exciting to see that the necessary data is already present in the wasm file, and that support in defmt-decoder and defmt-print is all that's needed to make it work.
I started working on this and realized that:
defmt.x
is doing (i.e. force all symbols to be in a virtual section starting at address 1). However, when using the lower 16-bits of the symbol address, it looks like it's working.If I get more time later (and https://github.com/gimli-rs/object/pull/539 gets merged), I'll try to send a draft PR to demonstrate a possible solution for this issue, such that we can discuss whether it's something we want.
EDIT: Note to myself: Make sure wasm-strip/wasm-opt removes those exports and globals.
I wrote a longer update here: https://github.com/gimli-rs/object/pull/539#issuecomment-1520915958.
I don't think this will be easy. The main difficulty will be to find a way to generate unique identifiers without consuming space in the Wasm linear memory. One idea I had was to use multi-memory, allocate the symbols in that memory, and strip it. Essentially using a memory as a section. But the support for multi-memory in Rust is not there yet.
Not sure if we should close the issue and reopen when feasible (or a new idea is found), or keep it open for tracking purposes.
As suggested by @bjorn3 (https://github.com/gimli-rs/object/pull/539#issuecomment-1521627995) we could just give up on optimizing data transfer and use hashes instead of increasing sequence for identifiers. This shouldn't impact binary size since the address is unknown until linking. Only optimization passes after the symbols get their address would be impacted.
I think we can keep the issue open
It is currently not possible to do
defmt-print -e foo.wasm
because the decoder expect an ELF and fails withUnknown file magic
.It looks like under the hood
defmt-decoder
uses theobject
crate which seems to support WebAssembly through thewasm
feature. Besides, it looks like the necessary data is already in the wasm file (I can see many.defmt.*
custom sections with data looking like formatting strings). So it looks like what is missing is support indefmt-decoder
and maybedefmt-print
.If such support would be added, it would be possible to use
defmt
when targeting WebAssembly.What do you think?
Here's an example file to play with:
Just remove the last line (the one with
defmt-print
) to see that the output is reasonable (it looks like normal defmt output just waiting to be decoded).