mirror of
https://github.com/golang/go
synced 2024-11-27 04:01:19 -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:
parent
596120fdc6
commit
72946ae867
@ -29,7 +29,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
|
|||||||
input := filepath.Join("testdata", file+".s")
|
input := filepath.Join("testdata", file+".s")
|
||||||
architecture, ctxt := setArch(goarch)
|
architecture, ctxt := setArch(goarch)
|
||||||
architecture.Init(ctxt)
|
architecture.Init(ctxt)
|
||||||
lexer := lex.NewLexer(input)
|
lexer := lex.NewLexer(input, false)
|
||||||
parser := NewParser(ctxt, architecture, lexer, false)
|
parser := NewParser(ctxt, architecture, lexer, false)
|
||||||
pList := new(obj.Plist)
|
pList := new(obj.Plist)
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -278,7 +278,7 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
|
|||||||
input := filepath.Join("testdata", file+".s")
|
input := filepath.Join("testdata", file+".s")
|
||||||
architecture, ctxt := setArch(goarch)
|
architecture, ctxt := setArch(goarch)
|
||||||
architecture.Init(ctxt)
|
architecture.Init(ctxt)
|
||||||
lexer := lex.NewLexer(input)
|
lexer := lex.NewLexer(input, false)
|
||||||
parser := NewParser(ctxt, architecture, lexer, false)
|
parser := NewParser(ctxt, architecture, lexer, false)
|
||||||
pList := new(obj.Plist)
|
pList := new(obj.Plist)
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -26,7 +26,6 @@ var (
|
|||||||
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", obj.UnlinkablePkg, "set expected package import to path")
|
Importpath = flag.String("p", obj.UnlinkablePkg, "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("compiling-runtime", false, "source to be compiled is part of the Go runtime")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DebugFlags struct {
|
var DebugFlags struct {
|
||||||
|
@ -34,22 +34,22 @@ type Input struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewInput returns an Input from the given path.
|
// NewInput returns an Input from the given path.
|
||||||
func NewInput(name string) *Input {
|
func NewInput(name string, compilingRuntime bool) *Input {
|
||||||
return &Input{
|
return &Input{
|
||||||
// include directories: look in source dir, then -I directories.
|
// include directories: look in source dir, then -I directories.
|
||||||
includes: append([]string{filepath.Dir(name)}, flags.I...),
|
includes: append([]string{filepath.Dir(name)}, flags.I...),
|
||||||
beginningOfLine: true,
|
beginningOfLine: true,
|
||||||
macros: predefine(flags.D),
|
macros: predefine(flags.D, compilingRuntime),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// predefine installs the macros set by the -D flag on the command line.
|
// 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)
|
macros := make(map[string]*Macro)
|
||||||
|
|
||||||
// Set macros for GOEXPERIMENTs so we can easily switch
|
// Set macros for GOEXPERIMENTs so we can easily switch
|
||||||
// runtime assembly code based on them.
|
// runtime assembly code based on them.
|
||||||
if *flags.CompilingRuntime {
|
if compilingRuntime {
|
||||||
for _, exp := range buildcfg.Experiment.Enabled() {
|
for _, exp := range buildcfg.Experiment.Enabled() {
|
||||||
// Define macro.
|
// Define macro.
|
||||||
name := "GOEXPERIMENT_" + exp
|
name := "GOEXPERIMENT_" + exp
|
||||||
|
@ -60,8 +60,8 @@ func (t ScanToken) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewLexer returns a lexer for the named file and the given link context.
|
// NewLexer returns a lexer for the named file and the given link context.
|
||||||
func NewLexer(name string) TokenReader {
|
func NewLexer(name string, compilingRuntime bool) TokenReader {
|
||||||
input := NewInput(name)
|
input := NewInput(name, compilingRuntime)
|
||||||
fd, err := os.Open(name)
|
fd, err := os.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%s\n", err)
|
log.Fatalf("%s\n", err)
|
||||||
|
@ -258,7 +258,7 @@ var lexTests = []lexTest{
|
|||||||
|
|
||||||
func TestLex(t *testing.T) {
|
func TestLex(t *testing.T) {
|
||||||
for _, test := range lexTests {
|
for _, test := range lexTests {
|
||||||
input := NewInput(test.name)
|
input := NewInput(test.name, false)
|
||||||
input.Push(NewTokenizer(test.name, strings.NewReader(test.input), nil))
|
input.Push(NewTokenizer(test.name, strings.NewReader(test.input), nil))
|
||||||
result := drain(input)
|
result := drain(input)
|
||||||
if result != test.output {
|
if result != test.output {
|
||||||
@ -328,7 +328,7 @@ var badLexTests = []badLexTest{
|
|||||||
|
|
||||||
func TestBadLex(t *testing.T) {
|
func TestBadLex(t *testing.T) {
|
||||||
for _, test := range badLexTests {
|
for _, test := range badLexTests {
|
||||||
input := NewInput(test.error)
|
input := NewInput(test.error, false)
|
||||||
input.Push(NewTokenizer(test.error, strings.NewReader(test.input), nil))
|
input.Push(NewTokenizer(test.error, strings.NewReader(test.input), nil))
|
||||||
err := firstError(input)
|
err := firstError(input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -35,6 +35,7 @@ func main() {
|
|||||||
if architecture == nil {
|
if architecture == nil {
|
||||||
log.Fatalf("unrecognized architecture %s", GOARCH)
|
log.Fatalf("unrecognized architecture %s", GOARCH)
|
||||||
}
|
}
|
||||||
|
compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
|
||||||
|
|
||||||
ctxt := obj.Linknew(architecture.LinkArch)
|
ctxt := obj.Linknew(architecture.LinkArch)
|
||||||
ctxt.Debugasm = flags.PrintOut
|
ctxt.Debugasm = flags.PrintOut
|
||||||
@ -79,9 +80,9 @@ func main() {
|
|||||||
var ok, diag bool
|
var ok, diag bool
|
||||||
var failedFile string
|
var failedFile string
|
||||||
for _, f := range flag.Args() {
|
for _, f := range flag.Args() {
|
||||||
lexer := lex.NewLexer(f)
|
lexer := lex.NewLexer(f, compilingRuntime)
|
||||||
parser := asm.NewParser(ctxt, architecture, lexer,
|
parser := asm.NewParser(ctxt, architecture, lexer,
|
||||||
*flags.CompilingRuntime)
|
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...)
|
||||||
|
26
src/cmd/dist/build.go
vendored
26
src/cmd/dist/build.go
vendored
@ -892,9 +892,6 @@ func runInstall(pkg string, ch chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
goasmh := pathf("%s/go_asm.h", workdir)
|
goasmh := pathf("%s/go_asm.h", workdir)
|
||||||
if IsRuntimePackagePath(pkg) {
|
|
||||||
asmArgs = append(asmArgs, "-compiling-runtime")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect symabis from assembly code.
|
// Collect symabis from assembly code.
|
||||||
var symabis string
|
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() {
|
func setNoOpt() {
|
||||||
for _, gcflag := range strings.Split(gogcflags, " ") {
|
for _, gcflag := range strings.Split(gogcflags, " ") {
|
||||||
if gcflag == "-N" || gcflag == "-l" {
|
if gcflag == "-N" || gcflag == "-l" {
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"cmd/go/internal/gover"
|
"cmd/go/internal/gover"
|
||||||
"cmd/go/internal/load"
|
"cmd/go/internal/load"
|
||||||
"cmd/go/internal/str"
|
"cmd/go/internal/str"
|
||||||
"cmd/internal/objabi"
|
|
||||||
"cmd/internal/quoted"
|
"cmd/internal/quoted"
|
||||||
"crypto/sha1"
|
"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" {
|
if cfg.Goarch == "386" {
|
||||||
// Define GO386_value from cfg.GO386.
|
// Define GO386_value from cfg.GO386.
|
||||||
|
@ -47,8 +47,6 @@ func PathToPrefix(s string) string {
|
|||||||
// some cases need to be aware of when they are building such a
|
// some cases need to be aware of when they are building such a
|
||||||
// package, for example to enable features such as ABI selectors in
|
// package, for example to enable features such as ABI selectors in
|
||||||
// assembly sources.
|
// assembly sources.
|
||||||
//
|
|
||||||
// Keep in sync with cmd/dist/build.go:IsRuntimePackagePath.
|
|
||||||
func IsRuntimePackagePath(pkgpath string) bool {
|
func IsRuntimePackagePath(pkgpath string) bool {
|
||||||
rval := false
|
rval := false
|
||||||
switch pkgpath {
|
switch pkgpath {
|
||||||
|
Loading…
Reference in New Issue
Block a user