Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stanhu opened this issue Nov 15, 2024 · 3 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@stanhu
Copy link

stanhu commented Nov 15, 2024

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.

@stanhu
Copy link
Author

stanhu commented Nov 15, 2024

Ok, it looks like we can switch our builds to do -B gobuildid instead.

We were doing this workaround before 089cc68676 was around.

@stanhu stanhu closed this as completed Nov 15, 2024
@cherrymui
Copy link
Member

We can't remove the length restriction, as macOS UUID has a fixed length.

Yeah, you discovered -B gobuildid, which should work on both Linux and macOS. Thanks.

@stanhu stanhu changed the title cmd/link: running go build -ldflags "-B <SHA1>" fails in Go 1.23.3 on mccOS cmd/link: running go build -ldflags "-B <SHA1>" fails in Go 1.23.3 on macOS Nov 18, 2024
praveenkumar added a commit to praveenkumar/crc that referenced this issue Feb 4, 2025
As of now, a random build ID (20 digits) generated and added to binary
but with go-1.23.x it is causing following issue in the CI

```
/usr/lib/golang/pkg/tool/linux_amd64/link: -B option too long (max 16 digits): 0x1c32bce09ea23923c57a3cca65fd91e377714192
```

Looks like `gobuilid` can be used to generate it with -B options without
random ID hack and it can work without isssue for CI

- golang/go#70380

```
$ readelf -n out/linux-amd64/crc

Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: x86-64-baseline

Displaying notes found in: .note.gnu.build-id
  Owner                Data size 	Description
  GNU                  0x00000014	NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: f1c4d1d70301bc12737353faf4ee38de3cd25930

```
praveenkumar added a commit to praveenkumar/crc that referenced this issue Feb 4, 2025
As of now, a random build ID (20 digits) generated and added to binary
but with go-1.23.x it is causing following issue in the CI

```
/usr/lib/golang/pkg/tool/linux_amd64/link: -B option too long (max 16 digits): 0x1c32bce09ea23923c57a3cca65fd91e377714192
```

Looks like `gobuilid` can be used to generate it with -B options without
random ID and it can work without isssue for CI

- golang/go#70380

```
$ readelf -n out/linux-amd64/crc

Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: x86-64-baseline

Displaying notes found in: .note.gnu.build-id
  Owner                Data size 	Description
  GNU                  0x00000014	NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: f1c4d1d70301bc12737353faf4ee38de3cd25930

```
praveenkumar added a commit to crc-org/crc that referenced this issue Feb 4, 2025
As of now, a random build ID (20 digits) generated and added to binary
but with go-1.23.x it is causing following issue in the CI

```
/usr/lib/golang/pkg/tool/linux_amd64/link: -B option too long (max 16 digits): 0x1c32bce09ea23923c57a3cca65fd91e377714192
```

Looks like `gobuilid` can be used to generate it with -B options without
random ID and it can work without isssue for CI

- golang/go#70380

```
$ readelf -n out/linux-amd64/crc

Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: x86-64-baseline

Displaying notes found in: .note.gnu.build-id
  Owner                Data size 	Description
  GNU                  0x00000014	NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: f1c4d1d70301bc12737353faf4ee38de3cd25930

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

4 participants