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: build sets PWD to relative path #46832

Closed
trofi opened this issue Jun 19, 2021 · 4 comments
Closed

cmd/go: build sets PWD to relative path #46832

trofi opened this issue Jun 19, 2021 · 4 comments
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@trofi
Copy link

trofi commented Jun 19, 2021

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

$ go version
go version go1.16.5 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
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/slyfox/.cache/go-build"
GOENV="/home/slyfox/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/slyfox/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/slyfox/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"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="x86_64-pc-linux-gnu-gcc"
CXX="x86_64-pc-linux-gnu-g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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=/tmp/go-build2541492012=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This is a forward of downstream ccache/ccache#860 bug where ccache was confused by PWD=. set by go build. In ccache/ccache#860 (comment) Joel Rosdahl notes that PWD should be an absolute path.

ccache is fixed since but I think it's worth fixing go build not to produce relative paths.

Executable single-file example:

Here is a directly executable example to illustrate the problem extracted from docker project:

#!/bin/bash

CC=gcc

# cleanup
rm -rf -- temp bug ccache-wrappers .cache

# create test files:
## simple go.mod:
cat > go.mod <<EOF
module github.com/PWD-bug

go 1.13
EOF

## simple main.go:
cat > main.go <<EOF
package main

import "C"

func main() {}
EOF

# create local ccache wrapper for $CC
mkdir -p ccache-wrappers
ln -s /usr/bin/ccache ccache-wrappers/${CC}

# create temp dir
mkdir -p temp

env -i \
  "CC=$CC" \
  "HOME=$(pwd)" \
  "TMPDIR=$(pwd)/temp" \
  "CCACHE_BASEDIR=$(pwd)" \
  "PATH=$(pwd)/ccache-wrappers:/usr/bin:/bin" \
go build -o bug .

What did you expect to see?

Expected the test to build successfully.

What did you see instead?

The ccache detects relative path in PWD and crashes:

$ ./bug.bash
# github.com/PWD-bug
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: signal: aborted (core dumped)
ccache: Util.cpp:731: std::string Util::get_relative_path(nonstd::sv_lite::string_view, nonstd::sv_lite::string_view): failed assertion: Util::is_absolute_path(dir)
@seankhliao seankhliao changed the title go build sets PWD=. (relative path instead of absolute) and breaks at least ccache. cmd/go: build sets PWD to relative path Jun 19, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 19, 2021
@seankhliao
Copy link
Member

cc @bcmills @jayconrod @matloob

@jayconrod jayconrod 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 Jun 21, 2021
@jayconrod jayconrod added this to the Backlog milestone Jun 21, 2021
@jayconrod
Copy link
Contributor

Looked into this a bit. I was able to reproduce the failure on a Debian machine. Adding a panic on non-absolute paths to base.AppendPWD caused problems very quickly. There are cases where we pass in "" and ".".

@gopherbot
Copy link

Change https://golang.org/cl/378396 mentions this issue: cmd/go/internal/base: in AppendPWD, check that PWD is absolute

@bcmills bcmills modified the milestones: Backlog, Go1.19 Jan 13, 2022
@bcmills bcmills added the early-in-cycle A change that should be done early in the 3 month dev cycle. label Jan 13, 2022
@bcmills bcmills self-assigned this Jan 13, 2022
@gopherbot
Copy link

This issue is currently labeled as early-in-cycle for Go 1.19.
That time is now, so a friendly reminder to look at it again.

@rsc rsc unassigned bcmills Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FrozenDueToAge 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