From 9ce601df6a8292f763b07994680013facd7b4a63 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 23 Sep 2021 23:40:58 +0700 Subject: [PATCH] cmd/go: move gc concurrency level computation near gcflags So after constructing "args" variable, "gcflags" is not used anywhere. It makes the code easier to maintain, and prevent subtle bug like #48490. Change-Id: I41653536480880a8a6f9fbf6cfa8a461b6fb3208 Reviewed-on: https://go-review.googlesource.com/c/go/+/351849 Reviewed-by: Bryan C. Mills Reviewed-by: Jay Conrod Reviewed-by: Russ Cox Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Trust: Cuong Manh Le --- src/cmd/go/internal/work/gc.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index 4e4a1d84514..fe0a45ec2a4 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -156,6 +156,10 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg } } } + // Add -c=N to use concurrent backend compilation, if possible. + if c := gcBackendConcurrency(gcflags); c > 1 { + gcflags = append(gcflags, fmt.Sprintf("-c=%d", c)) + } args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), defaultGcFlags, gcflags} if p.Internal.LocalPrefix != "" { @@ -181,11 +185,6 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg args = append(args, "-asmhdr", objdir+"go_asm.h") } - // Add -c=N to use concurrent backend compilation, if possible. - if c := gcBackendConcurrency(gcflags); c > 1 { - args = append(args, fmt.Sprintf("-c=%d", c)) - } - for _, f := range gofiles { f := mkAbs(p.Dir, f)