Skip to content

Execution of unreachable instruction invoking func(list<variant>) #288

@ethanstanley3

Description

@ethanstanley3

Description

echo "`wit-bindgen-go version` | `tinygo version` | `wasmtime --version` | `uname -m`"
wit-bindgen-go version v0.5.0 | tinygo version 0.35.0 darwin/arm64 (using go version go1.23.4 and LLVM version 18.1.2) | wasmtime 28.0.1 (1bdf2c2b5 2025-01-14) | arm64

Execution of a component created using wit-bindgen-go and tinygo hits an unreachable instruction. The component is a composition of two components, host and guest, that target the following worlds:

world guest {
  ... wasi imports ...
  
  variant var {
    a(list<u32>),
    b(u64),
  }

  export foo: func(name: list<var>);
}
world host {
  ... wasi imports...

  variant var {
    a(list<u32>),
    b(u64),
  }

  import foo: func(name: list<var>);

  export wasi:cli/run@0.2.0;
}

Below is the Go source of the host component:

package main

import (
        "go.bytecodealliance.org/cm"
        "example.com/reproduce/host/ns/pkg/host"
)

func main() {
        a := host.VarB(0)
        b := host.VarB(2)
        name := cm.ToList([]host.Var{a, b})
        
        host.Foo(name)

        println("hello from host")
}

And the guest component:

package main

import (
	"go.bytecodealliance.org/cm"
	"example.com/reproduce/guest/ns/pkg/guest"
)

func init() {
	guest.Exports.Foo = func(name cm.List[guest.Var]) {
		println("hello from guest")
	}
}

func main() {}

Component Model bindings are generated using wit-bindgen-go. Components are created using tinygo's wasip2 target. The components are composed using wac and executed with Wasmtime.

Steps to reproduce

Here is a zipped directory that reproduces the bug:
go-list-variant-unreachable.zip

  1. Unzip go-list-variant-unreachable.zip
  2. Build and run with ./verify.sh

Expected behavior

The following message should be written to standard output:

hello from guest
hello from host

Actual behavior

The execution fails. I get the following error message:

Error: failed to run main module `linked.wasm`

Caused by:
    0: failed to invoke `run` function
    1: error while executing at wasm backtrace:
           0:  0x154 - <unknown>!<wasm function 2>
           1: 0x27c80 - wit-component:shim!indirect-$root-foo
           2: 0x151c2 - main!internal/wasi/cli/v0.2.0/run.wasmexport_Run
           3: 0x14ea8 - main!internal/wasi/cli/v0.2.0/run.wasmexport_Run$gowrapper-wasmexport
           4: 0x14439 - main!tinygo_launch
           5: 0x14fd7 - main!runtime.scheduler
           6: 0x14d9e - main!internal/wasi/cli/v0.2.0/run.wasmexport_Run#wasmexport
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: wasm trap: wasm `unreachable` instruction executed

Note: Some changes to the value of b (such as b := host.VarB(0)) cause the execution to succeed.

Additional context

The Go source programs are derived from a test case produced by a differential testing framework for wit-bindgen and wit-bindgen-go. The wit definitions are derived from a test case produced by wit-smith.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions