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
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
)
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 {
}
// 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
}
// 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)
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 {
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 {
if architecture == nil {
log.Fatalf("unrecognized architecture %s", GOARCH)
}
+ compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
ctxt := obj.Linknew(architecture.LinkArch)
ctxt.Debugasm = flags.PrintOut
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...)
}
}
goasmh := pathf("%s/go_asm.h", workdir)
- if IsRuntimePackagePath(pkg) {
- asmArgs = append(asmArgs, "-compiling-runtime")
- }
// Collect symabis from assembly code.
var symabis string
}
}
-// 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" {
"cmd/go/internal/gover"
"cmd/go/internal/load"
"cmd/go/internal/str"
- "cmd/internal/objabi"
"cmd/internal/quoted"
"crypto/sha1"
)
}
}
}
- if objabi.IsRuntimePackagePath(pkgpath) {
- args = append(args, "-compiling-runtime")
- }
if cfg.Goarch == "386" {
// Define GO386_value from cfg.GO386.
// 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 {