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 <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-10-14 08:06:54 -04:00
parent ab541a0560
commit 4d1cecdee8
4 changed files with 61 additions and 19 deletions

View file

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

View file

@ -52,7 +52,6 @@ func main() {
case "all", "ret": case "all", "ret":
ctxt.Retpoline = true ctxt.Retpoline = true
} }
compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
ctxt.Bso = bufio.NewWriter(os.Stdout) ctxt.Bso = bufio.NewWriter(os.Stdout)
defer ctxt.Bso.Flush() defer ctxt.Bso.Flush()
@ -75,7 +74,8 @@ func main() {
var failedFile string var failedFile string
for _, f := range flag.Args() { for _, f := range flag.Args() {
lexer := lex.NewLexer(f) lexer := lex.NewLexer(f)
parser := asm.NewParser(ctxt, architecture, lexer, compilingRuntime) parser := asm.NewParser(ctxt, architecture, lexer,
*flags.CompilingRuntime)
ctxt.DiagFunc = func(format string, args ...interface{}) { ctxt.DiagFunc = func(format string, args ...interface{}) {
diag = true diag = true
log.Printf(format, args...) log.Printf(format, args...)

35
src/cmd/dist/build.go vendored
View file

@ -832,6 +832,21 @@ func runInstall(pkg string, ch chan struct{}) {
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64) asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64)
} }
goasmh := pathf("%s/go_asm.h", workdir) goasmh := pathf("%s/go_asm.h", workdir)
if IsRuntimePackagePath(pkg) {
asmArgs = append(asmArgs, "-compilingRuntime")
if os.Getenv("GOEXPERIMENT") == "regabi" {
// In order to make it easier to port runtime assembly
// to the register ABI, we introduce a macro
// indicating the experiment is enabled.
//
// Note: a similar change also appears in
// cmd/go/internal/work/gc.go.
//
// TODO(austin): Remove this once we commit to the
// register ABI (#40724).
asmArgs = append(asmArgs, "-D=GOEXPERIMENT_REGABI=1")
}
}
// Collect symabis from assembly code. // Collect symabis from assembly code.
var symabis string var symabis string
@ -1733,3 +1748,23 @@ func cmdlist() {
fatalf("write failed: %v", err) fatalf("write failed: %v", err)
} }
} }
// IsRuntimePackagePath examines 'pkgpath' and returns TRUE if it
// belongs to the collection of "runtime-related" packages, including
// "runtime" itself, "reflect", "syscall", and the
// "runtime/internal/*" packages. See also the function of the same
// name in cmd/internal/objabi/path.go.
func IsRuntimePackagePath(pkgpath string) bool {
rval := false
switch pkgpath {
case "runtime":
rval = true
case "reflect":
rval = true
case "syscall":
rval = true
default:
rval = strings.HasPrefix(pkgpath, "runtime/internal")
}
return rval
}

View file

@ -292,14 +292,20 @@ func asmArgs(a *Action, p *load.Package) []interface{} {
} }
} }
} }
if p.ImportPath == "runtime" && objabi.Regabi_enabled != 0 { if objabi.IsRuntimePackagePath(pkgpath) {
// In order to make it easier to port runtime assembly args = append(args, "-compilingRuntime")
// to the register ABI, we introduce a macro if objabi.Regabi_enabled != 0 {
// indicating the experiment is enabled. // In order to make it easier to port runtime assembly
// // to the register ABI, we introduce a macro
// TODO(austin): Remove this once we commit to the // indicating the experiment is enabled.
// register ABI (#40724). //
args = append(args, "-D=GOEXPERIMENT_REGABI=1") // Note: a similar change also appears in
// cmd/dist/build.go.
//
// TODO(austin): Remove this once we commit to the
// register ABI (#40724).
args = append(args, "-D=GOEXPERIMENT_REGABI=1")
}
} }
if cfg.Goarch == "mips" || cfg.Goarch == "mipsle" { if cfg.Goarch == "mips" || cfg.Goarch == "mipsle" {