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: regression on the default of CGO_ENABLED to 0 for cross builds #33673

Closed
bufflig opened this issue Aug 15, 2019 · 6 comments
Closed

cmd/go: regression on the default of CGO_ENABLED to 0 for cross builds #33673

bufflig opened this issue Aug 15, 2019 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@bufflig
Copy link
Contributor

bufflig commented Aug 15, 2019

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

$ go version
go version go1.12.5 linux/amd64
$ go version
go version debug linux/amd64 (tip)

Does this issue reproduce with the latest release?

Yes, it is with the latest release

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

go env Output
$ go env # 1.13 cross build
GOARCH="ppc64le"
GOBIN=""
GOCACHE="[redacted]"
GOENV="[redacted]"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="[redacted]"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="[redacted]"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="[redacted]"
GCCGO="gccgo"
GOPPC64="power8"
[redacted]
CGO_ENABLED="0"
[redacted]

What did you do?

When cross compiling on 1.13 (tip), CGO is disabled by default. This is a change of behavior since 1.12.
1.12:
GOARCH=ppc64le go env | grep CGO_ENABLED
CGO_ENABLED="1"
1.13:
GOARCH=ppc64le go env | grep CGO_ENABLED
CGO_ENABLED="0"

The cl introducing the change is https://golang.org/cl/171137
The cl description does not clearly state the changed behavior.

What did you expect to see?

CGO_ENABLED="1"
Either the unchanged behavior, or the changed behavior pointed out in the cl description and possibly even in release notes?

The changed behavior makes sense, as the environment needs to be updated anyway to get CGO to work when cross compiling, so an "out of the box" behavior where it's disabled makes sense. So fwiw, my suggestion is to just document it.

What did you see instead?

CGO_ENABLED="0"

We could either revert to the old behavior, or the changed behavior pointed out in the cl description and possibly even in release notes?

The changed behavior makes sense, as the environment needs to be updated anyway to get CGO to work when cross compiling, so an "out of the box" behavior where it's disabled makes sense. So fwiw, my suggestion is to just document it.

@cherrymui
Copy link
Member

1.12:
GOARCH=ppc64le go env | grep CGO_ENABLED
CGO_ENABLED="1"

I cannot reproduce this. I got

$ GOARCH=ppc64le go1.12 env | grep CGO_ENABLED
CGO_ENABLED="0"

It seems to me that for cross compilation CGO_ENABLED has been always 0, since at least go 1.6.

@dsnet dsnet changed the title cl/171137 changes the default of CGO_ENABLED to 0 for cross builds cmd/go: regression on the default of CGO_ENABLED to 0 for cross builds Aug 15, 2019
@dsnet dsnet added release-blocker Soon This needs to be done soon. (regressions, serious bugs, outages) labels Aug 15, 2019
@dsnet dsnet added this to the Go1.13 milestone Aug 15, 2019
@mvdan
Copy link
Member

mvdan commented Aug 15, 2019

I cannot reproduce this regression either. Perhaps provide clearer steps? Does this happen in a Docker image that we can use to reproduce?

$ go1 version
go version go1.12.8 linux/amd64
$ GOARCH=ppc64le go1 env | grep CGO_ENABLED
CGO_ENABLED="0"

@mvdan
Copy link
Member

mvdan commented Aug 15, 2019

Also, as per https://go.googlesource.com/proposal/+/master/design/30411-env.md, do you have anything in your os.UserConfigDir()+"/go/env", or any go/env file anywhere else?

@smasher164
Copy link
Member

@mvdan Did you mean to ask if @bufflig exported CGO_ENABLED="1" at some point before running the command (since the go/env file only affects a build that uses 1.13)?

$ docker run -it golang:1.12.5-alpine
/go # go version
go version go1.12.5 linux/amd64
/go # GOARCH=ppc64le go env | grep CGO_ENABLED
CGO_ENABLED="0"
/go # export CGO_ENABLED="1"
/go # GOARCH=ppc64le go env | grep CGO_ENABLED
CGO_ENABLED="1"

@ianlancetaylor
Copy link
Contributor

As others have said, the intent since the beginning has been to default CGO_ENABLED to 0 for a cross-compilation. I don't know why you are seeing CGO_ENABLED default to 1 in your Go 1.12 installation. That is the bug.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed Soon This needs to be done soon. (regressions, serious bugs, outages) release-blocker labels Aug 19, 2019
@bcmills bcmills modified the milestones: Go1.13, Go1.12.10 Aug 19, 2019
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 19, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

10 participants