Confusing error with wasm "a.out"
sunfishcode opened this issue ยท 1 comments
๐ Bug Description
Using the wasi-sdk to compile a C hello world testcase to a wasm binary and examine it with twiggy:
$ clang hello.c
$ file a.out
a.out: WebAssembly (wasm) binary module version 0x1 (MVP)
$ twiggy top a.out
error: Gimli error: UnexpectedEof
caused by: UnexpectedEof
It wasn't immediately clear what was causing this problem. After some experimenting, it appears that twiggy is determining the file type from its name. "a.out" is clang's default for executables, including wasm "executables".
$ mv a.out hello.wasm
$ twiggy top hello.wasm
Shallow Bytes โ Shallow % โ Item
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
9699 โ 25.80% โ printf_core
6143 โ 16.34% โ dlmalloc
2364 โ 6.29% โ data[0]
...
Similar things happen with .o files, though the symptoms are slightly different:
$ clang -c hello.c
$ file hello.o
hello.o: WebAssembly (wasm) binary module version 0x1 (MVP)
$ twiggy top hello.o
Shallow Bytes โ Shallow % โ Item
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ
0 โ 0.00% โ ฮฃ [0 Total Rows]
$ mv hello.o hello.o.wasm
$ twiggy top hello.o.wasm
Shallow Bytes โ Shallow % โ Item
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
86 โ 22.93% โ code[0]
67 โ 17.87% โ custom section 'linking'
34 โ 9.07% โ import env::__indirect_function_table
...
twiggy version: twiggy-opt 0.4.0
๐ Test Case
Take any wasm module file and rename it to "a.out" or "hello.o".
๐ Steps to Reproduce
Take any wasm module file, rename it to "a.out" or "hello.o", and run twiggy top
on it.
๐ฒ Actual Behavior
From the behavior and error messages, it appears twiggy is attempting to decode the wasm modules with a native object file decoder, and producing confusing output.
๐ค Expected Behavior
If it's a deliberate choice to use the filename to determine which decoder to use, a more descriptive error message would help. Otherwise, wasm has a magic cookie which can be used.