This repository has been archived by the owner on May 11, 2020. It is now read-only.
This repository has been archived by the owner on May 11, 2020. It is now read-only.
wasm: functions in FunctionIndexSpace include wrong contents #190
Open
Description
- Build a hello-world wasm:
package main
func main() {
println("Hello, World!")
}
GOOS=js GOARCH=wasm go build -o test.wasm helloworld.go
- Run the below code:
package main
import (
"fmt"
"os"
"github.com/go-interpreter/wagon/wasm"
)
func main() {
f, err := os.Open("test.wasm")
if err != nil {
panic(err)
}
defer f.Close()
mod, err := wasm.ReadModule(f, nil)
if err != nil {
panic(err)
}
fn := mod.FunctionIndexSpace[0]
fmt.Printf("name: %q\n", fn.Name) // This is empty. That's fine since this is an imported function 'debug'.
fmt.Printf("len(code): %d\n", len(fn.Body.Code)) // This is not empty. That's unexpected. This content is for the first function as 'go.buildid'.
}
It looks like the function's index and its instructions don't match. Some of the first functions should be imported functions, but include instructions for other functions. I think the function bodies are shifted.
Metadata
Assignees
Labels
No labels
Activity