Stream: git-wasmtime

Topic: wasmtime / Issue #1547 Inconsistent output versus Wasmer


view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 19:58):

vedantroy opened Issue #1547:

Thanks for opening a bug report! Please answer the questions below
if they're relevant and delete this text before submitting.

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 19:58):

vedantroy labeled Issue #1547:

Thanks for opening a bug report! Please answer the questions below
if they're relevant and delete this text before submitting.

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 19:58):

vedantroy edited Issue #1547:

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 19:58):

vedantroy edited Issue #1547:

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

I assume the issue is with wasmtime.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:13):

alexcrichton commented on Issue #1547:

Thanks for the report! The issue here is that the wasm linear memory isn't exported, but it's expected to be exported for wasi to work with it. You can fix this by replacing (memory 1) with (memory (export "memory") 1).

The exact particulars here are a little up-in-the-air since historically wasi implementations would use a memory without requiring it be exported, but semantically that felt a little odd and we tweaked it to require an export. The fd_write call in the example you've written is returning an error because memory isn't exported, but the error is being ignored.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:13):

alexcrichton labeled Issue #1547:

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

I assume the issue is with wasmtime.


Last updated: Nov 22 2024 at 16:03 UTC