wazero: arm64-specific: wasm fails to instantiate: out of bounds memory access

Describe the bug Running a wasm binary returns the error:

error instantiating wasm binary: module[] function[_start] failed: wasm error: out of bounds memory access
wasm stack trace:
        .time.__dataIO_.big8(i32) i32
        .github.com_BurntSushi_toml_internal.init(i32) i32
        .runtime.doInit1(i32) i32
        .runtime.main(i32) i32
        .wasm_pc_f_loop()
        ._rt0_wasm_wasip1()

To Reproduce Running on Darwin/arm64 M2 chip

set -x

if [ ! -d "yoke" ]; then
  git clone --depth=1 https://github.com/yokecd/yoke.git
fi

(
  cd yoke
  GOOS=wasip1 GOARCH=wasm go build -o ../redis-installer.wasm ./examples/redis
)

# will run successfully
go run github.com/tetratelabs/wazero/cmd/wazero@v1.6.0 run ./redis-installer.wasm

# will fail with aforementioned error
go run github.com/tetratelabs/wazero/cmd/wazero@v1.9.0 run ./redis-installer.wasm

Expected behavior Expected same output as wazero@v1.6.0

Environment (please complete the relevant information):

  • Go version: 1.24.0
  • wazero Version: 1.9.0
  • Host architecture: arm64
  • Runtime mode: compiler

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

ok, some degree of progress, big8 can’t be that big, and in fact with a little help from our friend GOSSAFUNC

GOSSAFUNC="time.(*dataIO).big8" GOOS=wasip1 GOARCH=wasm go build -o ../redis-installer.wasm ./examples/redis

we see there is a bunch of inlining happening. I tried a flag to disable inlining earlier and I didn’t get any success… but it turns out the flag has changed and the one I supplied was just being ignored 😄

so here’s the right incantation:

GOOS=wasip1 GOARCH=wasm go build -gcflags='all=-N -l' -o ../redis-installer.wasm ./examples/redis

surprise:

❯ go run ./cmd/wazero run ../repro/redis-installer.wasm
panic: value method time.Time.Local called using nil *Time pointer

goroutine 1 [running]:
time.(*Time).Local(0x0)
        <autogenerated>:1 +0x7
github.com/BurntSushi/toml/internal.init.func1()
        /Users/evacchi/.local/go/pkg/mod/github.com/!burnt!sushi/toml@v1.4.0/internal/tz.go:32 +0x2
github.com/BurntSushi/toml/internal.init()
        /Users/evacchi/.local/go/pkg/mod/github.com/!burnt!sushi/toml@v1.4.0/internal/tz.go:32 +0x3
exit status 2

and with GODEBUG='inittrace=1':

❯ go run ./cmd/wazero run -env GODEBUG='inittrace=1' ../repro/redis-installer.wasm
init runtime @0 ms, 0.033 ms clock, 0 bytes, 0 allocs
init crypto/internal/fips140deps/cpu @0.17 ms, 0.004 ms clock, 0 bytes, 0 allocs
init errors @0.19 ms, 0.024 ms clock, 16 bytes, 1 allocs
init internal/oserror @0.23 ms, 0.009 ms clock, 80 bytes, 5 allocs
init iter @0.26 ms, 0.005 ms clock, 16 bytes, 1 allocs
init math/rand/v2 @0.27 ms, 0.005 ms clock, 16 bytes, 1 allocs
init path @0.29 ms, 0.003 ms clock, 16 bytes, 1 allocs
init strconv @0.31 ms, 0.006 ms clock, 32 bytes, 2 allocs
init sync @0.32 ms, 0.010 ms clock, 0 bytes, 0 allocs
init internal/godebug @0.35 ms, 0.23 ms clock, 312 bytes, 7 allocs
init io @0.60 ms, 0.010 ms clock, 144 bytes, 9 allocs
init encoding/base32 @0.62 ms, 0.016 ms clock, 640 bytes, 2 allocs
init crypto @0.64 ms, 0.003 ms clock, 160 bytes, 1 allocs
init hash/crc32 @0.66 ms, 0.055 ms clock, 1264 bytes, 13 allocs
init math/rand @0.72 ms, 0.007 ms clock, 96 bytes, 2 allocs
init syscall @0.74 ms, 0.046 ms clock, 272 bytes, 3 allocs
init time @0.80 ms, 0.017 ms clock, 384 bytes, 8 allocs
init context @0.83 ms, 0.010 ms clock, 128 bytes, 2 allocs
init github.com/BurntSushi/toml/internal @0.85 ms, 0.032 ms clock, 48 bytes, 3 allocs
error instantiating wasm binary: module[] function[_start] failed: wasm error: out of bounds memory access
wasm stack trace:
        .math_rand.__rngSource_.Uint64(i32) i32
        .github.com_google_go_cmp_cmp_internal_diff.init(i32) i32
        .runtime.doInit1(i32) i32
        .runtime.doInit(i32) i32
        .wasm_pc_f_loop()
        ._rt0_wasm_wasip1()
exit status 1

this is great news because I think the root cause of the issue is the same (same weird difference in crashing behavior when inittrace=1), but at the same time the crash with no inittrace is a nil value which might be slightly easier to pinpoint!

I don’t have the technical expertise to add anything, but I just wanted to let you know that I appreciate your updates!