Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of _start export causes exception #362

Closed
kanaka opened this issue Apr 16, 2019 · 4 comments
Closed

Lack of _start export causes exception #362

kanaka opened this issue Apr 16, 2019 · 4 comments
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi

Comments

@kanaka
Copy link

kanaka commented Apr 16, 2019

Describe the bug

wasmer 0.3.0 appears to assume that a wasm module exports a "_start" function. This should either be optional or dropped since (start ...) is already supported and is called before the exported "_start" routine.

Steps to reproduce

The following wat file:

(module
  (memory 256)
  (export "memory" (memory 0))

  (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

  ;; __wasi_ciovec_t struct
  (data (i32.const 0) "\08\00\00\00") ;; buf: pointer to hello string
  (data (i32.const 4) "\0c\00\00\00") ;; buf_len: 12 characters
  ;; string
  (data (i32.const 8) "hello world\n")

  (func $main
    (drop (call $fd_write (i32.const 1) (i32.const 0) (i32.const 1) (i32.const 64)))
  )

  (start $main)
  ;;(export "_start" $main)
)

Will result in the following:

$ ~/.wasmer/bin/wasmer run wasitests/start.wasm
hello world
"ResolveError: ExportNotFound { name: \"_start\" }"

Note that the function specified by (start) is being called and then the exception is thrown. If both (start) and exported "_start" are used (uncomment export above) then the main function is executed twice as follows:

$ ~/.wasmer/bin/wasmer run wasitests/start.wasm
hello world
hello world

Expected behavior

wasmer should not require "_start" to be exported since this functionality is already supported by the standard (start) mechanism.

@kanaka kanaka added the bug Something isn't working label Apr 16, 2019
@syrusakbary
Copy link
Member

syrusakbary commented Apr 16, 2019

Good catch! Thanks for reporting the issue

@kanaka
Copy link
Author

kanaka commented Apr 17, 2019

Related issue in lucet: bytecodealliance/lucet#129 (comment) Based on discussion there seems like "_start" or something like it is needed (although I've suggested a different less confusing name) but the problem is that wasmer and lucet and throwing an exception when "_start" isn't exported (or is swallowing the exception).

@bjfish bjfish added the 📦 lib-wasi About wasmer-wasi label Apr 21, 2019
@bjfish
Copy link
Contributor

bjfish commented Apr 22, 2019

This is also being discussed here: WebAssembly/WASI#19

@syrusakbary
Copy link
Member

Closing the ticket here in favor of: WebAssembly/WASI#19
:)

surban pushed a commit to rust-wasi-web/wwrr that referenced this issue Nov 9, 2024
Correct types field in package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi
Projects
None yet
Development

No branches or pull requests

3 participants