How can I inspect the output of the AOT compiler, i.e. the .cwasm file?
I'd like to see the quality of the resulting code.
So far, I have not been able to see any significant performance advantage of using ahead of time compilation with wasmtime, as compared to wamr where the advantage is significant.
You can use objdump -d out.cwasm
to disassemble the .cwasm
file.
The generated code is the same, no matter if you do ahead-of-time or just-in-time compilation. You only gain not having to recompile every time you run your wasm module.
Thanks! You do not happen to know how to disassemble the output of wamrc, do you?
Unfortunately not, as I've never worked with wamr. If it also produces ELF binaries, objdump
might work there as well, but that's just a guess.
It happens to be an ELF file but that is an internal detail, not something that can be relied upon. But because of that, you can use objdump
and similar tools to inspect it.
AOT compilation doesn't do anymore optimizations than JIT compilation, it just allows you to do it ahead of time, and do things like not have a compiler at the location where you are running code.
AOT also enables mmap
ing code/static data from disk, which can be very useful for some workloads.
the primary motivation of wasmtime AOT is to allow the code generation and code execution to take place on different processes/machines/etc, which serverless use cases like fastly, where we compile to cwasm in our control plane and deploy the cwasm to edge nodes. in addition to deduplicating that workload from a large number of systems to just a single system, it also enables us to statically configure wasmtime to not even include the ability to generate code out on edge nodes (by way of cargo features - you can disable cranelift altogether, which means Module::new wont work, just Module::load), for the sake of the principle of least privilege
fitzgen (he/him) said:
It happens to be an ELF file but that is an internal detail, not something that can be relied upon. But because of that, you can use
objdump
and similar tools to inspect it.AOT compilation doesn't do anymore optimizations than JIT compilation, it just allows you to do it ahead of time, and do things like not have a compiler at the location where you are running code.
Unfortunately this does not work for me:
objdump: basicmath.aot: file format not recognized
How did you generate basicmath.aot
?
For example locally I get:
$ cat foo.wat
(module
(table 1 funcref)
(func (param i32)
(call_indirect (local.get 0))
)
)
$ wasmtime compile foo.wat
$ objdump -S foo.cwasm
foo.cwasm: file format elf64-littleaarch64
Disassembly of section .text:
0000000000000000 <wasm[0]::function[0]>:
0: 7f 23 03 d5 hint #27
4: fd 7b bf a9 stp x29, x30, [sp, #-16]!
...
Last updated: Dec 23 2024 at 13:07 UTC