]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist,cmd/go: broaden use of asm macro GOEXPERIMENT_REGABI
authorThan McIntosh <thanm@google.com>
Wed, 14 Oct 2020 12:06:54 +0000 (08:06 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 19 Oct 2020 19:27:54 +0000 (19:27 +0000)
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>
src/cmd/asm/internal/flags/flags.go
src/cmd/asm/main.go
src/cmd/dist/build.go
src/cmd/go/internal/work/gc.go

index 64024cc97db052f209e7258c435866642049df5a..076543995919588673ac6b7bac21eb731113f9a3 100644 (file)
@@ -15,15 +15,16 @@ import (
 )
 
 var (
-       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")
-       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")
-       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")
-       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")
-       Spectre    = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
+       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")
+       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")
+       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")
+       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")
+       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 (
index 01c963ac729f89737e938b5b921a4f0bc9e947c1..149925d23f184f7f0832ba89b831977c46cd0a88 100644 (file)
@@ -52,7 +52,6 @@ func main() {
        case "all", "ret":
                ctxt.Retpoline = true
        }
-       compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
 
        ctxt.Bso = bufio.NewWriter(os.Stdout)
        defer ctxt.Bso.Flush()
@@ -75,7 +74,8 @@ func main() {
        var failedFile string
        for _, f := range flag.Args() {
                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{}) {
                        diag = true
                        log.Printf(format, args...)
index 398ed6bce1158d0a9d7c2593715706199b6dca52..11da38ebdf8e123c6519e557699724394f0611fd 100644 (file)
@@ -832,6 +832,21 @@ func runInstall(pkg string, ch chan struct{}) {
                asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64)
        }
        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.
        var symabis string
@@ -1733,3 +1748,23 @@ func cmdlist() {
                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
+}
index 56ad1872be458e22d15144933a26ec9ea13c0eec..2df4a52ba594f2d804e8be4d9e79421d26d9f17c 100644 (file)
@@ -292,14 +292,20 @@ func asmArgs(a *Action, p *load.Package) []interface{} {
                        }
                }
        }
-       if p.ImportPath == "runtime" && objabi.Regabi_enabled != 0 {
-               // In order to make it easier to port runtime assembly
-               // to the register ABI, we introduce a macro
-               // indicating the experiment is enabled.
-               //
-               // TODO(austin): Remove this once we commit to the
-               // register ABI (#40724).
-               args = append(args, "-D=GOEXPERIMENT_REGABI=1")
+       if objabi.IsRuntimePackagePath(pkgpath) {
+               args = append(args, "-compilingRuntime")
+               if objabi.Regabi_enabled != 0 {
+                       // 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/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" {