Repository navigation
Closed
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.CriticalA critical problem that affects the availability or correctness of production systems built using GoA 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.Issues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.arch-wasmWebAssembly issuesWebAssembly issuescompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
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.wasmWhat 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.Issues describing a possible bug in the Go implementation.CriticalA critical problem that affects the availability or correctness of production systems built using GoA 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.Issues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.arch-wasmWebAssembly issuesWebAssembly issuescompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
- StatusShow more project fieldsDone
Activity
ldemailly commentedon Apr 8, 2025
can you reduce it to whichever github.com/external-secrets/external-secrets does in init/globals ?
(I assume the problem doesn't occur without
)
gabyhelp commentedon Apr 8, 2025
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
dmitshur commentedon Apr 8, 2025
CC @golang/wasm.
Zxilly commentedon Apr 8, 2025
Can you share the WAT format code of
function[51716]?davidmdm commentedon Apr 8, 2025
@Zxilly as a bit of a high level end user, I am not all too familiar with the tooling for doing that. I can try later today. But the script above should produce the offending binary for you.
davidmdm commentedon Apr 8, 2025
@Zxilly I have tried running
wasm2waton the binary but get a similar error:wasm2wat ./temp.wasm -o ./temp.wat 2b2bbc1: error: unable to read i32 leb128: i32.const valueRunning in verbose mode does not seem to give us more information:
Zxilly commentedon Apr 8, 2025
I've reproduce the problem and got the binary, thanks.
Zxilly commentedon Apr 8, 2025
I wrote a patch to try to fix this issue, but I'm not quite sure if I'm doing it right.
cc @cherrymui
gopherbot commentedon Apr 8, 2025
Change https://go.dev/cl/663995 mentions this issue:
cmd/internal/obj/wasm: use i64 for large return addrcherrymui commentedon Apr 9, 2025
Thanks for the report. This looks similar (and probably related) to #64856. When it have more than 32K of functions, a number of places in the code don't handle that many functions well. One difference is that this is signed integer overflow, i.e. more than 32K but not 64K. The CL above may be part of the fix, but it is probably not enough, especially once we get to more than 64K functions, it would certainly be not enough. I'll continue looking into it, along with #64856.
cherrymui commentedon Apr 9, 2025
@davidmdm Could you try if the CL above fix the issue? It probably makes it build and pass verification. It would still be good to know if the resulting binary runs okay. Thanks,
The easiest way to do this is to use the gotip command (https://golang.org/dl/gotip) and run
gotip download 663995. Then use gotip as the go command, e.g.gotip build .... (Manually downloading the CL and building the toolchain also works.)5 remaining items
cmd/internal/obj/wasm: use i64 for large return addr
gopherbot commentedon Apr 28, 2025
Change https://go.dev/cl/668615 mentions this issue:
[release-branch.go1.24] cmd/internal/obj/wasm: use i64 for large return addr[release-branch.go1.24] cmd/internal/obj/wasm: use i64 for large retu…