Hi,
I tried invoking a Wasm module I compiled using emscripten 3.1.24 and wasmtime-cli 8.0.0. It has a bunch of imports I don't care about, so I used the new --default-values-unknown-imports flag to ignore them. I then got this error:
Error: failed to run main module module.wasm
Caused by:
0: failed to instantiate "module.wasm"
1: incompatible import type for wasi_snapshot_preview1::fd_seek
2: function types incompatible: expected func of type (i32, i32, i32, i32, i32) -> (i32)
, found func of type (i32, i64, i32, i32) -> (i32)
I'm not sure why there are more than 3 arguments in both the signature that wasmtime expects and the signature that the module wants, becaue according to the spec fd_seek should only accept the fd, offset, and whence arguments. Does anyone have an idea of what is happening? Could there be inconsistent calling conventions at play? Are there any good mitigations?
OK, I found the reason for the fourth argument, it is a pointer that contains the filesize retrun value
https://github.com/WebAssembly/wasi-libc/blob/0b3b1bb9f1776d7e64ef65b899ed6b3cfa9576eb/libc-bottom-half/headers/public/wasi/api.h#L1721
Still, why does wasmtime expect five arguments then? Did I accidentally compile a 32-bit wasmtime that does not support i64, and it split up the offset argument into two i32s?
If you want to run a wasm module using wasmtime, you have to compile it with wasi-sdk, not emscripten. Emscripten uses a different syscall interface. It just so happens to overlap a lot with wasi.
Thanks! Just out of curiosity, is there any documentation regarding the Wasi functions signatures that explain why fd_seek uses five arguments?
No idea why that is the case.
No idea why that is the case.
@wsta , you are probably looking for the WASI preview1 definition here: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#fd_seek
Thanks, but I already found that. It shows that fd_seek has three arguments viewed from a high level, but not how many arguments are actually used in Wasm. Based on the wasi-libc api, it would make sense that four arguments are used
https://github.com/WebAssembly/wasi-libc/blob/0b3b1bb9f1776d7e64ef65b899ed6b3cfa9576eb/libc-bottom-half/headers/public/wasi/api.h#L1721
I also checked with another Wasm module compiled using wasi-sdk, and interestingly it uses four arguments, just like the module compiled with emscripten. But in this case wasmtime has no problems with it.
Last updated: Nov 22 2024 at 17:03 UTC