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

Open
bufflig opened this issue Aug 15, 2019 · 5 comments

Comments

@bufflig
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Aug 15, 2019

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 this to the Go1.13 milestone Aug 15, 2019

@mvdan

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

@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

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.