mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/objabi: extract shared functionality from obj
Now only cmd/asm and cmd/compile depend on cmd/internal/obj. Changing the assembler backends no longer requires reinstalling cmd/link or cmd/addr2line. There's also now one canonical definition of the object file format in cmd/internal/objabi/doc.go, with a warning to update all three implementations. objabi is still something of a grab bag of unrelated code (e.g., flag and environment variable handling probably belong in a separate "tool" package), but this is still progress. Fixes #15165. Fixes #20026. Change-Id: Ic4b92fac7d0d35438e0d20c9579aad4085c5534c Reviewed-on: https://go-review.googlesource.com/40972 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
f71f32e5e1
commit
1e3570ac86
118 changed files with 2419 additions and 2407 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"cmd/compile/internal/ssa"
|
||||
"cmd/compile/internal/types"
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/src"
|
||||
"cmd/internal/sys"
|
||||
"flag"
|
||||
|
|
@ -68,7 +69,7 @@ var debugtab = []struct {
|
|||
|
||||
func usage() {
|
||||
fmt.Printf("usage: compile [options] file.go...\n")
|
||||
obj.Flagprint(1)
|
||||
objabi.Flagprint(1)
|
||||
Exit(2)
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +86,7 @@ func hidePanic() {
|
|||
}
|
||||
|
||||
func doversion() {
|
||||
p := obj.Expstring()
|
||||
p := objabi.Expstring()
|
||||
if p == "X:none" {
|
||||
p = ""
|
||||
}
|
||||
|
|
@ -93,7 +94,7 @@ func doversion() {
|
|||
if p != "" {
|
||||
sep = " "
|
||||
}
|
||||
fmt.Printf("compile version %s%s%s\n", obj.Version, sep, p)
|
||||
fmt.Printf("compile version %s%s%s\n", objabi.Version, sep, p)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -162,49 +163,49 @@ func Main(archInit func(*Arch)) {
|
|||
mappkg.Name = "go.map"
|
||||
mappkg.Prefix = "go.map"
|
||||
|
||||
Nacl = obj.GOOS == "nacl"
|
||||
Nacl = objabi.GOOS == "nacl"
|
||||
|
||||
flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
|
||||
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
|
||||
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
|
||||
obj.Flagcount("C", "disable printing of columns in error messages", &Debug['C']) // TODO(gri) remove eventually
|
||||
objabi.Flagcount("%", "debug non-static initializers", &Debug['%'])
|
||||
objabi.Flagcount("B", "disable bounds checking", &Debug['B'])
|
||||
objabi.Flagcount("C", "disable printing of columns in error messages", &Debug['C']) // TODO(gri) remove eventually
|
||||
flag.StringVar(&localimport, "D", "", "set relative `path` for local imports")
|
||||
obj.Flagcount("E", "debug symbol export", &Debug['E'])
|
||||
obj.Flagfn1("I", "add `directory` to import search path", addidir)
|
||||
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
|
||||
obj.Flagcount("N", "disable optimizations", &Debug['N'])
|
||||
objabi.Flagcount("E", "debug symbol export", &Debug['E'])
|
||||
objabi.Flagfn1("I", "add `directory` to import search path", addidir)
|
||||
objabi.Flagcount("K", "debug missing line numbers", &Debug['K'])
|
||||
objabi.Flagcount("N", "disable optimizations", &Debug['N'])
|
||||
flag.BoolVar(&Debug_asm, "S", false, "print assembly listing")
|
||||
obj.Flagfn0("V", "print compiler version", doversion)
|
||||
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
|
||||
objabi.Flagfn0("V", "print compiler version", doversion)
|
||||
objabi.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
|
||||
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
|
||||
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
|
||||
flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
|
||||
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`")
|
||||
flag.BoolVar(&flagDWARF, "dwarf", true, "generate DWARF symbols")
|
||||
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
|
||||
obj.Flagcount("f", "debug stack frames", &Debug['f'])
|
||||
obj.Flagcount("h", "halt on error", &Debug['h'])
|
||||
obj.Flagcount("i", "debug line number stack", &Debug['i'])
|
||||
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
|
||||
objabi.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
|
||||
objabi.Flagcount("f", "debug stack frames", &Debug['f'])
|
||||
objabi.Flagcount("h", "halt on error", &Debug['h'])
|
||||
objabi.Flagcount("i", "debug line number stack", &Debug['i'])
|
||||
objabi.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
|
||||
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
|
||||
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
|
||||
obj.Flagcount("l", "disable inlining", &Debug['l'])
|
||||
objabi.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
|
||||
objabi.Flagcount("l", "disable inlining", &Debug['l'])
|
||||
flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
|
||||
obj.Flagcount("live", "debug liveness analysis", &debuglive)
|
||||
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
|
||||
objabi.Flagcount("live", "debug liveness analysis", &debuglive)
|
||||
objabi.Flagcount("m", "print optimization decisions", &Debug['m'])
|
||||
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
|
||||
flag.BoolVar(&dolinkobj, "dolinkobj", true, "generate linker-specific objects; if false, some invalid code may compile")
|
||||
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
||||
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
||||
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
|
||||
flag.BoolVar(&writearchive, "pack", false, "write package file instead of object file")
|
||||
obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
|
||||
objabi.Flagcount("r", "debug generated wrappers", &Debug['r'])
|
||||
flag.BoolVar(&flag_race, "race", false, "enable race detector")
|
||||
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
|
||||
objabi.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
|
||||
flag.StringVar(&pathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
|
||||
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
|
||||
flag.BoolVar(&Debug_vlog, "v", false, "increase debug verbosity")
|
||||
obj.Flagcount("w", "debug type checking", &Debug['w'])
|
||||
objabi.Flagcount("w", "debug type checking", &Debug['w'])
|
||||
flag.BoolVar(&use_writebarrier, "wb", true, "enable write barrier")
|
||||
var flag_shared bool
|
||||
var flag_dynlink bool
|
||||
|
|
@ -219,7 +220,7 @@ func Main(archInit func(*Arch)) {
|
|||
flag.StringVar(&blockprofile, "blockprofile", "", "write block profile to `file`")
|
||||
flag.StringVar(&mutexprofile, "mutexprofile", "", "write mutex profile to `file`")
|
||||
flag.StringVar(&benchfile, "bench", "", "append benchmark times to `file`")
|
||||
obj.Flagparse(usage)
|
||||
objabi.Flagparse(usage)
|
||||
|
||||
Ctxt.Flag_shared = flag_dynlink || flag_shared
|
||||
Ctxt.Flag_dynlink = flag_dynlink
|
||||
|
|
@ -600,7 +601,7 @@ func writebench(filename string) error {
|
|||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintln(&buf, "commit:", obj.Version)
|
||||
fmt.Fprintln(&buf, "commit:", objabi.Version)
|
||||
fmt.Fprintln(&buf, "goos:", runtime.GOOS)
|
||||
fmt.Fprintln(&buf, "goarch:", runtime.GOARCH)
|
||||
timings.Write(&buf, "BenchmarkCompile:"+myimportpath+":")
|
||||
|
|
@ -723,7 +724,7 @@ func findpkg(name string) (file string, ok bool) {
|
|||
}
|
||||
}
|
||||
|
||||
if obj.GOROOT != "" {
|
||||
if objabi.GOROOT != "" {
|
||||
suffix := ""
|
||||
suffixsep := ""
|
||||
if flag_installsuffix != "" {
|
||||
|
|
@ -737,11 +738,11 @@ func findpkg(name string) (file string, ok bool) {
|
|||
suffix = "msan"
|
||||
}
|
||||
|
||||
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.a", obj.GOROOT, obj.GOOS, obj.GOARCH, suffixsep, suffix, name)
|
||||
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.a", objabi.GOROOT, objabi.GOOS, objabi.GOARCH, suffixsep, suffix, name)
|
||||
if _, err := os.Stat(file); err == nil {
|
||||
return file, true
|
||||
}
|
||||
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.o", obj.GOROOT, obj.GOOS, obj.GOARCH, suffixsep, suffix, name)
|
||||
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.o", objabi.GOROOT, objabi.GOOS, objabi.GOARCH, suffixsep, suffix, name)
|
||||
if _, err := os.Stat(file); err == nil {
|
||||
return file, true
|
||||
}
|
||||
|
|
@ -887,7 +888,7 @@ func importfile(f *Val) *types.Pkg {
|
|||
errorexit()
|
||||
}
|
||||
|
||||
q := fmt.Sprintf("%s %s %s %s", obj.GOOS, obj.GOARCH, obj.Version, obj.Expstring())
|
||||
q := fmt.Sprintf("%s %s %s %s", objabi.GOOS, objabi.GOARCH, objabi.Version, objabi.Expstring())
|
||||
if p[10:] != q {
|
||||
yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q)
|
||||
errorexit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue