Skip to content

cmd/go: env -changed misses CGO_LDFLAGS, others #69994

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

Open
rliebz opened this issue Oct 23, 2024 · 8 comments
Open

cmd/go: env -changed misses CGO_LDFLAGS, others #69994

rliebz opened this issue Oct 23, 2024 · 8 comments
Assignees
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rliebz
Copy link

rliebz commented Oct 23, 2024

Go version

go version go1.23.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/rob/Library/Caches/go-build'
GOENV='/Users/rob/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rob/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/rob/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/rob/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-w'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ry/6bttgkt51f14fhb1cwsg_6r00000gp/T/go-build1178049255=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Change the default value of CGO_LDFLAGS:

go env -w CGO_LDFLAGS=-w

Then check what values have changed:

go env -changed

What did you see happen?

No output

What did you expect to see?

I expected the output to be:

CGO_LDFLAGS='-w'

When most env variables are overridden in this way, they correctly show up in the output. Since CGO_LDFLAGS is one of the values that shows up in the output of go env without any flags, I would also expect it to be reflected with go env -changed when the value was non-default.

I have tested this with a few other cases and found inconsistent results, including:

  • Some flags like CGO_ENABLED, GOPATH, GOPRIVATE, and CGO_CFLAGS are respected
  • Other flags like CGO_LDFLAGS and GCCGO are not respected. It might literally be just these two, but I only tested a handful
  • go env -changed does not seem to report a value if the corresponding environment variable is exported. To reproduce:
$ go env -w CGO_ENABLED=0
$ go env -changed
CGO_ENABLED='0'
$ CGO_ENABLED=0 go env -changed
$ CGO_ENABLED=2 go env -changed

I could not find anything in the original proposal (#34208) or in the docs (go help env) that would suggest why this would be the expected behavior.

@qiulaidongfeng
Copy link
Member

Thanks report.
I will investigate.

@seankhliao seankhliao changed the title go env -changed misses CGO_LDFLAGS, others cmd/go: env -changed misses CGO_LDFLAGS, others Oct 23, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621995 mentions this issue: cmd/go: fix incorrect determining default value of CGO_ENABLED

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621996 mentions this issue: cmd/go: fix typo in ExtraEnvVarsCostly

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621997 mentions this issue: cmd/go: fix GOCACHE error print non-default value when env set to default value

@qiulaidongfeng
Copy link
Member

Thanks again for your report, I rechecked the implementation.
Three newly discovered bug have been sent CL fix.
old bug(#67492) fix in https://go.dev/cl/586241

@cagedmantis cagedmantis added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 28, 2024
@cagedmantis cagedmantis added this to the Go1.24 milestone Oct 28, 2024
@cagedmantis
Copy link
Contributor

cc @matloob @samthanawalla

gopherbot pushed a commit that referenced this issue Nov 5, 2024
For #69994

Change-Id: I7db39074f6a055efb29c1cbd0db4c286864a5da6
Reviewed-on: https://go-review.googlesource.com/c/go/+/621996
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: bcd a <[email protected]>
Reviewed-by: Sam Thanawalla <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Auto-Submit: Sam Thanawalla <[email protected]>
@matloob matloob assigned matloob and qiulaidongfeng and unassigned matloob Nov 12, 2024
@gopherbot gopherbot modified the milestones: Go1.24, Go1.25 Feb 11, 2025
gopherbot pushed a commit that referenced this issue Apr 9, 2025
When other environment variables are set to default values,
we will not print it in go env -changed,
GOCACHE should do the same.

For #69994

Change-Id: I16661803cf1f56dd132b4db1c2d5cb4823fc0e58
Reviewed-on: https://go-review.googlesource.com/c/go/+/621997
Reviewed-by: Sean Liao <[email protected]>
Auto-Submit: Sean Liao <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
gopherbot pushed a commit that referenced this issue May 8, 2025
The default value is the value obtained when
no environment variables are set and go env  -w is not used.

In the past,
we used the current value
(may be modified by an environment variable to a non-default value),
error was used as the default value.

For #69994

Change-Id: Iead3a6cacd04dc51a094ffb9f7bb7553320fcd78
Reviewed-on: https://go-review.googlesource.com/c/go/+/621995
Reviewed-by: Michael Matloob <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/671635 mentions this issue: cmd/go: fix not print GCCGO when it's not the default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go 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

6 participants