Skip to content

cmd/link: go:buildinfo was not written in wasm #73741

Open
@Zxilly

Description

@Zxilly
Member

Go version

go version go1.24.3 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\zxilly\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\zxilly\AppData\Roaming\go\env
set GOEXE=
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-fPIC -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\zxilly\AppData\Local\Temp\go-build4032600516=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=T:\gotmp\go.mod
set GOMODCACHE=C:\Users\zxilly\go\pkg\mod
set GONOPROXY=1
set GONOSUMDB=
set GOOS=linux
set GOPATH=C:\Users\zxilly\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=on
set GOTELEMETRYDIR=C:\Users\zxilly\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.3
set GOWASM=
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Build a binary with GOOS=js GOARCH=wasm go build -o main.wasm main.go

What did you see happen?

go:buildinfo was not written into the binary.

What did you expect to see?

go:buildinfo was written like other arch.

Activity

linked a pull request that will close this issue on May 16, 2025
gopherbot

gopherbot commented on May 16, 2025

@gopherbot
Contributor

Change https://go.dev/cl/673475 mentions this issue: cmd/link: attach buildinfo to wasm binary

added
BugReportIssues describing a possible bug in the Go implementation.
on May 16, 2025
cherrymui

cherrymui commented on May 16, 2025

@cherrymui
Member

Thanks for the issue. What is the user-visible effect of this? Thanks.

Zxilly

Zxilly commented on May 16, 2025

@Zxilly
MemberAuthor

go version -m and buildinfo.Read cannot be applied to wasm files, at least with the current logic, which is to read a separate .go.buildinfo segment.

Of course, before we can do any of this, we'll probably also need a debug/wasm

Zxilly

Zxilly commented on May 16, 2025

@Zxilly
MemberAuthor

In fact, we probably don't need a separate .go.buildinfo because that information is already embedded in the data segment as the symbol runtime.modinfo. But that's how all other platforms are implemented, and I'm inclined to be consistent for now.

ref: #73731

cherrymui

cherrymui commented on May 16, 2025

@cherrymui
Member

Okay, thanks. I agree that if we do this, we probably want to be consistent with other platforms, i.e. using a separate .go.buildinfo section, instead of reaching to specific symbols. (One can strip symbol names, but usually not section names.)

Yeah, we don't currently have a way to parse wasm files, so go version -m wouldn't work anyway. Is there a need to add buildinfo now? I'm okay with adding it now, but I'm a bit concerned that there is not a good way to test.

(Personally I'd like to have a wasm file parser, even if just internal, so go tool objdump etc. works. But it needs work.)

Zxilly

Zxilly commented on May 16, 2025

@Zxilly
MemberAuthor

In fact, there is a much simpler way to do this, by checking src/cmd/go/internal/modload/build.go, where we can see that the buildinfo is wrapped around the corresponding magic number, which means that searching for the two magic numbers is usually enough to find the corresponding modinfo without having to rely on the symbol table.

However, this logic does not apply to wasm, because wasm's linker implements memory pack optimization, and consecutive modinfo string may be sliced and diced into different segments (which I think is unlikely to happen), in which case the modinfo string in the binary are not consecutive.

After retore the wasm memory, such logic can apply to wasm. There is a reference implementation in https://github.com/Zxilly/go-size-analyzer/blob/afd50eccac019aa51bca4dbc5eeca1cb7903e64e/internal/wrapper/wasm.go#L92-L123

Zxilly

Zxilly commented on May 16, 2025

@Zxilly
MemberAuthor

It makes sense to provide an wasm parser in the standard library, because after checking the go ecosystem I found that there isn't a sufficiently robust implementation of a wasm parser, the best library I found came from binary decoder in wazero, but they chose to keep this library for the internal implementation.

cherrymui

cherrymui commented on May 16, 2025

@cherrymui
Member

Probably. Or it could be a third-party package. That would be a separate discussion (and proposal), though.

cherrymui

cherrymui commented on May 16, 2025

@cherrymui
Member

For this issue specifically, do you have a need for buildinfo now, before we have any parsing logic? Thanks.

Zxilly

Zxilly commented on May 16, 2025

@Zxilly
MemberAuthor

I don't need it, as I said above, I implemented the runtime.modinfo parsing logic, and this issue was brought up mainly to align with other architectures.

12 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.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

    Todo

    Relationships

    None yet

      Development

      Participants

      @mknyszek@gopherbot@cherrymui@Zxilly@gabyhelp

      Issue actions

        cmd/link: `go:buildinfo` was not written in `wasm` · Issue #73741 · golang/go