Skip to content

go/build: Passes bad $GOROOT to go list subprocess #35056

Closed
@tv42

Description

@tv42

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

# this sdk came from `go get golang.org/dl/go1.13.3`,
# I'm fiddling with PATH to eliminate other installed Go
# versions to reproduce with a known good version,
# without parent/child version mismatch later.
$ PATH="$HOME/sdk/go1.13.3/bin:/bin:/usr/bin" go version
go version go1.13.3 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
PATH="$HOME/sdk/go1.13.3/bin:/bin:/usr/bin" go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tv/.cache/go-build"
GOENV="/home/tv/.config/go/env"
GOEXE=""
GOFLAGS="-trimpath"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="mntn.llc/go,*.mntn.llc,eagain.net/2019,eagain.net/tools"
GONOSUMDB="mntn.llc/go,*.mntn.llc,eagain.net/2019,eagain.net/tools"
GOOS="linux"
GOPATH="/home/tv/go"
GOPRIVATE="mntn.llc/go,*.mntn.llc,eagain.net/2019,eagain.net/tools"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tv/sdk/go1.13.3"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tv/sdk/go1.13.3/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/tv/z/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/home/tv/tmp/go-build434657787=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~$ mkdir z
~$ cd z
~/z$ go mod init example.com/m
go: creating new go.mod: module example.com/m
~/z$ cat >main.go
package main

import (
	"fmt"
	"go/build"
	"os"
	"runtime"
)

func main() {
	fmt.Printf("runtime.GOROOT=%v\n", runtime.GOROOT())
	_, err := build.Import("example.com/m", ".", build.ImportComment)
	if err != nil {
		fmt.Printf("error: %v", err)
		os.Exit(1)
	}
}
~/z$ PATH="$HOME/sdk/go1.13.3/bin:/bin:/usr/bin" go run .
runtime.GOROOT=go
error: go/build: importGo example.com/m: exit status 2
go: cannot find GOROOT directory: go


exit status 1

What did you expect to see?

Successful run, with ImportDir returning metadata about the package example.com/m that I just created.

What did you see instead?

The go list subprocess is spawned with a broken GOROOT=go in environment, an explicitly set $GOROOT prevents the child from deducing GOROOT from /proc/self/exe, and this causes it to fail.

Confirmation that $GOROOT is passed:

~/z$ PATH="$HOME/sdk/go1.13.3/bin:/bin:/usr/bin" sh -c 'go build && strace -f -o log -v -e execve ./m >/dev/null; grep execve log|tail -1'
1190329 execve("/home/tv/sdk/go1.13.3/bin/go", ["go", "list", "-compiler=gc", "-tags=", "-installsuffix=", "-f={{.Dir}}\n{{.ImportPath}}\n{{.R"..., "example.com/m"], [...skipped things..., "GOOS=linux", "GOARCH=amd64", "GOROOT=go", "GOPATH=/home/tv/go", "CGO_ENABLED=1"]) = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions