Zhangyx24 opened issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
'''
(module
(type (;0;) (func (param i32) (result i64)))
(import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0)))
(func (;1;) (type 0) (param i32) (result i64)
local.get 0
call 0)
(memory (;0;) 1)
(export "memory" (memory 0))
(export "_start" (func 1)))
'''Then we use 'wat2wasm clock_res_get.wat' to generate the wasm file, and use 'wasmer vaildate clock_res_get.wasm' to validate the wasm file and it passes the validation.
After that, we use command 'wasmtime --invoke "_start" clock_res_get.wasm 1 2' to execute it, but get the error:
Error: failed to run main moduleclock_res_get.wasm
Caused by:
0: failed to instantiate "clock_res_get.wasm"
1: incompatible import type forwasi_snapshot_preview1::clock_res_get
2: function types incompatible: expected func of type(i32) -> (i64)
, found func of type(i32, i32) -> (i32)
Zhangyx24 edited issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1 2
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
Zhangyx24 edited issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
Zhangyx24 edited issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
And
wasmer clock_res_get.wasm
get the same error:error: failed to run `clock_res_get.wasm` │ 1: failed to instantiate WASI module ╰─▶ 2: Error while importing "wasi_snapshot_preview1"."clock_res_get": incompatible import type. Expected Function(FunctionType { params: [I32], results: [I64] }) but received Function(FunctionType { params: [I32, I32], results: [I32] })
Zhangyx24 closed issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
And
wasmer clock_res_get.wasm
get the same error:error: failed to run `clock_res_get.wasm` │ 1: failed to instantiate WASI module ╰─▶ 2: Error while importing "wasi_snapshot_preview1"."clock_res_get": incompatible import type. Expected Function(FunctionType { params: [I32], results: [I64] }) but received Function(FunctionType { params: [I32, I32], results: [I32] })
bjorn3 commented on issue #6371:
If a result type is
(expected $some_type (error $errno))
in witx, an out pointer is used for the$some_type
value, while the return value is$errno
. See for example https://docs.rs/wasi/latest/src/wasi/lib_generated.rs.html#1282-1289 on how to call it.
Zhangyx24 reopened issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
And
wasmer clock_res_get.wasm
get the same error:error: failed to run `clock_res_get.wasm` │ 1: failed to instantiate WASI module ╰─▶ 2: Error while importing "wasi_snapshot_preview1"."clock_res_get": incompatible import type. Expected Function(FunctionType { params: [I32], results: [I64] }) but received Function(FunctionType { params: [I32, I32], results: [I32] })
alexcrichton commented on issue #6371:
I'd recommend following the link that @bjorn3 mentioned to determine the ABIs here. Otherwise the error here is correct and working as expected, so I'm going to close this.
When you say you generated a
*.wat
, though, how did you generate that? What led you to thinking that the return value could bei64
?Additionally the validation phase of WebAssembly does not check against actual host imports, it instead only validates the WebAssembly module in isolation. Instantiation later on, when host imports are provided, is where further type-checking happens to ensure that whatever is imported by the module is actually provided by the host.
alexcrichton closed issue #6371:
In the doc of WASI func : https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md
The signature of the WASI func 'clock_res_get' is params: i32, and result :i32.
<img width="1302" alt="截屏2023-05-11 20 22 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/4c0984fa-6753-49cc-a1b6-69998608bd22">And in the wasi_snapshot_preview1.witx (https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/witx/wasi_snapshot_preview1.witx), it shows the same signature of 'clock_res_get'.
<img width="980" alt="截屏2023-05-11 20 23 57" src="https://github.com/bytecodealliance/wasmtime/assets/28601300/cc17c695-8e2a-4619-9bd1-24d3b8cfda7f">So we generate a wat fie to import the 'clock_res_get' func:
(module (type (;0;) (func (param i32) (result i64))) (import "wasi_snapshot_preview1" "clock_res_get" (func (;0;) (type 0))) (func (;1;) (type 0) (param i32) (result i64) local.get 0 call 0) (memory (;0;) 1) (export "memory" (memory 0)) (export "_start" (func 1)))
Then we use
wat2wasm clock_res_get.wat
to generate the wasm file, and usewasmer vaildate clock_res_get.wasm'
to validate the wasm file and it passes the validation.After that, we use command
wasmtime --invoke "_start" clock_res_get.wasm 1
to execute it, but get the error:Error: failed to run main module `clock_res_get.wasm` Caused by: 0: failed to instantiate "clock_res_get.wasm" 1: incompatible import type for `wasi_snapshot_preview1::clock_res_get` 2: function types incompatible: expected func of type `(i32) -> (i64)`, found func of type `(i32, i32) -> (i32)`
And
wasmer clock_res_get.wasm
get the same error:error: failed to run `clock_res_get.wasm` │ 1: failed to instantiate WASI module ╰─▶ 2: Error while importing "wasi_snapshot_preview1"."clock_res_get": incompatible import type. Expected Function(FunctionType { params: [I32], results: [I64] }) but received Function(FunctionType { params: [I32, I32], results: [I32] })
Zhangyx24 commented on issue #6371:
Thanks a lot.
Last updated: Dec 23 2024 at 12:05 UTC