Skip to content

cmd/compile: program compiles to wasm but is invalid: go:wasmexport: integer too large #73246

@davidmdm

Description

@davidmdm

Go version

go1.24.2 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/davidmdm/go/bin'
GOCACHE='/Users/davidmdm/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/davidmdm/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/s1/hqn8jdf97bj_xvlp070s_mh00000gn/T/go-build3338415171=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/davidmdm/Documents/coding/yokecd/examples/go.mod'
GOMODCACHE='/Users/davidmdm/go/pkg/mod'
GONOPROXY='github.com/davidmdm/*'
GONOSUMDB='github.com/davidmdm/*'
GOOS='darwin'
GOPATH='/Users/davidmdm/go'
GOPRIVATE='github.com/nestoca/*,github.com/davidmdm/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/davidmdm/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/davidmdm/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='go1.24.2+auto'
GOTOOLDIR='/Users/davidmdm/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I compiled a program to wasm using GOOS=wasip1 GOARCH=wasm and when I tried to execute it with wazero and wasmtime found that the program was invalid.

I have managed to create a minimal reproduction.

Create a new directory and run the following script.

(It seems to only fail if I import the external-secret project and use a wasm export in combination)

set -x

go mod init temp

go get github.com/external-secrets/external-secrets@v0.15.1
go mod tidy

cat <<EOF >main.go
package main

import _ "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"

func main() {}

//go:wasmexport malloc
func malloc(size uint32) uint32 {
	return 0
}
EOF

GOOS=wasip1 GOARCH=wasm go build -o ./temp.wasm .

wazero compile ./temp.wasm || wasmtime compile ./temp.wasm
EOF

GOOS=wasip1 GOARCH=wasm go build -o ./temp.wasm .

wazero compile ./temp.wasm || wasmtime compile ./temp.wasm

What did you see happen?

Both wazero and wasmtime fail to compile the wasm binary produced by the above program.

Wazero:

error compiling wasm binary: invalid function[51716] export["malloc"]: read i32 immediate: overflows a 32-bit integer

Wasmtime:

Error: WebAssembly translation error

Caused by:
    Invalid input WebAssembly code at offset 45267909: invalid var_i32: integer too large

What did you expect to see?

Binary produced by Go Toolchain compiles successfully and can be executed successfully.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.CriticalA critical problem that affects the availability or correctness of production systems built using GoFixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.arch-wasmWebAssembly issuescompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions