1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:30:05 -07:00

cmd/asm,cmd/dist,cmd/go: remove asm -compiling-runtime flag

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>
This commit is contained in:
Austin Clements 2023-06-30 16:33:49 -04:00
parent 596120fdc6
commit 72946ae867
9 changed files with 23 additions and 55 deletions

View 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

View File

@ -26,7 +26,6 @@ var (
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")
)
var DebugFlags struct {

View 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

View 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)

View 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 {

View 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...)

26
src/cmd/dist/build.go vendored
View 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" {

View 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.

View 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 {