aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-02-27 15:37:32 -0500
committerCherry Mui <cherryyz@google.com>2023-03-06 19:22:03 +0000
commit5987f3c2715d93cb52f05dcb1c29825507e1d625 (patch)
tree248ac05e7316add5a50ed0a5510ca6ed02075acd /src/cmd/go/internal/load/pkg.go
parent3eedba50b10ca9086646f12d7917912cff7d4d0a (diff)
downloadgo-5987f3c2715d93cb52f05dcb1c29825507e1d625.tar.gz
go-5987f3c2715d93cb52f05dcb1c29825507e1d625.zip
cmd/go: make PGO profile path per package
Currently, the PGO profile path is global for a single go command invocation, as it applies to all packages being built (or none). With -pgo=auto mode with multiple main packages, packages from a single go command invocation could have different profiles. So it is necessary that the PGO profile path is per package, which is this CL does. For #58099. Change-Id: I148a15970ec907272db85b4b27ad6b08c41d6c0c Reviewed-on: https://go-review.googlesource.com/c/go/+/472357 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 799f7de85e..cfb853e979 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -232,6 +232,7 @@ type PackageInternal struct {
TestmainGo *[]byte // content for _testmain.go
Embed map[string][]string // //go:embed comment mapping
OrigImportPath string // original import path before adding '_test' suffix
+ PGOProfile string // path to PGO profile
Asmflags []string // -asmflags for this package
Gcflags []string // -gcflags for this package
@@ -2385,11 +2386,11 @@ func (p *Package) setBuildInfo(autoVCS bool) {
appendSetting("-ldflags", ldflags)
}
}
- if cfg.BuildPGOFile != "" {
+ if p.Internal.PGOProfile != "" {
if cfg.BuildTrimpath {
- appendSetting("-pgo", filepath.Base(cfg.BuildPGOFile))
+ appendSetting("-pgo", filepath.Base(p.Internal.PGOProfile))
} else {
- appendSetting("-pgo", cfg.BuildPGOFile)
+ appendSetting("-pgo", p.Internal.PGOProfile)
}
}
if cfg.BuildMSan {
@@ -2894,7 +2895,7 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
return pkgs
}
-// setPGOProfilePath sets cfg.BuildPGOFile to the PGO profile path.
+// setPGOProfilePath sets the PGO profile path for pkgs.
// In -pgo=auto mode, it finds the default PGO profile.
func setPGOProfilePath(pkgs []*Package) {
switch cfg.BuildPGO {
@@ -2929,16 +2930,21 @@ func setPGOProfilePath(pkgs []*Package) {
}
file := filepath.Join(mainpkg.Dir, "default.pgo")
if fi, err := os.Stat(file); err == nil && !fi.IsDir() {
- cfg.BuildPGOFile = file
+ for _, p := range PackageList(pkgs) {
+ p.Internal.PGOProfile = file
+ }
}
default:
// Profile specified from the command line.
// Make it absolute path, as the compiler runs on various directories.
- if p, err := filepath.Abs(cfg.BuildPGO); err != nil {
+ file, err := filepath.Abs(cfg.BuildPGO)
+ if err != nil {
base.Fatalf("fail to get absolute path of PGO file %s: %v", cfg.BuildPGO, err)
- } else {
- cfg.BuildPGOFile = p
+ }
+
+ for _, p := range PackageList(pkgs) {
+ p.Internal.PGOProfile = file
}
}
}