go version)?$ go version go version go1.13 darwin/amd64
Yes
go env)?go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rtoledo/Library/Caches/go-build"
GOENV="/Users/rtoledo/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rtoledo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5f/_qpgtfqn50v9076584zs6p6cns_ysz/T/go-build619092751=/tmp/go-build -gno-record-gcc-switches -fno-common"
go test ./... -coverpkg=./...
Tests running OK.
2019/09/05 11:57:31 duplicate symbol main.main (types 1 and 1) in main and /Users/rtoledo/Library/Caches/go-build/ee/ee28c25020a2b94486bc9068230305877cfb8f0f08d992d0c5a33faa6bdea84c-d(_go_.o)
This might be a regression for #32150. Sorry I cannot provide a working example, the bug is kinda esoteric to me and I cannot create a shareable project where this happens.
Edit: How to reproduce
https://github.com/golang/go/issues/34114#issuecomment-530146959
Also, it works without problem in 1.12.9
I am seeing this same issue with go 1.13 in darwin
I also see the same problem with go version go1.13 linux/amd64
We're also seeing this on go1.13 linux/amd64, though I can't get it to reproduce outside our build machine.
Deleting .cache/go-build had no effect, other than to change the error output to this -- I haven't been able to find who sets $WORK, but there are no _pkg_.a or _go_.o files on disk:
2019/09/10 10:00:49 duplicate symbol main.main (types 1 and 1) in main and $WORK/b318/_pkg_.a(_go_.o)
go env Output (from failing machine)
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/share/tomcat8/.cache/go-build"
GOENV="/usr/share/tomcat8/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/share/tomcat8/.jenkins/workspace/code-coverage"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/share/tomcat8/.jenkins/workspace/code-coverage/.build_env/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/share/tomcat8/.jenkins/workspace/code-coverage/.build_env/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches"
Don't know if it can help, but this problem appeared systematically in one repo with vendor/ directory and so built with -mod vendor + code coverage enabled. Converting it to go.mod (still with code coverage enabled) fixed the problem.
I'm seeing the same problem here (no problem with Go <= 1.12.x).
After the comment from @maxatome I made some tests on our private project.
Running go test ./... -coverprofile=coverage.out -coverpkg=./... -count=1 the results are:
dep as dependency management, having a vendor folder with dependencies. Tests fail with "duplicate symbol" error.go mod as dependency management, without vendor folder. Tests pass successfully.go mod with vendor folder (executing go mod vendor). Tests pass successfully.go mod with vendor folder. But setting GO111MODULE=off. Tests fail with "duplicate symbol" error.Didn't try replicating this behavior on an example repo, might try doing so in the following days if time permits.
I've managed to create a very small repo that reproduces the issue: https://github.com/emiguens/go-cover-fail.
After cloning the repo just run go test ./... -coverprofile=coverage.out -coverpkg=./... -count=1 and you'll see the following output:
$ go test ./... -coverprofile=coverage.out -coverpkg=./... -count=1
? github.com/emiguens/go-cover-fail [no test files]
# github.com/emiguens/go-cover-fail/pkg1.test
2019/09/10 19:27:09 duplicate symbol main.main (types 1 and 1) in main and /Users/emiguens/Library/Caches/go-build/24/24691ab861edac4f0767346c8d02eb886ed269874dacb9e5f27dc53368bb053c-d(_go_.o)
FAIL github.com/emiguens/go-cover-fail/pkg1 [build failed]
# github.com/emiguens/go-cover-fail/pkg2.test
2019/09/10 19:27:09 duplicate symbol main.main (types 1 and 1) in main and /Users/emiguens/Library/Caches/go-build/24/24691ab861edac4f0767346c8d02eb886ed269874dacb9e5f27dc53368bb053c-d(_go_.o)
FAIL github.com/emiguens/go-cover-fail/pkg2 [build failed]
FAIL
If I remove the main.go file and re-run the command, it executed correctly.
Another scenarios:
/vendor and Gopkg.* files, making the tests use dependencies from $GOPATH results in the same error.go vendor and executing the command with GO111MODULE=offresults in tests failing.All in all it seems to be something related with using a vendor folder with dependencies.
Hope this helps =D
@gopherbot please open a backport issue for Go 1.13, this looks like a possible regression without a workaround.
/cc @bcmills @jayconrod
Backport issue(s) opened: #34223 (for 1.13).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.
I've further reduced the test case, now it fails without having any external dependencies (only using the standard library). Just a main package with a subpackage with one function, so no vendor directory either.
After running go mod init (creates a go.mod file with no dependencies) tests run fine.
Just in case, you can see the commit history in the linked project to see how the test case evolved.
See previously #30374 and #32150.
This has the same root cause as #30907, but it affects packages built in GOPATH mode. Previously, I believed this bug only affected build info for modules, so the fix was pretty narrow. I'll send a CL that broadens the fix to cover this case.
Change https://golang.org/cl/195279 mentions this issue: cmd/go: fix link error for -coverpkg in GOPATH mode
Most helpful comment
I've managed to create a very small repo that reproduces the issue: https://github.com/emiguens/go-cover-fail.
After cloning the repo just run
go test ./... -coverprofile=coverage.out -coverpkg=./... -count=1and you'll see the following output:If I remove the
main.gofile and re-run the command, it executed correctly.Another scenarios:
/vendorandGopkg.*files, making the tests use dependencies from$GOPATHresults in the same error.go vendorand executing the command withGO111MODULE=offresults in tests failing.All in all it seems to be something related with using a
vendorfolder with dependencies.Hope this helps =D