-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: drop support for GOROOT_FINAL #62047
Comments
We use GOROOT_FINAL to prevent our build server's path from being written into the resulting toolchain. It sounds like now make.bash will end up building the toolchain with -trimpath set (by default?), which achieves the same goal. Is that right? |
@rittneje, correct. The recommended way to prevent build server paths from being written is to use |
This proposal has been added to the active column of the proposals project |
Have all remaining concerns about this proposal been addressed? |
Based on the discussion above, this proposal seems like a likely accept. Remove all use of GOROOT_FINAL in the tree, since it stopped working in Go 1.21 and no one has complained. Specifically:
|
No change in consensus, so accepted. 🎉 Remove all use of GOROOT_FINAL in the tree, since it stopped working in Go 1.21 and no one has complained. Specifically:
|
Change https://go.dev/cl/539975 mentions this issue: |
Due to golang/go#62047, Go 1.23 won't support `GOROOT_FINAL`. This means that bazel-contrib#971 will no longer fix bazel-contrib#969, meaning linked binaries will contain full GOROOT paths, making them non-reproducible. Instead of using `GOROOT_FINAL`, this change sets `GOROOT` when invoking the linker, which will cause the linker to continue to write `GOROOT` into the binary, keeping builds consistent. This works on Go 1.23rc1 as well. I'm not a rules_go expert and I'm not married to this particular solution, I just wanted to bring attention to the issue. If there's a clever way we can set `-trimpath` when invoking the compiler, that might be better - but we already use that flag to trim off the bazel sandbox I believe.
* Clear GOROOT when linking Due to golang/go#62047, Go 1.23 won't support `GOROOT_FINAL`. This means that #971 will no longer fix #969, meaning linked binaries will contain full GOROOT paths, making them non-reproducible. Instead of using `GOROOT_FINAL`, this change sets `GOROOT` when invoking the linker, which will cause the linker to continue to write `GOROOT` into the binary, keeping builds consistent. This works on Go 1.23rc1 as well. I'm not a rules_go expert and I'm not married to this particular solution, I just wanted to bring attention to the issue. If there's a clever way we can set `-trimpath` when invoking the compiler, that might be better - but we already use that flag to trim off the bazel sandbox I believe. * switch based on runtime.Version
Prior to Go 1.21, setting the
GOROOT_FINAL
variable during themake
scripts changed theGOROOT
value embedded in the tools installed in$GOROOT/bin
and$GOROOT/pkg/tool
. That allowed those tools (primarilycmd/go
) to locateGOROOT
even if it (or just its binaries) was symlinked or copied to a different install location.In Go 1.9 (#18678), to reduce confusion and boilerplate from explicit
GOROOT
settings,cmd/go
was changed to useos.Executable
to locate its own binary and then deriveGOROOT
from the fact thatcmd/go
is normally installed in$GOROOT/bin
.cmd/go
then passes that path to other tools explicitly as needed. As long as thego
command invoked by the user is actually resolved in$GOROOT/bin
(possibly via a symlink), it will infer the correctGOROOT
regardless of what value may happen to be baked in.As of Go 1.21, in order to provide reproducible builds of the Go toolchain (#57120),
cmd/dist
started building releases with the-trimpath
flag set, which incidentally causedGOROOT_FINAL
to have no effect (#61921). (Development versions of toolchains are still built without-trimpath
by default, soGOROOT_FINAL
may affect those builds somewhat.)So
GOROOT_FINAL
is only really helpful if all of the following occur:GOROOT
is moved after themake
script is run,cmd/go
binary is copied or hard-linked (not symlinked!) to some location outside ofGOROOT/bin
, andcmd/go
binary is invoked without settingGOROOT
explicitly.I believe that the intersection of those conditions is “basically never”:
GOROOT
.cmd/go
from some other location (like/usr/bin/go
) are likely to use symlinks or wrapper scripts instead of hard-links or copies.GOROOT_FINAL
cannot locate it when copied to another location #61921) are Void Linux and Guix, which were both using copies, but it appears that they are likely to switch to symlinks instead:GOROOT_FINAL
cannot locate it when copied to another location #61921 (comment)GOROOT
explicitly.On the other hand,
GOROOT_FINAL
has long been a source of bugs and complexity in the Go project (see https://github.com/golang/go/issues?q=is%3Aissue+GOROOT_FINAL+in%3Atitle). In particular, tests of the toolchain itself may need to takeGOROOT_FINAL
into account when they inspect or run artifacts built during the test.I propose that we:
GOROOT_FINAL
settings incmd/dist
,cmd/go
, and themake
scripts.GOROOT_FINAL
incmd/link
with an explict flag (--trimgoroot
?), or changecmd/go
to always setGOROOT_FINAL
to be equal to eitherGOROOT
(if-trimpath
is off) or the literal string"$GOROOT"
(if-trimpath
is on).GOROOT_FINAL
.cmd/link
already does not mention its use ofGOROOT_FINAL
.)The text was updated successfully, but these errors were encountered: