]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm,cmd/dist,cmd/go: remove asm -compiling-runtime flag
authorAustin Clements <austin@google.com>
Fri, 30 Jun 2023 20:33:49 +0000 (16:33 -0400)
committerAustin Clements <austin@google.com>
Tue, 22 Aug 2023 19:18:23 +0000 (19:18 +0000)
Currently, dist and go pass a -compiling-runtime flag to asm if
they're compiling a runtime package. However, now that we always pass
the package path to asm, it can make that determination just as well
as its callers can. This CL moves that check into asm and drops the
flag.

This in turn makes dist's copy of IsRuntimePackagePath unnecessary, so
we delete it.

Change-Id: I6ecf2d50b5b83965012af34dbe5f9a973ba0778b
Reviewed-on: https://go-review.googlesource.com/c/go/+/521697
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/internal/flags/flags.go
src/cmd/asm/internal/lex/input.go
src/cmd/asm/internal/lex/lex.go
src/cmd/asm/internal/lex/lex_test.go
src/cmd/asm/main.go
src/cmd/dist/build.go
src/cmd/go/internal/work/gc.go
src/cmd/internal/objabi/path.go

index 1ec9ebd5b512d4231359822c735ebae140ba3909..694312170a57c091b641c48eaea1cd741eb30cc0 100644 (file)
@@ -29,7 +29,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
        input := filepath.Join("testdata", file+".s")
        architecture, ctxt := setArch(goarch)
        architecture.Init(ctxt)
-       lexer := lex.NewLexer(input)
+       lexer := lex.NewLexer(input, false)
        parser := NewParser(ctxt, architecture, lexer, false)
        pList := new(obj.Plist)
        var ok bool
@@ -278,7 +278,7 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
        input := filepath.Join("testdata", file+".s")
        architecture, ctxt := setArch(goarch)
        architecture.Init(ctxt)
-       lexer := lex.NewLexer(input)
+       lexer := lex.NewLexer(input, false)
        parser := NewParser(ctxt, architecture, lexer, false)
        pList := new(obj.Plist)
        var ok bool
index b9a94a0c092541c1677aa8aedcfe0f42e6874e63..e15a062749fab5351ce4e85e5f041ac566417702 100644 (file)
@@ -16,17 +16,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")
-       Linkshared       = flag.Bool("linkshared", false, "generate code that will be linked against Go 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", obj.UnlinkablePkg, "set expected package import to path")
-       Spectre          = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
-       CompilingRuntime = flag.Bool("compiling-runtime", false, "source to be compiled is part of the Go runtime")
+       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")
+       Linkshared = flag.Bool("linkshared", false, "generate code that will be linked against Go 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", obj.UnlinkablePkg, "set expected package import to path")
+       Spectre    = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
 )
 
 var DebugFlags struct {
index 276b4b0dcd6cd1accf0b1f2e626fe0cefc0b9b50..3034377793fb45c3bbac7ed92c3c5e493f319daf 100644 (file)
@@ -34,22 +34,22 @@ type Input struct {
 }
 
 // NewInput returns an Input from the given path.
-func NewInput(name string) *Input {
+func NewInput(name string, compilingRuntime bool) *Input {
        return &Input{
                // include directories: look in source dir, then -I directories.
                includes:        append([]string{filepath.Dir(name)}, flags.I...),
                beginningOfLine: true,
-               macros:          predefine(flags.D),
+               macros:          predefine(flags.D, compilingRuntime),
        }
 }
 
 // predefine installs the macros set by the -D flag on the command line.
-func predefine(defines flags.MultiFlag) map[string]*Macro {
+func predefine(defines flags.MultiFlag, compilingRuntime bool) map[string]*Macro {
        macros := make(map[string]*Macro)
 
        // Set macros for GOEXPERIMENTs so we can easily switch
        // runtime assembly code based on them.
-       if *flags.CompilingRuntime {
+       if compilingRuntime {
                for _, exp := range buildcfg.Experiment.Enabled() {
                        // Define macro.
                        name := "GOEXPERIMENT_" + exp
index 7cd41a55a9b33c0453962e147b9c8ee8371ff004..15a3c67d855091695f74ebf2b00ab7f98c972c5d 100644 (file)
@@ -60,8 +60,8 @@ func (t ScanToken) String() string {
 }
 
 // NewLexer returns a lexer for the named file and the given link context.
-func NewLexer(name string) TokenReader {
-       input := NewInput(name)
+func NewLexer(name string, compilingRuntime bool) TokenReader {
+       input := NewInput(name, compilingRuntime)
        fd, err := os.Open(name)
        if err != nil {
                log.Fatalf("%s\n", err)
index e8dcf4b22f1218dc3e403d3271ba22945a447e87..a1c4974f64fa671eb662c17789c47e3be6357a45 100644 (file)
@@ -258,7 +258,7 @@ var lexTests = []lexTest{
 
 func TestLex(t *testing.T) {
        for _, test := range lexTests {
-               input := NewInput(test.name)
+               input := NewInput(test.name, false)
                input.Push(NewTokenizer(test.name, strings.NewReader(test.input), nil))
                result := drain(input)
                if result != test.output {
@@ -328,7 +328,7 @@ var badLexTests = []badLexTest{
 
 func TestBadLex(t *testing.T) {
        for _, test := range badLexTests {
-               input := NewInput(test.error)
+               input := NewInput(test.error, false)
                input.Push(NewTokenizer(test.error, strings.NewReader(test.input), nil))
                err := firstError(input)
                if err == nil {
index 6a25fd426b7de050f03b35dab837d054f34a10c1..e75aa8664bcb70733b273b055e429c768069425b 100644 (file)
@@ -35,6 +35,7 @@ func main() {
        if architecture == nil {
                log.Fatalf("unrecognized architecture %s", GOARCH)
        }
+       compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
 
        ctxt := obj.Linknew(architecture.LinkArch)
        ctxt.Debugasm = flags.PrintOut
@@ -79,9 +80,9 @@ func main() {
        var ok, diag bool
        var failedFile string
        for _, f := range flag.Args() {
-               lexer := lex.NewLexer(f)
+               lexer := lex.NewLexer(f, compilingRuntime)
                parser := asm.NewParser(ctxt, architecture, lexer,
-                       *flags.CompilingRuntime)
+                       compilingRuntime)
                ctxt.DiagFunc = func(format string, args ...interface{}) {
                        diag = true
                        log.Printf(format, args...)
index 0afa5f062e4393d7b061c9b220ea1f5fac3d2ba7..031a8d901362ad8b7e8a71ad76d6b816fa3a684b 100644 (file)
@@ -892,9 +892,6 @@ func runInstall(pkg string, ch chan struct{}) {
                }
        }
        goasmh := pathf("%s/go_asm.h", workdir)
-       if IsRuntimePackagePath(pkg) {
-               asmArgs = append(asmArgs, "-compiling-runtime")
-       }
 
        // Collect symabis from assembly code.
        var symabis string
@@ -1947,29 +1944,6 @@ func cmdlist() {
        }
 }
 
-// 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.
-//
-// Keep in sync with cmd/internal/objabi/path.go:IsRuntimePackagePath.
-func IsRuntimePackagePath(pkgpath string) bool {
-       rval := false
-       switch pkgpath {
-       case "runtime":
-               rval = true
-       case "reflect":
-               rval = true
-       case "syscall":
-               rval = true
-       case "internal/bytealg":
-               rval = true
-       default:
-               rval = strings.HasPrefix(pkgpath, "runtime/internal")
-       }
-       return rval
-}
-
 func setNoOpt() {
        for _, gcflag := range strings.Split(gogcflags, " ") {
                if gcflag == "-N" || gcflag == "-l" {
index 26b4e0f490df3fa3df5c54bd05724b4080b5e9d4..216cbcf3448b648f478a20eb7915d6a0901898a2 100644 (file)
@@ -22,7 +22,6 @@ import (
        "cmd/go/internal/gover"
        "cmd/go/internal/load"
        "cmd/go/internal/str"
-       "cmd/internal/objabi"
        "cmd/internal/quoted"
        "crypto/sha1"
 )
@@ -359,9 +358,6 @@ func asmArgs(a *Action, p *load.Package) []any {
                        }
                }
        }
-       if objabi.IsRuntimePackagePath(pkgpath) {
-               args = append(args, "-compiling-runtime")
-       }
 
        if cfg.Goarch == "386" {
                // Define GO386_value from cfg.GO386.
index aacab9a0ca7fa920d980e5dd940a7669cf7ac61a..cb06dbe58e2c9179b0a935ba3224c6a15bb3e6ee 100644 (file)
@@ -47,8 +47,6 @@ func PathToPrefix(s string) string {
 // some cases need to be aware of when they are building such a
 // package, for example to enable features such as ABI selectors in
 // assembly sources.
-//
-// Keep in sync with cmd/dist/build.go:IsRuntimePackagePath.
 func IsRuntimePackagePath(pkgpath string) bool {
        rval := false
        switch pkgpath {