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: go list prints unexpected compiler output for non-stale targets #56375

Closed
bcmills opened this issue Oct 21, 2022 · 3 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2022

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

~/x/tools$ gotip version
go version devel go1.20-867babe1b1 Fri Oct 21 16:23:01 2022 +0000 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
~/x/tools$ gotip env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/bcmills/.cache/go-build"
GOENV="/usr/local/google/home/bcmills/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/google/home/bcmills/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/google/home/bcmills"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/bcmills/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-867babe1b1 Fri Oct 21 16:23:01 2022 +0000"
GCCGO="/usr/local/google/home/bcmills/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/usr/local/google/home/bcmills/x/tools/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3491113060=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Use go install to build a binary in a way that produces output to stdout or stderr, then go list -json=Stale to verify that that binary is not, in fact, stale.

What did you expect to see?

Compiler output from go install and go build, and no compiler output from go list (unless, perhaps, the -export or -compiled flag is set).

What did you see instead?

The go list command, with neither -export nor -compiled repeats all of the stdout / stderr output from the compiler for the go install command, even though it should have no possibility of actually running the compiler!

~/x/tools$ gotip install -gcflags=-m ./cmd/goyacc
# golang.org/x/tools/cmd/goyacc
cmd/goyacc/yacc.go:138:6: can inline ASSOC
cmd/goyacc/yacc.go:140:6: can inline PLEVEL
cmd/goyacc/yacc.go:142:6: can inline TYPE
cmd/goyacc/yacc.go:145:6: can inline SETASC
cmd/goyacc/yacc.go:147:6: can inline SETPLEV
cmd/goyacc/yacc.go:149:6: can inline SETTYPE
cmd/goyacc/yacc.go:166:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:167:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:168:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:169:14: inlining call to flag.BoolVar
…

~/x/tools$ gotip list -gcflags=-m -json=Stale ./cmd/goyacc
# golang.org/x/tools/cmd/goyacc
cmd/goyacc/yacc.go:138:6: can inline ASSOC
cmd/goyacc/yacc.go:140:6: can inline PLEVEL
cmd/goyacc/yacc.go:142:6: can inline TYPE
cmd/goyacc/yacc.go:145:6: can inline SETASC
cmd/goyacc/yacc.go:147:6: can inline SETPLEV
cmd/goyacc/yacc.go:149:6: can inline SETTYPE
cmd/goyacc/yacc.go:166:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:167:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:168:16: inlining call to flag.StringVar
cmd/goyacc/yacc.go:169:14: inlining call to flag.BoolVar
…
{}

I noticed this existing bug while reviewing CL 444619 (CC @matloob)

@bcmills bcmills added the GoCommand cmd/go label Oct 21, 2022
@bcmills
Copy link
Contributor Author

bcmills commented Oct 21, 2022

This bug was likely introduced in CL 128903, which fixed #23877.

@bcmills bcmills added this to the Backlog milestone Oct 21, 2022
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 21, 2022
@bcmills
Copy link
Contributor Author

bcmills commented Oct 21, 2022

The condition that controls whether we would actually run the compiler appears to be here:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/work/exec.go;l=476-479;drc=01604129aee8bfc9dd3e2fffd2ad8f772a3089ec

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/444836 mentions this issue: cmd/go: don't print cached output for non-build list commands

romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
If a user is running a go list command that wouldn't trigger a build
(for example if -export was passed), don't print the cached stdout
outputs for previous builds of the artifacts.

Fixes golang#56375

Change-Id: I1d3e6c01d0eb3dada941bb2783ce2ac69aa3d5d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/444836
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
@golang golang locked and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

2 participants