mirror of https://github.com/golang/go.git
cmd/asm, cmd/cgo, cmd/compile, cmd/cover, cmd/link: use standard -V output
Also add -V=full to print a unique identifier of the specific tool being invoked. This will be used for content-based staleness. Also sort and clean up a few of the flag doc comments. Change-Id: I786fe50be0b8e5f77af809d8d2dab721185c2abd Reviewed-on: https://go-review.googlesource.com/68590 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
cb3b345209
commit
840f2c167f
|
|
@ -19,23 +19,26 @@ The GOOS and GOARCH environment variables set the desired target.
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
|
|
||||||
-D value
|
-D name[=value]
|
||||||
predefined symbol with optional simple value -D=identifier=value;
|
Predefine symbol name with an optional simple value.
|
||||||
can be set multiple times
|
Can be repeated to define multiple symbols.
|
||||||
-I value
|
-I dir1 -I dir2
|
||||||
include directory; can be set multiple times
|
Search for #include files in dir1, dir2, etc,
|
||||||
-S print assembly and machine code
|
after consulting $GOROOT/pkg/$GOOS_$GOARCH.
|
||||||
|
-S
|
||||||
|
Print assembly and machine code.
|
||||||
|
-V
|
||||||
|
Print assembler version and exit.
|
||||||
-debug
|
-debug
|
||||||
dump instructions as they are parsed
|
Dump instructions as they are parsed.
|
||||||
-dynlink
|
-dynlink
|
||||||
support references to Go symbols defined in other shared libraries
|
Support references to Go symbols defined in other shared libraries.
|
||||||
-o string
|
-o file
|
||||||
output file; default foo.o for /a/b/c/foo.s
|
Write output to file. The default is foo.o for /a/b/c/foo.s.
|
||||||
-shared
|
-shared
|
||||||
generate code that can be linked into a shared library
|
Generate code that can be linked into a shared library.
|
||||||
-trimpath string
|
-trimpath prefix
|
||||||
remove prefix from recorded source file paths
|
Remove prefix from recorded source file paths.
|
||||||
|
|
||||||
Input language:
|
Input language:
|
||||||
|
|
||||||
The assembler uses mostly the same syntax for all architectures,
|
The assembler uses mostly the same syntax for all architectures,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
package flags
|
package flags
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmd/internal/objabi"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -31,6 +32,7 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
flag.Var(&D, "D", "predefined symbol with optional simple value -D=identifier=value; can be set multiple times")
|
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")
|
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.
|
// MultiFlag allows setting a value multiple times to collect a list, as in -I=dir1 -I=dir2.
|
||||||
|
|
|
||||||
|
|
@ -315,32 +315,35 @@ invoking the C compiler to compile the C parts of the package.
|
||||||
|
|
||||||
The following options are available when running cgo directly:
|
The following options are available when running cgo directly:
|
||||||
|
|
||||||
|
-V
|
||||||
|
Print cgo version and exit.
|
||||||
|
-debug-define
|
||||||
|
Debugging option. Print #defines.
|
||||||
|
-debug-gcc
|
||||||
|
Debugging option. Trace C compiler execution and output.
|
||||||
-dynimport file
|
-dynimport file
|
||||||
Write list of symbols imported by file. Write to
|
Write list of symbols imported by file. Write to
|
||||||
-dynout argument or to standard output. Used by go
|
-dynout argument or to standard output. Used by go
|
||||||
build when building a cgo package.
|
build when building a cgo package.
|
||||||
|
-dynlinker
|
||||||
|
Write dynamic linker as part of -dynimport output.
|
||||||
-dynout file
|
-dynout file
|
||||||
Write -dynimport output to file.
|
Write -dynimport output to file.
|
||||||
-dynpackage package
|
-dynpackage package
|
||||||
Set Go package for -dynimport output.
|
Set Go package for -dynimport output.
|
||||||
-dynlinker
|
|
||||||
Write dynamic linker as part of -dynimport output.
|
|
||||||
-godefs
|
|
||||||
Write out input file in Go syntax replacing C package
|
|
||||||
names with real values. Used to generate files in the
|
|
||||||
syscall package when bootstrapping a new target.
|
|
||||||
-srcdir directory
|
|
||||||
Find the Go input files, listed on the command line,
|
|
||||||
in directory.
|
|
||||||
-objdir directory
|
|
||||||
Put all generated files in directory.
|
|
||||||
-importpath string
|
|
||||||
The import path for the Go package. Optional; used for
|
|
||||||
nicer comments in the generated files.
|
|
||||||
-exportheader file
|
-exportheader file
|
||||||
If there are any exported functions, write the
|
If there are any exported functions, write the
|
||||||
generated export declarations to file.
|
generated export declarations to file.
|
||||||
C code can #include this to see the declarations.
|
C code can #include this to see the declarations.
|
||||||
|
-importpath string
|
||||||
|
The import path for the Go package. Optional; used for
|
||||||
|
nicer comments in the generated files.
|
||||||
|
-import_runtime_cgo
|
||||||
|
If set (which it is by default) import runtime/cgo in
|
||||||
|
generated output.
|
||||||
|
-import_syscall
|
||||||
|
If set (which it is by default) import syscall in
|
||||||
|
generated output.
|
||||||
-gccgo
|
-gccgo
|
||||||
Generate output for the gccgo compiler rather than the
|
Generate output for the gccgo compiler rather than the
|
||||||
gc compiler.
|
gc compiler.
|
||||||
|
|
@ -348,16 +351,13 @@ The following options are available when running cgo directly:
|
||||||
The -fgo-prefix option to be used with gccgo.
|
The -fgo-prefix option to be used with gccgo.
|
||||||
-gccgopkgpath path
|
-gccgopkgpath path
|
||||||
The -fgo-pkgpath option to be used with gccgo.
|
The -fgo-pkgpath option to be used with gccgo.
|
||||||
-import_runtime_cgo
|
-godefs
|
||||||
If set (which it is by default) import runtime/cgo in
|
Write out input file in Go syntax replacing C package
|
||||||
generated output.
|
names with real values. Used to generate files in the
|
||||||
-import_syscall
|
syscall package when bootstrapping a new target.
|
||||||
If set (which it is by default) import syscall in
|
-objdir directory
|
||||||
generated output.
|
Put all generated files in directory.
|
||||||
-debug-define
|
-srcdir directory
|
||||||
Debugging option. Print #defines.
|
|
||||||
-debug-gcc
|
|
||||||
Debugging option. Trace C compiler execution and output.
|
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"cmd/internal/objabi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Package collects information about the package we're going to write.
|
// A Package collects information about the package we're going to write.
|
||||||
|
|
@ -201,6 +203,7 @@ var importSyscall = flag.Bool("import_syscall", true, "import syscall in generat
|
||||||
var goarch, goos string
|
var goarch, goos string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
objabi.AddVersionFlag() // -V
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ func Main(archInit func(*Arch)) {
|
||||||
objabi.Flagcount("K", "debug missing line numbers", &Debug['K'])
|
objabi.Flagcount("K", "debug missing line numbers", &Debug['K'])
|
||||||
objabi.Flagcount("N", "disable optimizations", &Debug['N'])
|
objabi.Flagcount("N", "disable optimizations", &Debug['N'])
|
||||||
flag.BoolVar(&Debug_asm, "S", false, "print assembly listing")
|
flag.BoolVar(&Debug_asm, "S", false, "print assembly listing")
|
||||||
objabi.Flagfn0("V", "print compiler version", doversion)
|
objabi.AddVersionFlag() // -V
|
||||||
objabi.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
|
objabi.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
|
||||||
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
|
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
|
||||||
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
|
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"cmd/internal/objabi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usageMessage = "" +
|
const usageMessage = "" +
|
||||||
|
|
@ -67,6 +69,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
objabi.AddVersionFlag()
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2522,10 +2522,18 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg string, allaction
|
||||||
if cfg.BuildBuildmode == "plugin" {
|
if cfg.BuildBuildmode == "plugin" {
|
||||||
ldflags = append(ldflags, "-pluginpath", load.PluginPath(root.Package))
|
ldflags = append(ldflags, "-pluginpath", load.PluginPath(root.Package))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(rsc): This is probably wrong - see golang.org/issue/22155.
|
||||||
if cfg.GOROOT != runtime.GOROOT() {
|
if cfg.GOROOT != runtime.GOROOT() {
|
||||||
ldflags = append(ldflags, "-X=runtime/internal/sys.DefaultGoroot="+cfg.GOROOT)
|
ldflags = append(ldflags, "-X=runtime/internal/sys.DefaultGoroot="+cfg.GOROOT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store BuildID inside toolchain binaries as a unique identifier of the
|
||||||
|
// tool being run, for use by content-based staleness determination.
|
||||||
|
if root.Package.Goroot && strings.HasPrefix(root.Package.ImportPath, "cmd/") {
|
||||||
|
ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.Package.Internal.BuildID)
|
||||||
|
}
|
||||||
|
|
||||||
// If the user has not specified the -extld option, then specify the
|
// If the user has not specified the -extld option, then specify the
|
||||||
// appropriate linker. In case of C++ code, use the compiler named
|
// appropriate linker. In case of C++ code, use the compiler named
|
||||||
// by the CXX environment variable or defaultCXX if CXX is not set.
|
// by the CXX environment variable or defaultCXX if CXX is not set.
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Flagcount(name, usage string, val *int) {
|
func Flagcount(name, usage string, val *int) {
|
||||||
flag.Var((*count)(val), name, usage)
|
flag.Var((*count)(val), name, usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Flagfn0(name, usage string, f func()) {
|
|
||||||
flag.Var(fn0(f), name, usage)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Flagfn1(name, usage string, f func(string)) {
|
func Flagfn1(name, usage string, f func(string)) {
|
||||||
flag.Var(fn1(f), name, usage)
|
flag.Var(fn1(f), name, usage)
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +32,43 @@ func Flagparse(usage func()) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddVersionFlag() {
|
||||||
|
flag.Var(versionFlag{}, "V", "print version and exit")
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildID string // filled in by linker
|
||||||
|
|
||||||
|
type versionFlag struct{}
|
||||||
|
|
||||||
|
func (versionFlag) IsBoolFlag() bool { return true }
|
||||||
|
func (versionFlag) Get() interface{} { return nil }
|
||||||
|
func (versionFlag) String() string { return "" }
|
||||||
|
func (versionFlag) Set(s string) error {
|
||||||
|
name := os.Args[0]
|
||||||
|
name = name[strings.LastIndex(name, `/`)+1:]
|
||||||
|
name = name[strings.LastIndex(name, `\`)+1:]
|
||||||
|
p := Expstring()
|
||||||
|
if p == DefaultExpstring() {
|
||||||
|
p = ""
|
||||||
|
}
|
||||||
|
sep := ""
|
||||||
|
if p != "" {
|
||||||
|
sep = " "
|
||||||
|
}
|
||||||
|
|
||||||
|
// The go command invokes -V=full to get a unique identifier
|
||||||
|
// for this tool. It is assumed that the release version is sufficient
|
||||||
|
// for releases, but during development we include the full
|
||||||
|
// build ID of the binary, so that if the compiler is changed and
|
||||||
|
// rebuilt, we notice and rebuild all packages.
|
||||||
|
if s == "full" && strings.HasPrefix(Version, "devel") {
|
||||||
|
p += " buildID=" + buildID
|
||||||
|
}
|
||||||
|
fmt.Printf("%s version %s%s%s\n", name, Version, sep, p)
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// count is a flag.Value that is like a flag.Bool and a flag.Int.
|
// count is a flag.Value that is like a flag.Bool and a flag.Int.
|
||||||
// If used as -name, it increments the count, but -name=x sets the count.
|
// If used as -name, it increments the count, but -name=x sets the count.
|
||||||
// Used for verbose flag -v.
|
// Used for verbose flag -v.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ Flags:
|
||||||
-T address
|
-T address
|
||||||
Set text segment address.
|
Set text segment address.
|
||||||
-V
|
-V
|
||||||
Print the linker version and exit.
|
Print linker version and exit.
|
||||||
-X importpath.name=value
|
-X importpath.name=value
|
||||||
Set the value of the string variable in importpath named name to value.
|
Set the value of the string variable in importpath named name to value.
|
||||||
Note that before Go 1.5 this option took two separate arguments.
|
Note that before Go 1.5 this option took two separate arguments.
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ func Main(arch *sys.Arch, theArch Arch) {
|
||||||
flag.Var(&ctxt.BuildMode, "buildmode", "set build `mode`")
|
flag.Var(&ctxt.BuildMode, "buildmode", "set build `mode`")
|
||||||
objabi.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo)
|
objabi.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo)
|
||||||
objabi.Flagfn1("L", "add specified `directory` to library path", func(a string) { Lflag(ctxt, a) })
|
objabi.Flagfn1("L", "add specified `directory` to library path", func(a string) { Lflag(ctxt, a) })
|
||||||
objabi.Flagfn0("V", "print version and exit", doversion)
|
objabi.AddVersionFlag() // -V
|
||||||
objabi.Flagfn1("X", "add string value `definition` of the form importpath.name=value", func(s string) { addstrdata1(ctxt, s) })
|
objabi.Flagfn1("X", "add string value `definition` of the form importpath.name=value", func(s string) { addstrdata1(ctxt, s) })
|
||||||
objabi.Flagcount("v", "print link trace", &ctxt.Debugvlog)
|
objabi.Flagcount("v", "print link trace", &ctxt.Debugvlog)
|
||||||
objabi.Flagfn1("importcfg", "read import configuration from `file`", ctxt.readImportCfg)
|
objabi.Flagfn1("importcfg", "read import configuration from `file`", ctxt.readImportCfg)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue