]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.12] cmd/go: avoid link errors when -coverpkg covers main packages
authorJay Conrod <jayconrod@google.com>
Fri, 1 Mar 2019 22:20:28 +0000 (17:20 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 13 Mar 2019 19:48:23 +0000 (19:48 +0000)
commita40b76a40c024fb018045d1d2fd94f9e7b186a15
treeb2610f212b99e6119bb28f13b06ae6e92545c3b2
parent7e880151b1763ebe608d7c2cadf36b71f184332a
[release-branch.go1.12] cmd/go: avoid link errors when -coverpkg covers main packages

The -coverpkg lets users specify a list of packages that should have
coverage instrumentation. This may include packages not transitively
imported by tests. For each tested package, the synthetic main package
imports all covered packages so they can be registered with
testing.RegisterCover. This makes it possible for a main package to
import another main package.

When we compile a package with p.Internal.BuildInfo set (set on main
packages by Package.load in module mode), we set
runtime/debug.modinfo. Multiple main packages may be passed to the
linker because of the above scenario, so this causes duplicate symbol
errors.

This change copies p.Internal.BuildInfo to the synthetic main package
instead of the internal test package. Additionally, it forces main
packages imported by the synthetic test main package to be recompiled
for testing. Recompiled packages won't have p.Internal.BuildInfo set.

Fixes #30684

Change-Id: I06f028d55905039907940ec89d2835f5a1040203
Reviewed-on: https://go-review.googlesource.com/c/go/+/164877
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit 10156b678336f7628a7f1fdd84ffe2a28d66969a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/166318
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/go/internal/load/test.go
src/cmd/go/testdata/script/cover_pkgall_multiple_mains.txt [new file with mode: 0644]