Stream: wasmtime

Topic: Format of .cwasm file?


view this post on Zulip Mats Brorsson (Oct 26 2023 at 08:50):

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.

view this post on Zulip Martin Fink (Oct 26 2023 at 09:48):

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.

view this post on Zulip Mats Brorsson (Oct 26 2023 at 09:59):

Thanks! You do not happen to know how to disassemble the output of wamrc, do you?

view this post on Zulip Martin Fink (Oct 26 2023 at 10:10):

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.

view this post on Zulip fitzgen (he/him) (Oct 26 2023 at 16:00):

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.

view this post on Zulip Lann Martin (Oct 26 2023 at 16:02):

AOT also enables mmaping code/static data from disk, which can be very useful for some workloads.

view this post on Zulip Pat Hickey (Oct 26 2023 at 17:21):

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

view this post on Zulip Mats Brorsson (Oct 30 2023 at 10:16):

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

view this post on Zulip Alex Crichton (Oct 30 2023 at 13:37):

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