Skip to content

Commit 085c609

Browse files
committed
cmd/go: fix go command fails to perform concurrent compilation
CL 344909 fixed the bug in the order of passing gcflags from cmd/go to cmd/compile. In that process, we merged the flags passed by cmd/go and the flags specified by "-gcflags" to one variable. That causes the gcBackendConcurrency function fails to detect concurrency level, since when it expects only the latter flags. To fix this, just don't merge those two variables, so we can now correctly detect the concurrency level and passing the right -c to the compiler. Fixes #48490 Change-Id: I1293a7d6b946b7fccdd5cd34a38452bf6306e115 Reviewed-on: https://go-review.googlesource.com/c/go/+/351049 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 3664950 commit 085c609

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/cmd/go/internal/work/gc.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
7575
}
7676

7777
pkgpath := pkgPath(a)
78-
gcflags := []string{"-p", pkgpath}
78+
defaultGcFlags := []string{"-p", pkgpath}
7979
if p.Module != nil {
8080
v := p.Module.GoVersion
8181
if v == "" {
@@ -94,19 +94,19 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
9494
v = "1.16"
9595
}
9696
if allowedVersion(v) {
97-
gcflags = append(gcflags, "-lang=go"+v)
97+
defaultGcFlags = append(defaultGcFlags, "-lang=go"+v)
9898
}
9999
}
100100
if p.Standard {
101-
gcflags = append(gcflags, "-std")
101+
defaultGcFlags = append(defaultGcFlags, "-std")
102102
}
103103
_, compilingRuntime := runtimePackages[p.ImportPath]
104104
compilingRuntime = compilingRuntime && p.Standard
105105
if compilingRuntime {
106106
// runtime compiles with a special gc flag to check for
107107
// memory allocations that are invalid in the runtime package,
108108
// and to implement some special compiler pragmas.
109-
gcflags = append(gcflags, "-+")
109+
defaultGcFlags = append(defaultGcFlags, "-+")
110110
}
111111

112112
// If we're giving the compiler the entire package (no C etc files), tell it that,
@@ -125,25 +125,25 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
125125
}
126126
}
127127
if extFiles == 0 {
128-
gcflags = append(gcflags, "-complete")
128+
defaultGcFlags = append(defaultGcFlags, "-complete")
129129
}
130130
if cfg.BuildContext.InstallSuffix != "" {
131-
gcflags = append(gcflags, "-installsuffix", cfg.BuildContext.InstallSuffix)
131+
defaultGcFlags = append(defaultGcFlags, "-installsuffix", cfg.BuildContext.InstallSuffix)
132132
}
133133
if a.buildID != "" {
134-
gcflags = append(gcflags, "-buildid", a.buildID)
134+
defaultGcFlags = append(defaultGcFlags, "-buildid", a.buildID)
135135
}
136136
if p.Internal.OmitDebug || cfg.Goos == "plan9" || cfg.Goarch == "wasm" {
137-
gcflags = append(gcflags, "-dwarf=false")
137+
defaultGcFlags = append(defaultGcFlags, "-dwarf=false")
138138
}
139139
if strings.HasPrefix(runtimeVersion, "go1") && !strings.Contains(os.Args[0], "go_bootstrap") {
140-
gcflags = append(gcflags, "-goversion", runtimeVersion)
140+
defaultGcFlags = append(defaultGcFlags, "-goversion", runtimeVersion)
141141
}
142142
if symabis != "" {
143-
gcflags = append(gcflags, "-symabis", symabis)
143+
defaultGcFlags = append(defaultGcFlags, "-symabis", symabis)
144144
}
145145

146-
gcflags = append(gcflags, str.StringList(forcedGcflags, p.Internal.Gcflags)...)
146+
gcflags := str.StringList(forcedGcflags, p.Internal.Gcflags)
147147
if compilingRuntime {
148148
// Remove -N, if present.
149149
// It is not possible to build the runtime with no optimizations,
@@ -157,7 +157,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
157157
}
158158
}
159159

160-
args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), gcflags}
160+
args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), defaultGcFlags, gcflags}
161161
if p.Internal.LocalPrefix != "" {
162162
// Workaround #43883.
163163
args = append(args, "-D", p.Internal.LocalPrefix)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tests golang.org/issue/48490
2+
# cmd/go should enable concurrent compilation by default
3+
4+
# Skip test on darwin/arm64, see #48496.
5+
# TODO(cuonglm): remove this once #48496 is fixed.
6+
[darwin] [arm64] skip
7+
8+
# Reset all experiments, since one of them can disable
9+
# concurrent compilation, e.g: fieldtrack.
10+
env GOEXPERIMENT=none
11+
12+
env GOMAXPROCS=4
13+
go build -n -x -a fmt
14+
stderr ' -c=4 '

0 commit comments

Comments
 (0)