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 fails when build with -trimpath due to lack of gcc #37158

Open
narqo opened this issue Feb 10, 2020 · 2 comments
Open

cmd/go: Build fails when build with -trimpath due to lack of gcc #37158

narqo opened this issue Feb 10, 2020 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@narqo
Copy link
Contributor

narqo commented Feb 10, 2020

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

$ go version
go version go1.13.7 linux/amd64

Does this issue reproduce with the latest release?

Yes, in both 1.13 and 1.14rc1

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

go env Output
$ go env
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
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="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build998143923=/tmp/go-build -gno-record-gcc-switches"

What did you do?

When one builds a Go binary inside Docker container (golang:1.13.7-alpine3.10) adding -trimpath to the build command, fails the build if a C compiler wasn't pre-installed.

Dockerfile:

FROM golang:1.13.7-alpine3.10
ENV GO111MODULE=off
COPY . /go/src/github.com/<goproject>
WORKDIR /go/src/github.com/<goproject>
RUN go build -trimpath -o gobin ./<main.go>

The same code, with the same docker image, but w/o -trimpath builds successfully.

What did you expect to see?

Expected, that go build -trimpath will have the same behaviour as one with no flag.

What did you see instead?

Build fails, requiring gcc.

# runtime/cgo
exec: "gcc": executable file not found in $PATH

As was pointed out by @ianlancetaylor for a similar question on go-nuts 1, this is (likely) due to runtime/cgo needs to be rebuilt in order to trim the paths.

I believe, there isn't any documentation or a note, describing this, so the change in go build's behaviour is surprising for a user.

@bcmills
Copy link
Contributor

bcmills commented Feb 10, 2020

Expected, that go build -trimpath will have the same behaviour as one with no flag.

If the behavior were exactly the same, then there would be no need for the flag. 😅


I think the issue you are describing boils down to: the Go release should ship with a standard library built with -trimpath.

I don't know how feasible that is, but I suspect that it is tantamount to saying that the -trimpath flag should be enabled by default: otherwise, users who invoke go build without -trimpath would run into the same problem that you are running into with -trimpath.

(I think I actually agree that -trimpath should be the default, but it's not a trivial change, and should probably have a separate proposal. See also #24904.)

CC @jayconrod @matloob @cagedmantis @toothrot @dmitshur

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 10, 2020
@bcmills bcmills added this to the Unplanned milestone Feb 10, 2020
@jayconrod
Copy link
Contributor

Related #33840, #27303, #26988.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants