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: -B gobuildid doesn't work when building the toolchain itself #63934

Closed
znkr opened this issue Nov 3, 2023 · 6 comments
Closed

cmd/link: -B gobuildid doesn't work when building the toolchain itself #63934

znkr opened this issue Nov 3, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@znkr
Copy link
Contributor

znkr commented Nov 3, 2023

This is a follow up to #41004 which added support for -B gobuildid to cmd/link. Unfortunately, this doesn't work when building the toolchain itself.

What version of Go are you using (go version)?

tip

What did you do?

 % GO_LDFLAGS="-B gobuildid" ./make.bash

What did you expect to see?

A successful build producing Go toolchain binaries that have .note.gnu.build-id ELF section.

What did you see instead?

 % GO_LDFLAGS="-B gobuildid" ./make.bash
Building Go cmd/dist using /usr/lib/google-golang. (go1.22-20230729-RC00 cl/552016856 +457721cd52 X:fieldtrack,bo
ringcrypto linux/amd64)
Building Go toolchain1 using /usr/lib/google-golang.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.
HASH[moduleIndex]
HASH[moduleIndex]: "devel go1.22-eca5a97340 Tue Sep 19 05:51:26 2023 +0000"
HASH[moduleIndex]: "modroot [RECACTED]/dev/go/src/cmd\n"
...
HASH[moduleIndex]: "file template.go 2023-09-19 12:37:51.569044164 +0000 UTC 7335\n"
HASH[moduleIndex]: 5cf632a5d0cc7bcf669b75b3abc54664c46ea44ca853a3d5812f5efccf086406
cmd/link true
go tool dist: unexpected stale targets reported by  [RECACTED]/dev/go/pkg/tool/linux_amd64/go_bootstrap list -gcflags="" -ldflags="-B gobuildid" for [cmd/asm cmd/cgo cmd/compile cmd/link] (consider rerunning with GOMAXPROCS=1 GODEBUG=gocachehash=1):
        STALE cmd/asm: stale dependency: internal/goarch
        STALE cmd/cgo: stale dependency: internal/goarch
        STALE cmd/compile: stale dependency: internal/goarch
        STALE cmd/link: stale dependency: internal/goarch
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 3, 2023
@cherrymui
Copy link
Member

cherrymui commented Nov 3, 2023

This is known, and we went back and forth a few times in CL https://go.dev/cl/511475 , and that is partly the reason we don't always do this (if -B is not otherwise set).

The issue is that the GNU build ID, being part of the toolchain binary, is considered as input for the next compilation. So there is a convergence problem. There are probably ways to solve it, and we've discussed a lot on the CL. But it needs more thoughts.

If you really want it, maybe you can do go install -ldflags=-B=gobuildid cmd/... after make.bash. That will make the standard library packages become stale and will need rebuild at the next compilation, but that is probably okay.

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 3, 2023
@cherrymui cherrymui added this to the Unplanned milestone Nov 3, 2023
@znkr
Copy link
Contributor Author

znkr commented Feb 19, 2024

Thanks Cherry. I gave that a spin, but ran into new issues after trying that and gave up. In the end, I solved it by specifying a fixed build id that's overridden with the hash sum of the binary in a separate step after make.bash.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618597 mentions this issue: cmd/internal/buildid: skip over Mach-O UUID from buildid computation

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618600 mentions this issue: cmd/internal/buildid: skip over GNU build ID from buildid computation

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618601 mentions this issue: cmd/link: on ELF, generate GNU build ID by default

gopherbot pushed a commit that referenced this issue Oct 21, 2024
With the "-B gobuildid" linker option (which will be the default
on some platforms), the host build ID (GNU build ID, Mach-O UUID)
depends on the Go buildid. If the host build ID is included in the
Go buildid computation, it will lead to convergence problem for
the toolchain binaries. So ignore the host build ID in the buildid
computation.

This CL only handles Mach-O UUID. ELF GNU build ID will be handled
later.

For #68678.
For #63934.

Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14,gotip-darwin-arm64_13
Change-Id: Ie8ff20402a1c6083246d25dea391140c75be40d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/618597
Reviewed-by: Michael Knyszek <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
gopherbot pushed a commit that referenced this issue Oct 21, 2024
This is similar to CL 618597, but for GNU build ID on ELF. This
makes it possible to enable "-B gobuildid" by default on ELF.

Updates #41004.
For #63934.

Change-Id: I4e663a27a2f7824bce994c783fe6d9ce8d1a395a
Reviewed-on: https://go-review.googlesource.com/c/go/+/618600
Reviewed-by: Than McIntosh <[email protected]>
Reviewed-by: Michael Knyszek <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621639 mentions this issue: cmd/link: don't pass --build-id to C linker on Solaris

gopherbot pushed a commit that referenced this issue Oct 24, 2024
On Solaris the default (non-GNU) C linker doesn't support the
--build-id flag (and I'm not aware of any alternative). So check
that the linker supports the flag before passing it.

Updates #41004, #63934.

Cq-Include-Trybots: luci.golang.try:gotip-solaris-amd64
Change-Id: I4379e5bf6eb495154d663ac4ed802ecb11fcf91c
Reviewed-on: https://go-review.googlesource.com/c/go/+/621639
Reviewed-by: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 24, 2024
@dmitshur dmitshur modified the milestones: Unplanned, Go1.24 Oct 24, 2024
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. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants