cmd/go/internal/list: may fail if `-export -covermode=atomic` is used
Go version
go version go1.22.4 darwin/arm64
Output of go env in your module/workspace:
GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/romain.marcadier/Library/Caches/go-build'
GOENV='/Users/romain.marcadier/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/romain.marcadier/go/pkg/mod'
GONOPROXY='github.com/DataDog'
GONOSUMDB='github.com/DataDog,go.ddbuild.io'
GOOS='darwin'
GOPATH='/Users/romain.marcadier/go'
GOPRIVATE='github.com/DataDog'
GOPROXY='binaries.ddbuild.io,proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/romain.marcadier/Development/Datadog/orchestrion/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/qh/q2mpbd0j6xsb7vc8dqzdm81h0000gn/T/go-build3755867500=/tmp/go-build -gno-record-gcc-switches -fno-common'
What did you do?
Trying to use go list to obtain the exports for a given package and its dependencies; possibly built with coverage instrumentation... Use a command similar to the following (io being a standard library package that runs into the issue, but this happens with virtually any other package that does not "already" depend on sync/atomic):
$ go list -cover -covermode=atomic -coverpkg=io -deps -export -json io
What did you see happen?
Removed -deps and -json arguments as they are largely irrelevant to the issue; but basically:
$ go list -cover -covermode=atomic -coverpkg=io -export io
# io
/opt/homebrew/Cellar/go/1.22.4/libexec/src/io/io.go:13:35: could not import sync/atomic (open : no such file or directory)
io
$ echo $?
1
What did you expect to see?
I'd have expected compilation to succeed and exports to be returned (the go build equivalent command is successful):
$ go list -cover -covermode=atomic -coverpkg=io -deps -export -json io
io
$ echo $?
0
Related Issues
- cmd/go: list with -export and -covermode=atomic fails to build #65264 (closed)
- cmd/go: test -coverpkg: compilation error when file only contains interface definitions #61709 (closed)
- x/tools/go/packages: Load returned packages with errors when specifying GOOS #36547
- cmd/compile: using non-exported generic type causes internal compiler error #48337 (closed)
- cmd/{go,cover}: errors on 'go test -covermode=atomic sync/atomic' #57445 (closed)
- x/tools/go/gcexportdata: can't import package from pkg/mod #52269
- cmd/go: test with coverage unexpect fail #43242 (closed)
- cmd/go: TestScript/cover_sync_atomic_import failures #66528 (closed)
- go/cmd: all.bash broken by an issue with modules #26825 (closed)
- cmd/compile/internal/types2: TestSelf fails if a built pkg/.../syntax.a doesn't exist #56573 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
I'm observing this issue with all go releases tested so far (1.21, 1.22, 1.23-rc), and expect it is present on older releases, too.
Investigations so far (superficially) suggest that:
-
go buildwould update the-importcfgfile passed to thecompilecommand to includesync/atomicwhen building with-covermode=atomic -
go liston the other hand fails to do this, resulting in it failing to produce exports for packages that don't depend onsync/atomicbefore they're instrumented.
This is the same as https://github.com/golang/go/issues/65264, which has been closed/resolved on Feb 1st, so I was expecting the fix to be released already?
Oh my bad, it's fixed in 1.23.0-rc.1 apparently (my tests are failing for another reason).
I'm okay with this being closed; however I'd like to understand if there is any plan to back-port this fix to 1.21 and/or 1.22...
The fix in https://github.com/golang/go/commit/ac08c05d4daa11957fcada6db33f2150936bac27 looks simple enough to backport to me.
/cc @matloob @samthanawalla
Okay, created backport issues https://github.com/golang/go/issues/68221 and https://github.com/golang/go/issues/68222
Change https://go.dev/cl/595496 mentions this issue: [release-branch.go1.22] cmd/go: fix build config before creating actions for 'go list -cover'
Change https://go.dev/cl/595495 mentions this issue: [release-branch.go1.21] cmd/go: fix build config before creating actions for 'go list -cover'