Skip to content
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
@hajimehoshi

Description

  1. Build a hello-world wasm:
package main

func main() {
        println("Hello, World!")
}
GOOS=js GOARCH=wasm go build -o test.wasm helloworld.go 
  1. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions