golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.29k stars 17.58k forks source link

cmd/go/internal/list: may fail if `-export -covermode=atomic` is used #68212

Open RomainMuller opened 3 months ago

RomainMuller commented 3 months ago

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
gabyhelp commented 3 months ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

RomainMuller commented 3 months ago

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:


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?

RomainMuller commented 3 months ago

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...

rsc commented 3 months ago

The fix in https://github.com/golang/go/commit/ac08c05d4daa11957fcada6db33f2150936bac27 looks simple enough to backport to me.

/cc @matloob @samthanawalla

matloob commented 3 months ago

Okay, created backport issues https://github.com/golang/go/issues/68221 and https://github.com/golang/go/issues/68222

gopherbot commented 3 months ago

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'

gopherbot commented 3 months ago

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'