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/go: relative path in 'CC' environment variable should be rejected explicitly #38372

Closed
vedantroy opened this issue Apr 10, 2020 · 8 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@vedantroy
Copy link
Contributor

vedantroy commented Apr 10, 2020

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

1.14.1 linux/amd64

Does this issue reproduce with the latest release?

I'm on 1.14.1, is that recent enough? It seems troublesome to upgrade to 1.14.2

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vedantroy/.cache/go-build"
GOENV="/home/vedantroy/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vedantroy/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="./bin/clang"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="--sysroot=./share/wasi-sysroot -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build024786726=/tmp/go-build -gno-record-gcc-switches"

What did you do?

GO111MODULE=on go get golang.org/x/tools/gopls@latest

What did you expect to see?

gopls get updated.

What did you see instead?

go: golang.org/x/tools/gopls latest => v0.4.0
# runtime/cgo
fork/exec ./bin/clang: no such file or directory

I have clang installed on my system though. So not sure what the issue is.

Edit: I seem to have fixed this issue. Not sure how, but the VsCode Go extension had me click a button that recompiled a bunch of packages. I'll still leave this issue open though, because the error was confusing, and I don't know how to fix it.

Edit 2: My CC variable was mis-configured because earlier I had ran a shell script that messed with my environment. It is worth noting that whatever fix is implemented should probably explicitly mention the CC variable is the root cause because I had no idea until this issue was filed.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Apr 10, 2020
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre stamblerre changed the title gopls: Can't upgrade "fork/exec ./bin/clang: no such file or directory" cmd/go: can't upgrade "fork/exec ./bin/clang: no such file or directory" Apr 10, 2020
@stamblerre stamblerre removed the gopls Issues related to the Go language server, gopls. label Apr 10, 2020
@bcmills bcmills changed the title cmd/go: can't upgrade "fork/exec ./bin/clang: no such file or directory" cmd/go: relative path in 'CC' environment variable should be rejected explicitly Apr 11, 2020
@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Apr 11, 2020
@bcmills bcmills added this to the Backlog milestone Apr 11, 2020
@bcmills
Copy link
Contributor

bcmills commented Apr 11, 2020

The CC environment variable must specify an absolute path, not a relative one.

The fact that cmd/go does not diagnose that problem explicitly is a bug.

CC @jayconrod @matloob

@obeyda
Copy link
Contributor

obeyda commented Apr 12, 2020

I would like to help on this, maybe we need to add checks for CC and CXX in envcmd.MkEnv()

if env := strings.Fields(cfg.Getenv("CC")); len(env) > 0 {

@bcmills
Copy link
Contributor

bcmills commented Apr 13, 2020

Possibly, but we also need to ensure that the user doesn't get stuck with a bad CC value through running go env -w or similar.

So in addition to the check in envcmd.MkEnv, we may also need something akin to the GOOS/GOARCH check:

if err := work.CheckGOOSARCHPair(goos, goarch); err != nil {
base.Fatalf("go env -w: %v", err)
}

@obeyda
Copy link
Contributor

obeyda commented Apr 15, 2020

I am relatively new to this, so i have some questions: in go env -w we can report failure by base.Fatalf, but what should we do in envcmd.MkEnv? print an error and ignore is (set it to the default value)?

@bcmills
Copy link
Contributor

bcmills commented Apr 15, 2020

Since a bad CC value affects most commands that attempt to build, perhaps we should check CC and CXX during cmd/go/internal/work.BuildInit instead of in envcmd.MkEnv.

@gopherbot
Copy link

Change https://golang.org/cl/228517 mentions this issue: cmd/go: make sure CC and CXX are absolute

@obeyda
Copy link
Contributor

obeyda commented Oct 13, 2020

Can someone please review this?

@golang golang locked and limited conversation to collaborators Oct 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants