aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/base
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2022-03-07 10:32:51 -0500
committerThan McIntosh <thanm@google.com>2022-09-27 10:30:53 +0000
commite6d9057e2f3442b133afe7e37bec72bb9b780b04 (patch)
tree15ac9b503567f7d7151238f8f9a62235c8d00794 /src/cmd/compile/internal/base
parent072c7d4969862c84430cc2daef20a8f7f3ba78a2 (diff)
downloadgo-e6d9057e2f3442b133afe7e37bec72bb9b780b04.tar.xz
cmd/compile: add coverage fixup mode
Adds a -coveragecfg=<configfile> command line option to the compiler to help support a cooperative "tool and compiler" mode for coverage instrumentation. In this mode the cmd/cover tool generates most of the counter instrumentation via source-to-source rewriting, but the compiler fixes up the result if passed the "-coveragecfg" option. The fixups include: - reclassifying counter variables (special storage class) - marking meta-data variables are read-only - adding in an init call to do registation Updates #51430. Change-Id: Iead72b85209725ee044542374465f118a3ee72e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/395895 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/base')
-rw-r--r--src/cmd/compile/internal/base/flag.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go
index a005d2cdf2..459ebf3ba4 100644
--- a/src/cmd/compile/internal/base/flag.go
+++ b/src/cmd/compile/internal/base/flag.go
@@ -9,6 +9,8 @@ import (
"flag"
"fmt"
"internal/buildcfg"
+ "internal/coverage"
+ "io/ioutil"
"log"
"os"
"reflect"
@@ -110,6 +112,7 @@ type CmdFlags struct {
MemProfileRate int "help:\"set runtime.MemProfileRate to `rate`\""
MutexProfile string "help:\"write mutex profile to `file`\""
NoLocalImports bool "help:\"reject local (relative) imports\""
+ CoverageCfg func(string) "help:\"read coverage configuration from `file`\""
Pack bool "help:\"write to file.a instead of file.o\""
Race bool "help:\"enable race detector\""
Shared *bool "help:\"generate code that can be linked into a shared library\"" // &Ctxt.Flag_shared, set below
@@ -127,10 +130,11 @@ type CmdFlags struct {
Patterns map[string][]string
Files map[string]string
}
- ImportDirs []string // appended to by -I
- ImportMap map[string]string // set by -importcfg
- PackageFile map[string]string // set by -importcfg; nil means not in use
- SpectreIndex bool // set by -spectre=index or -spectre=all
+ ImportDirs []string // appended to by -I
+ ImportMap map[string]string // set by -importcfg
+ PackageFile map[string]string // set by -importcfg; nil means not in use
+ CoverageInfo *coverage.CoverFixupConfig // set by -coveragecfg
+ SpectreIndex bool // set by -spectre=index or -spectre=all
// Whether we are adding any sort of code instrumentation, such as
// when the race detector is enabled.
Instrumenting bool
@@ -154,6 +158,7 @@ func ParseFlags() {
Flag.EmbedCfg = readEmbedCfg
Flag.GenDwarfInl = 2
Flag.ImportCfg = readImportCfg
+ Flag.CoverageCfg = readCoverageCfg
Flag.LinkShared = &Ctxt.Flag_linkshared
Flag.Shared = &Ctxt.Flag_shared
Flag.WB = true
@@ -430,6 +435,18 @@ func readImportCfg(file string) {
}
}
+func readCoverageCfg(file string) {
+ var cfg coverage.CoverFixupConfig
+ data, err := ioutil.ReadFile(file)
+ if err != nil {
+ log.Fatalf("-coveragecfg: %v", err)
+ }
+ if err := json.Unmarshal(data, &cfg); err != nil {
+ log.Fatalf("error reading -coveragecfg file %q: %v", file, err)
+ }
+ Flag.Cfg.CoverageInfo = &cfg
+}
+
func readEmbedCfg(file string) {
data, err := os.ReadFile(file)
if err != nil {