Skip to content

cmd/dist: tools built with GOROOT_FINAL cannot locate it when copied to another location #61921

Not planned
@g4s8

Description

@g4s8

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

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ /usr/lib/go/bin/go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/g4s8/.cache/go-build'
GOENV='/home/g4s8/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/g4s8/go/pkg/mod'
GOOS='linux'
GOPATH='/home/g4s8/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
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 -m64 -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4273986275=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to build go 1.21.0 from sources for Void Linux go package: https://github.com/void-linux/void-packages

The steps to build it (inside go repo directory):

unset GCC CC CXX LD CFLAGS
unset CGO_CXXFLAGS CGO_ENABLED

export GOROOT_FINAL=/usr/lib/go
export GOROOT=$PWD
export GOARCH=amd64

cd src
bash make.bash -v

sudo rm -f /usr/bin/go
sudo rm -fr /usr/lib/go/
sudo cp  ../bin/* -t /usr/bin
sudo cp -r .. /usr/lib/go

What did you expect to see?

When running /usr/bin/go version (or any other go command, like go build, etc) to see

go version go1.21.0 linux/amd64

What did you see instead?

When running go command or /usr/bin/go:

$ go version
go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set

$ go build
go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set

If I run /usr/lib/go/bin/go, then all commands works fine:

$ /usr/lib/go/bin/go version
go version go1.21.0 linux/amd64

If I run exactly the same build commands for go version 1.20.7, it's working fine:

$ go version
go version go1.20.7 linux/amd64

or

$ /usr/bin/go version
go version go1.20.7 linux/amd64

Activity

changed the title [-]GOROOT_FINAL environment doesn't work for go1.21.0[/-] [+]cmd/go: `GOROOT_FINAL` doesn't work for go1.21.0[/+] on Aug 10, 2023
added this to the Backlog milestone on Aug 10, 2023
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Aug 10, 2023
mknyszek

mknyszek commented on Aug 10, 2023

@mknyszek
Contributor
changed the title [-]cmd/go: `GOROOT_FINAL` doesn't work for go1.21.0[/-] [+]cmd/dist: `GOROOT_FINAL` doesn't work for go1.21.0[/+] on Aug 10, 2023
self-assigned this
on Aug 10, 2023
modified the milestones: Backlog, Go1.22 on Aug 10, 2023
bcmills

bcmills commented on Aug 10, 2023

@bcmills
Contributor

This is almost certainly a consequence of https://go.dev/cl/463740 (for #24904).

When built with -trimpath, the go command uses os.Executable to find its GOROOT, expecting that it is installed at $GOROOT/bin/go, and lots of Go programs (especially tests) expect to be able to find the go command at that location (from a configuration that gives only a GOROOT path).

@g4s8, is there a reason your script is using cp to make copies of the binaries in GOROOT/bin, instead of using ln to make /usr/bin/go a symbolic link? It seems like that would be a simpler solution, and would allow the Go toolchain installed on Void Linux to use the same reproducible binaries that are distributed through the Go project.

changed the title [-]cmd/dist: `GOROOT_FINAL` doesn't work for go1.21.0[/-] [+]cmd/dist: tools built with `GOROOT_FINAL` cannot locate it when copied to another location[/+] on Aug 10, 2023
bcmills

bcmills commented on Aug 10, 2023

@bcmills
Contributor

I wonder if we should change cmd/dist to omit the -trimpath flag when GOROOT_FINAL is set.

(But I would still recommend not setting it, and using symlinks instead. 🤷‍♂️)

40 remaining items

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

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Unfortunate

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @rsc@mknyszek@g4s8@dmitshur@bcmills

      Issue actions

        cmd/dist: tools built with `GOROOT_FINAL` cannot locate it when copied to another location · Issue #61921 · golang/go