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

Crashes under component adapter due to duplicate imports #152

Open
erikrose opened this issue Jan 30, 2025 · 0 comments
Open

Crashes under component adapter due to duplicate imports #152

erikrose opened this issue Jan 30, 2025 · 0 comments

Comments

@erikrose
Copy link

Under common circumstances, the SDK emits builds containing duplicate imports. While this may or may not cause problems for core-warm modules, it does cause fatal errors during warming when running under the component adapter. (The Component spec says "All import names are required to be unique…", so validation gets grumpy.)

Under TinyGo, all is well. This happens only in standard Go.

We can trigger it simply by importing fmt:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Boo.")
}

This simple Hello World yields a duplicate import of fd_write:

(module
  (@custom "go:buildid" (before first) "\ff Go build ID: \22ZAI6HtN-4zG0VVqmMtgC/rfEJODF44cJvsrHdxcKc/B64BrDsnqrpbbNq-uDKP/AWH8AG7tT8ZUOccLYjcx\22\0a \ff")
  (type (;0;) (func (param i32) (result i32)))
  (type (;1;) (func (result i32)))
  (type (;2;) (func (param i32)))
  (type (;3;) (func (param i32 i32) (result i32)))
  (type (;4;) (func (param i32 i64 i32) (result i32)))
  (type (;5;) (func (param i32 i32 i32 i32) (result i32)))
  (type (;6;) (func (param i32 i32 i32) (result i32)))
  (type (;7;) (func (param i64 i64 i64 i64) (result i64)))
  (type (;8;) (func (param i64 i64 i64) (result i64)))
  (type (;9;) (func (param i64) (result i64)))
  (type (;10;) (func (result i64)))
  (type (;11;) (func))
  (type (;12;) (func (param i64 i64) (result i64)))
  (type (;13;) (func (param f64) (result i64)))
  (import "wasi_snapshot_preview1" "sched_yield" (func (;0;) (type 1)))
  (import "wasi_snapshot_preview1" "proc_exit" (func (;1;) (type 2)))
  (import "wasi_snapshot_preview1" "args_get" (func (;2;) (type 3)))
  (import "wasi_snapshot_preview1" "args_sizes_get" (func (;3;) (type 3)))
  (import "wasi_snapshot_preview1" "clock_time_get" (func (;4;) (type 4)))
  (import "wasi_snapshot_preview1" "environ_get" (func (;5;) (type 3)))
  (import "wasi_snapshot_preview1" "environ_sizes_get" (func (;6;) (type 3)))
  (import "wasi_snapshot_preview1" "fd_write" (func (;7;) (type 5)))
  (import "wasi_snapshot_preview1" "random_get" (func (;8;) (type 3)))
  (import "wasi_snapshot_preview1" "poll_oneoff" (func (;9;) (type 5)))
  (import "wasi_snapshot_preview1" "fd_close" (func (;10;) (type 0)))
  (import "wasi_snapshot_preview1" "fd_write" (func (;11;) (type 5)))
  (import "wasi_snapshot_preview1" "fd_fdstat_get" (func (;12;) (type 3)))
  (import "wasi_snapshot_preview1" "fd_fdstat_set_flags" (func (;13;) (type 3)))
  (import "wasi_snapshot_preview1" "fd_prestat_get" (func (;14;) (type 3)))
  (import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func (;15;) (type 6)))
  (table (;0;) 5707 funcref)

For comparison, compiling an empty main() (and thus no fmt import) emits only 1 fd_write:

(module
  (@custom "go:buildid" (before first) "\ff Go build ID: \22oJjh20Vd5HLdjwBLqkiv/3cWfLYIpQjXR-C7uRXx-/irQbKsKoC6gLX3wKK44S/XmL4TBTGUnyXE0hCNQd1\22\0a \ff")
  (type (;0;) (func (param i32) (result i32)))
  (type (;1;) (func (result i32)))
  (type (;2;) (func (param i32)))
  (type (;3;) (func (param i32 i32) (result i32)))
  (type (;4;) (func (param i32 i64 i32) (result i32)))
  (type (;5;) (func (param i32 i32 i32 i32) (result i32)))
  (type (;6;) (func (param i64 i64 i64) (result i64)))
  (type (;7;) (func (param i32 i32 i32) (result i32)))
  (type (;8;) (func (param i64) (result i64)))
  (type (;9;) (func (result i64)))
  (type (;10;) (func))
  (type (;11;) (func (param i64 i64) (result i64)))
  (type (;12;) (func (param f64) (result i64)))
  (import "wasi_snapshot_preview1" "sched_yield" (func (;0;) (type 1)))
  (import "wasi_snapshot_preview1" "proc_exit" (func (;1;) (type 2)))
  (import "wasi_snapshot_preview1" "args_get" (func (;2;) (type 3)))
  (import "wasi_snapshot_preview1" "args_sizes_get" (func (;3;) (type 3)))
  (import "wasi_snapshot_preview1" "clock_time_get" (func (;4;) (type 4)))
  (import "wasi_snapshot_preview1" "environ_get" (func (;5;) (type 3)))
  (import "wasi_snapshot_preview1" "environ_sizes_get" (func (;6;) (type 3)))
  (import "wasi_snapshot_preview1" "fd_write" (func (;7;) (type 5)))
  (import "wasi_snapshot_preview1" "random_get" (func (;8;) (type 3)))
  (import "wasi_snapshot_preview1" "poll_oneoff" (func (;9;) (type 5)))
  (table (;0;) 5184 funcref)

fd_write is not unique in this respect, though it is the most common. Several other duplicates occur in the wild as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant