mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
We are planning to use indices for symbol references, instead of symbol names. Here we assign indices to symbols defined in the package being compiled, and propagate the indices to the dependent packages in the export data. A symbol is referenced by a tuple, (package index, symbol index). Normally, for a given symbol, this index is unique, and the symbol index is globally consistent (but with exceptions, see below). The package index is local to a compilation. For example, when compiling the fmt package, fmt.Println gets assigned index 25, then all packages that reference fmt.Println will refer it as (X, 25) with some X. X is the index for the fmt package, which may differ in different compilations. There are some symbols that do not have clear package affiliation, such as dupOK symbols and linknamed symbols. We cannot give them globally consistent indices. We categorize them as non-package symbols, assign them with package index 1 and a symbol index that is only meaningful locally. Currently nothing will consume the indices. All this is behind a flag, -newobj. The flag needs to be set for all builds (-gcflags=all=-newobj -asmflags=all=-newobj), or none. Change-Id: I18e489c531e9a9fbc668519af92c6116b7308cab Reviewed-on: https://go-review.googlesource.com/c/go/+/196029 Reviewed-by: Than McIntosh <thanm@google.com>
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package flags implements top-level flags and the usage message for the assembler.
|
|
package flags
|
|
|
|
import (
|
|
"cmd/internal/objabi"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
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")
|
|
PrintOut = flag.Bool("S", false, "print assembly and machine code")
|
|
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")
|
|
Newobj = flag.Bool("newobj", false, "use new object file format")
|
|
)
|
|
|
|
var (
|
|
D MultiFlag
|
|
I MultiFlag
|
|
)
|
|
|
|
func init() {
|
|
flag.Var(&D, "D", "predefined symbol with optional simple value -D=identifier=value; can be set multiple times")
|
|
flag.Var(&I, "I", "include directory; can be set multiple times")
|
|
objabi.AddVersionFlag() // -V
|
|
}
|
|
|
|
// MultiFlag allows setting a value multiple times to collect a list, as in -I=dir1 -I=dir2.
|
|
type MultiFlag []string
|
|
|
|
func (m *MultiFlag) String() string {
|
|
if len(*m) == 0 {
|
|
return ""
|
|
}
|
|
return fmt.Sprint(*m)
|
|
}
|
|
|
|
func (m *MultiFlag) Set(val string) error {
|
|
(*m) = append(*m, val)
|
|
return nil
|
|
}
|
|
|
|
func Usage() {
|
|
fmt.Fprintf(os.Stderr, "usage: asm [options] file.s ...\n")
|
|
fmt.Fprintf(os.Stderr, "Flags:\n")
|
|
flag.PrintDefaults()
|
|
os.Exit(2)
|
|
}
|
|
|
|
func Parse() {
|
|
flag.Usage = Usage
|
|
flag.Parse()
|
|
if flag.NArg() == 0 {
|
|
flag.Usage()
|
|
}
|
|
|
|
// Flag refinement.
|
|
if *OutputFile == "" {
|
|
if flag.NArg() != 1 {
|
|
flag.Usage()
|
|
}
|
|
input := filepath.Base(flag.Arg(0))
|
|
if strings.HasSuffix(input, ".s") {
|
|
input = input[:len(input)-2]
|
|
}
|
|
*OutputFile = fmt.Sprintf("%s.o", input)
|
|
}
|
|
}
|