tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Panic building WASM target when using embed.FS

Open samuel opened this issue 1 year ago • 0 comments

I'm getting a panic in interpreter.go when using TinyGo to compile to the WASM target with embed.FS.

A small test case that triggers the issue: https://github.com/samuel/tinygo-embed-panic

When I try to build using TinyGo 0.330 on macOS installed through Homebrew:

$ tinygo version
tinygo version 0.33.0 darwin/arm64 (using go version go1.23.2 and LLVM version 18.1.2)

$ tinygo build -o bug.wasm -target wasm                             
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x38 pc=0x102902fd8]

goroutine 32 [running]:
github.com/tinygo-org/tinygo/interp.(*runner).run(0x140023300a0, 0x14001fa5680, {0x14002181e90, 0x6, 0x14001dcd650?}, 0x140036a0150, {0x140028ff0f0, 0x10})
        /Users/runner/work/tinygo/tinygo/interp/interpreter.go:361 +0x3448
github.com/tinygo-org/tinygo/interp.(*runner).run(0x140023300a0, 0x14001fa55e0, {0x140020f3e10, 0x3, 0x14002984198?}, 0x140040aab70, {0x140028afdf0, 0xc})
        /Users/runner/work/tinygo/tinygo/interp/interpreter.go:552 +0x673c
github.com/tinygo-org/tinygo/interp.(*runner).run(0x140023300a0, 0x14001fa46e0, {0x14004371590, 0x1, 0x1084d0f40?}, 0x14003fced80, {0x14002d211e8, 0x8})
        /Users/runner/work/tinygo/tinygo/interp/interpreter.go:552 +0x673c
github.com/tinygo-org/tinygo/interp.(*runner).run(0x140023300a0, 0x14001fa4690, {0x0, 0x0, 0x0?}, 0x0, {0x106d42c1f, 0x4})
        /Users/runner/work/tinygo/tinygo/interp/interpreter.go:552 +0x673c
github.com/tinygo-org/tinygo/interp.Run({0x14001476df8?}, 0x102943a7c?, 0x30?)
        /Users/runner/work/tinygo/tinygo/interp/interp.go:117 +0x4dc
github.com/tinygo-org/tinygo/builder.optimizeProgram({0x14001476e50?}, 0x140001cac00, 0x140001dec60)
        /Users/runner/work/tinygo/tinygo/builder/build.go:1108 +0x3c
github.com/tinygo-org/tinygo/builder.Build.func5(0x1400146cc00?)
        /Users/runner/work/tinygo/tinygo/builder/build.go:582 +0x4b0
github.com/tinygo-org/tinygo/builder.runJob(0x1400146cc60, 0x140035fe000)
        /Users/runner/work/tinygo/tinygo/builder/jobs.go:222 +0x48
created by github.com/tinygo-org/tinygo/builder.runJobs in goroutine 1
        /Users/runner/work/tinygo/tinygo/builder/jobs.go:123 +0x43c

If I remove the line _, _ = io.ReadAll(f) it succeeds but I'm not sure that's the real issue as in a larger codebase where I experienced this the problem would come and go based on other code changes (even just having another case statement could cause it).

samuel avatar Oct 09 '24 03:10 samuel