Skip to content

Commit 4d1cecd

Browse files
committed
cmd/dist,cmd/go: broaden use of asm macro GOEXPERIMENT_REGABI
This extends a change made in https://golang.org/cl/252258 to the go command (to define an asm macro when GOEXPERIMENT=regabi is in effect); we need this same macro during the bootstrap build in order to build the runtime correctly. In addition, expand the set of packages where the macro is applied to {runtime, reflect, syscall, runtime/internal/*}, and move the logic for deciding when something is a "runtime package" out of the assembler and into cmd/{go,dist}, introducing a new assembler command line flag instead. Updates #27539, #40724. Change-Id: Ifcc7f029f56873584de1e543c55b0d3e54ad6c49 Reviewed-on: https://go-review.googlesource.com/c/go/+/262317 Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent ab541a0 commit 4d1cecd

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

src/cmd/asm/internal/flags/flags.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import (
1515
)
1616

1717
var (
18-
Debug = flag.Bool("debug", false, "dump instructions as they are parsed")
19-
OutputFile = flag.String("o", "", "output file; default foo.o for /a/b/c/foo.s as first argument")
20-
TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths")
21-
Shared = flag.Bool("shared", false, "generate code that can be linked into a shared library")
22-
Dynlink = flag.Bool("dynlink", false, "support references to Go symbols defined in other shared libraries")
23-
AllErrors = flag.Bool("e", false, "no limit on number of errors reported")
24-
SymABIs = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble")
25-
Importpath = flag.String("p", "", "set expected package import to path")
26-
Spectre = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
18+
Debug = flag.Bool("debug", false, "dump instructions as they are parsed")
19+
OutputFile = flag.String("o", "", "output file; default foo.o for /a/b/c/foo.s as first argument")
20+
TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths")
21+
Shared = flag.Bool("shared", false, "generate code that can be linked into a shared library")
22+
Dynlink = flag.Bool("dynlink", false, "support references to Go symbols defined in other shared libraries")
23+
AllErrors = flag.Bool("e", false, "no limit on number of errors reported")
24+
SymABIs = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble")
25+
Importpath = flag.String("p", "", "set expected package import to path")
26+
Spectre = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
27+
CompilingRuntime = flag.Bool("compilingRuntime", false, "source to be compiled is part of the Go runtime")
2728
)
2829

2930
var (

src/cmd/asm/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func main() {
5252
case "all", "ret":
5353
ctxt.Retpoline = true
5454
}
55-
compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
5655

5756
ctxt.Bso = bufio.NewWriter(os.Stdout)
5857
defer ctxt.Bso.Flush()
@@ -75,7 +74,8 @@ func main() {
7574
var failedFile string
7675
for _, f := range flag.Args() {
7776
lexer := lex.NewLexer(f)
78-
parser := asm.NewParser(ctxt, architecture, lexer, compilingRuntime)
77+
parser := asm.NewParser(ctxt, architecture, lexer,
78+
*flags.CompilingRuntime)
7979
ctxt.DiagFunc = func(format string, args ...interface{}) {
8080
diag = true
8181
log.Printf(format, args...)

src/cmd/dist/build.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,21 @@ func runInstall(pkg string, ch chan struct{}) {
832832
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64)
833833
}
834834
goasmh := pathf("%s/go_asm.h", workdir)
835+
if IsRuntimePackagePath(pkg) {
836+
asmArgs = append(asmArgs, "-compilingRuntime")
837+
if os.Getenv("GOEXPERIMENT") == "regabi" {
838+
// In order to make it easier to port runtime assembly
839+
// to the register ABI, we introduce a macro
840+
// indicating the experiment is enabled.
841+
//
842+
// Note: a similar change also appears in
843+
// cmd/go/internal/work/gc.go.
844+
//
845+
// TODO(austin): Remove this once we commit to the
846+
// register ABI (#40724).
847+
asmArgs = append(asmArgs, "-D=GOEXPERIMENT_REGABI=1")
848+
}
849+
}
835850

836851
// Collect symabis from assembly code.
837852
var symabis string
@@ -1733,3 +1748,23 @@ func cmdlist() {
17331748
fatalf("write failed: %v", err)
17341749
}
17351750
}
1751+
1752+
// IsRuntimePackagePath examines 'pkgpath' and returns TRUE if it
1753+
// belongs to the collection of "runtime-related" packages, including
1754+
// "runtime" itself, "reflect", "syscall", and the
1755+
// "runtime/internal/*" packages. See also the function of the same
1756+
// name in cmd/internal/objabi/path.go.
1757+
func IsRuntimePackagePath(pkgpath string) bool {
1758+
rval := false
1759+
switch pkgpath {
1760+
case "runtime":
1761+
rval = true
1762+
case "reflect":
1763+
rval = true
1764+
case "syscall":
1765+
rval = true
1766+
default:
1767+
rval = strings.HasPrefix(pkgpath, "runtime/internal")
1768+
}
1769+
return rval
1770+
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,20 @@ func asmArgs(a *Action, p *load.Package) []interface{} {
292292
}
293293
}
294294
}
295-
if p.ImportPath == "runtime" && objabi.Regabi_enabled != 0 {
296-
// In order to make it easier to port runtime assembly
297-
// to the register ABI, we introduce a macro
298-
// indicating the experiment is enabled.
299-
//
300-
// TODO(austin): Remove this once we commit to the
301-
// register ABI (#40724).
302-
args = append(args, "-D=GOEXPERIMENT_REGABI=1")
295+
if objabi.IsRuntimePackagePath(pkgpath) {
296+
args = append(args, "-compilingRuntime")
297+
if objabi.Regabi_enabled != 0 {
298+
// In order to make it easier to port runtime assembly
299+
// to the register ABI, we introduce a macro
300+
// indicating the experiment is enabled.
301+
//
302+
// Note: a similar change also appears in
303+
// cmd/dist/build.go.
304+
//
305+
// TODO(austin): Remove this once we commit to the
306+
// register ABI (#40724).
307+
args = append(args, "-D=GOEXPERIMENT_REGABI=1")
308+
}
303309
}
304310

305311
if cfg.Goarch == "mips" || cfg.Goarch == "mipsle" {

0 commit comments

Comments
 (0)