Open
Description
What version of Go are you using (go version
)?
$ go version go version devel go1.21-993707a9d6 Tue May 30 20:19:54 2023 +0000 linux/arm64
What did you do?
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
)
func main() {
b := [16]byte{}
rand.Read(b[:])
fmt.Println(hex.EncodeToString(b[:]))
}
GOARCH=wasm GOOS=wasip1 go build -o main.wasm main.go
wasm2wat main.wasm
The imports in the generated .wat file are:
(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_read" (func (;11;) (type 5)))
(import "wasi_snapshot_preview1" "fd_write" (func (;12;) (type 5)))
(import "wasi_snapshot_preview1" "random_get" (func (;13;) (type 3)))
(import "wasi_snapshot_preview1" "fd_fdstat_get" (func (;14;) (type 3)))
(import "wasi_snapshot_preview1" "fd_fdstat_set_flags" (func (;15;) (type 3)))
(import "wasi_snapshot_preview1" "fd_prestat_get" (func (;16;) (type 3)))
(import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func (;17;) (type 6)))
Both fd_write
and random_get
appear twice.
What did you expect to see?
Each import appears only once
This isn't an invalid wasm file and doesn't affect the end result much, but there is clearly some part of the compiler that isn't weeding out duplicate imports for wasm.