Skip to content

cmd/link: running go build -ldflags "-B <SHA1>" fails in Go 1.23.3 on macOS #70380

@stanhu

Description

@stanhu

Go version

go version go1.23.3 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/stanhu/.local/share/mise/installs/go/1.23.3/bin'
GOCACHE='/Users/stanhu/Library/Caches/go-build'
GOENV='/Users/stanhu/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/stanhu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/stanhu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/stanhu/.local/share/mise/installs/go/1.23.3'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/stanhu/.local/share/mise/installs/go/1.23.3/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/stanhu/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/k4/mbnh565n4wg6xpbqv45tv91h0000gn/T/go-build3699512861=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

We create binaries with our own GNU build IDs. This used to work fine in Go 1.23.2, but it now fails in Go 1.23.3.

To reproduce, create test.go:

package main

func main() { }

Then run:

% go build -ldflags "-B 0x2f89c25e032c0815b33c9ec2a4aa0012f6eb3090" test.go
# command-line-arguments
/Users/stanhu/.local/share/mise/installs/go/1.23.3/pkg/tool/darwin_arm64/link: -B option too long (max 16 digits): 0x2f89c25e032c0815b33c9ec2a4aa0012f6eb3090

I believe 5472853 (the fix for #68678 (comment)) caused this issue. Now on macOS, the build IDs can only be 16 characters.

@cherrymui Can we remove this restriction?

What did you see happen?

link: -B option too long (max 16 digits): 0x2f89c25e032c0815b33c9ec2a4aa0012f6eb3090

What did you expect to see?

No build errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions