Commit 0f4132c9 authored by Russ Cox's avatar Russ Cox

all: build and use go tool compile, go tool link

This CL fixes the build to use the newly created go tool compile
and go tool link in place of go tool 5g, go tool 5l, and so on.

See golang-dev thread titled "go tool compile, etc" for background.

Although it was not a primary motivation, this conversion does
reduce the wall clock time and cpu time required for make.bash
by about 10%.

Change-Id: I79cbbdb676cab029db8aeefb99a53178ff55f98d
Reviewed-on: https://go-review.googlesource.com/10288Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 17eba6e6
...@@ -540,7 +540,7 @@ func install(dir string) { ...@@ -540,7 +540,7 @@ func install(dir string) {
if elem == "go" { if elem == "go" {
elem = "go_bootstrap" elem = "go_bootstrap"
} }
link = []string{fmt.Sprintf("%s/%sl", tooldir, gochar), "-o", pathf("%s/%s%s", tooldir, elem, exe)} link = []string{pathf("%s/link", tooldir), "-o", pathf("%s/%s%s", tooldir, elem, exe)}
targ = len(link) - 1 targ = len(link) - 1
} }
ttarg := mtime(link[targ]) ttarg := mtime(link[targ])
...@@ -675,7 +675,7 @@ func install(dir string) { ...@@ -675,7 +675,7 @@ func install(dir string) {
} else { } else {
archive = b archive = b
} }
compile := []string{pathf("%s/%sg", tooldir, gochar), "-pack", "-o", b, "-p", pkg} compile := []string{pathf("%s/compile", tooldir), "-pack", "-o", b, "-p", pkg}
if dir == "runtime" { if dir == "runtime" {
compile = append(compile, "-+", "-asmhdr", pathf("%s/go_asm.h", workdir)) compile = append(compile, "-+", "-asmhdr", pathf("%s/go_asm.h", workdir))
} }
...@@ -897,17 +897,9 @@ var buildorder = []string{ ...@@ -897,17 +897,9 @@ var buildorder = []string{
// compilers but build only the $GOARCH ones. // compilers but build only the $GOARCH ones.
var cleantab = []string{ var cleantab = []string{
// Commands and C libraries. // Commands and C libraries.
"cmd/5g", "cmd/compile",
"cmd/5l",
"cmd/6g",
"cmd/6l",
"cmd/7g",
"cmd/7l",
"cmd/8g",
"cmd/8l",
"cmd/9g",
"cmd/9l",
"cmd/go", "cmd/go",
"cmd/link",
"cmd/old5a", "cmd/old5a",
"cmd/old6a", "cmd/old6a",
"cmd/old8a", "cmd/old8a",
......
...@@ -23,31 +23,33 @@ import ( ...@@ -23,31 +23,33 @@ import (
// which are commands, and entries beginning with internal/, which are // which are commands, and entries beginning with internal/, which are
// packages supporting the commands. // packages supporting the commands.
var bootstrapDirs = []string{ var bootstrapDirs = []string{
"5g",
"5l",
"6g",
"6l",
"7g",
"7l",
"8g",
"8l",
"9g",
"9l",
"asm", "asm",
"asm/internal/arch", "asm/internal/arch",
"asm/internal/asm", "asm/internal/asm",
"asm/internal/flags", "asm/internal/flags",
"asm/internal/lex", "asm/internal/lex",
"compile",
"compile/internal/amd64",
"compile/internal/arm",
"compile/internal/arm64",
"compile/internal/big",
"compile/internal/gc",
"compile/internal/ppc64",
"compile/internal/x86",
"internal/asm", "internal/asm",
"internal/gcprog", "internal/gcprog",
"internal/gc/big",
"internal/gc",
"internal/ld",
"internal/obj", "internal/obj",
"internal/obj/arm", "internal/obj/arm",
"internal/obj/arm64", "internal/obj/arm64",
"internal/obj/ppc64", "internal/obj/ppc64",
"internal/obj/x86", "internal/obj/x86",
"link",
"link/internal/amd64",
"link/internal/arm",
"link/internal/arm64",
"link/internal/ld",
"link/internal/ppc64",
"link/internal/x86",
"old5a", "old5a",
"old6a", "old6a",
"old8a", "old8a",
......
...@@ -1532,7 +1532,7 @@ func (b *builder) linkShared(a *action) (err error) { ...@@ -1532,7 +1532,7 @@ func (b *builder) linkShared(a *action) (err error) {
} }
ldflags = append(ldflags, d.p.ImportPath+"="+d.target) ldflags = append(ldflags, d.p.ImportPath+"="+d.target)
} }
return b.run(".", a.target, nil, buildToolExec, tool(archChar()+"l"), "-o", a.target, importArgs, ldflags) return b.run(".", a.target, nil, buildToolExec, tool("link"), "-o", a.target, importArgs, ldflags)
} }
// install is the action for installing a single package or executable. // install is the action for installing a single package or executable.
...@@ -2109,11 +2109,11 @@ func (noToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error ...@@ -2109,11 +2109,11 @@ func (noToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error
type gcToolchain struct{} type gcToolchain struct{}
func (gcToolchain) compiler() string { func (gcToolchain) compiler() string {
return tool(archChar() + "g") return tool("compile")
} }
func (gcToolchain) linker() string { func (gcToolchain) linker() string {
return tool(archChar() + "l") return tool("link")
} }
func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool, importArgs []string, gofiles []string) (ofile string, output []byte, err error) { func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool, importArgs []string, gofiles []string) (ofile string, output []byte, err error) {
...@@ -2152,7 +2152,7 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool, ...@@ -2152,7 +2152,7 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool,
gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix) gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix)
} }
args := []interface{}{buildToolExec, tool(archChar() + "g"), "-o", ofile, "-trimpath", b.work, buildGcflags, gcargs, "-D", p.localPrefix, importArgs} args := []interface{}{buildToolExec, tool("compile"), "-o", ofile, "-trimpath", b.work, buildGcflags, gcargs, "-D", p.localPrefix, importArgs}
if ofile == archive { if ofile == archive {
args = append(args, "-pack") args = append(args, "-pack")
} }
...@@ -2333,7 +2333,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action, ...@@ -2333,7 +2333,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
ldflags = setextld(ldflags, compiler) ldflags = setextld(ldflags, compiler)
ldflags = append(ldflags, "-buildmode="+ldBuildmode) ldflags = append(ldflags, "-buildmode="+ldBuildmode)
ldflags = append(ldflags, buildLdflags...) ldflags = append(ldflags, buildLdflags...)
return b.run(".", p.ImportPath, nil, buildToolExec, tool(archChar()+"l"), "-o", out, importArgs, ldflags, mainpkg) return b.run(".", p.ImportPath, nil, buildToolExec, tool("link"), "-o", out, importArgs, ldflags, mainpkg)
} }
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error { func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error {
......
...@@ -230,9 +230,9 @@ func TestHello(t *testing.T) { ...@@ -230,9 +230,9 @@ func TestHello(t *testing.T) {
} }
run("go", "build", "cmd/pack") // writes pack binary to dir run("go", "build", "cmd/pack") // writes pack binary to dir
run("go", "tool", char+"g", "hello.go") run("go", "tool", "compile", "hello.go")
run("./pack", "grc", "hello.a", "hello."+char) run("./pack", "grc", "hello.a", "hello."+char)
run("go", "tool", char+"l", "-o", "a.out", "hello.a") run("go", "tool", "link", "-o", "a.out", "hello.a")
out := run("./a.out") out := run("./a.out")
if out != "hello world\n" { if out != "hello world\n" {
t.Fatalf("incorrect output: %q, want %q", out, "hello world\n") t.Fatalf("incorrect output: %q, want %q", out, "hello world\n")
...@@ -304,10 +304,10 @@ func TestLargeDefs(t *testing.T) { ...@@ -304,10 +304,10 @@ func TestLargeDefs(t *testing.T) {
} }
run("go", "build", "cmd/pack") // writes pack binary to dir run("go", "build", "cmd/pack") // writes pack binary to dir
run("go", "tool", char+"g", "large.go") run("go", "tool", "compile", "large.go")
run("./pack", "grc", "large.a", "large."+char) run("./pack", "grc", "large.a", "large."+char)
run("go", "tool", char+"g", "-I", ".", "main.go") run("go", "tool", "compile", "-I", ".", "main.go")
run("go", "tool", char+"l", "-L", ".", "-o", "a.out", "main."+char) run("go", "tool", "link", "-L", ".", "-o", "a.out", "main."+char)
out := run("./a.out") out := run("./a.out")
if out != "ok\n" { if out != "ok\n" {
t.Fatalf("incorrect output: %q, want %q", out, "ok\n") t.Fatalf("incorrect output: %q, want %q", out, "ok\n")
......
...@@ -49,7 +49,7 @@ func dotest(self bool) bool { ...@@ -49,7 +49,7 @@ func dotest(self bool) bool {
// the resulting binary looks like it was built from pclinetest.s, // the resulting binary looks like it was built from pclinetest.s,
// but we have renamed it to keep it away from the go tool. // but we have renamed it to keep it away from the go tool.
pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest") pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest")
command := fmt.Sprintf("go tool asm -o %s.6 pclinetest.asm && go tool 6l -H linux -E main -o %s %s.6", command := fmt.Sprintf("go tool asm -o %s.o pclinetest.asm && go tool link -H linux -E main -o %s %s.o",
pclinetestBinary, pclinetestBinary, pclinetestBinary) pclinetestBinary, pclinetestBinary, pclinetestBinary)
cmd := exec.Command("sh", "-c", command) cmd := exec.Command("sh", "-c", command)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
......
...@@ -7,8 +7,8 @@ set -e ...@@ -7,8 +7,8 @@ set -e
eval $(go tool dist env) eval $(go tool dist env)
O=$GOCHAR O=$GOCHAR
GC="go tool ${O}g" GC="go tool compile"
LD="go tool ${O}l" LD="go tool link"
gccm="" gccm=""
case "$O" in case "$O" in
......
...@@ -26,11 +26,11 @@ func main() { ...@@ -26,11 +26,11 @@ func main() {
err = os.Chdir(filepath.Join("fixedbugs", "bug248.dir")) err = os.Chdir(filepath.Join("fixedbugs", "bug248.dir"))
check(err) check(err)
run("go", "tool", a+"g", "bug0.go") run("go", "tool", "compile", "bug0.go")
run("go", "tool", a+"g", "bug1.go") run("go", "tool", "compile", "bug1.go")
run("go", "tool", a+"g", "bug2.go") run("go", "tool", "compile", "bug2.go")
run(errchk, "go", "tool", a+"g", "-e", "bug3.go") run(errchk, "go", "tool", "compile", "-e", "bug3.go")
run("go", "tool", a+"l", "bug2."+a) run("go", "tool", "link", "bug2."+a)
run(fmt.Sprintf(".%c%s.out", filepath.Separator, a)) run(fmt.Sprintf(".%c%s.out", filepath.Separator, a))
os.Remove("bug0." + a) os.Remove("bug0." + a)
......
...@@ -23,9 +23,9 @@ func main() { ...@@ -23,9 +23,9 @@ func main() {
os.Exit(1) os.Exit(1)
} }
run("go", "tool", a+"g", filepath.Join("fixedbugs", "bug302.dir", "p.go")) run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
run("go", "tool", "pack", "grc", "pp.a", "p."+a) run("go", "tool", "pack", "grc", "pp.a", "p."+a)
run("go", "tool", a+"g", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go")) run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
os.Remove("p."+a) os.Remove("p."+a)
os.Remove("pp.a") os.Remove("pp.a")
os.Remove("main."+a) os.Remove("main."+a)
......
...@@ -26,8 +26,8 @@ func main() { ...@@ -26,8 +26,8 @@ func main() {
err = os.Chdir(filepath.Join(".", "fixedbugs", "bug345.dir")) err = os.Chdir(filepath.Join(".", "fixedbugs", "bug345.dir"))
check(err) check(err)
run("go", "tool", a+"g", "io.go") run("go", "tool", "compile", "io.go")
run(errchk, "go", "tool", a+"g", "-e", "main.go") run(errchk, "go", "tool", "compile", "-e", "main.go")
os.Remove("io." + a) os.Remove("io." + a)
} }
......
...@@ -24,10 +24,10 @@ func main() { ...@@ -24,10 +24,10 @@ func main() {
err = os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) err = os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
check(err) check(err)
run("go", "tool", a+"g", "-N", "-o", "slow."+a, "pkg.go") run("go", "tool", "compile", "-N", "-o", "slow."+a, "pkg.go")
run("go", "tool", a+"g", "-o", "fast."+a, "pkg.go") run("go", "tool", "compile", "-o", "fast."+a, "pkg.go")
run("go", "tool", a+"g", "-o", "main."+a, "main.go") run("go", "tool", "compile", "-o", "main."+a, "main.go")
run("go", "tool", a+"l", "-o", "a.exe", "main."+a) run("go", "tool", "link", "-o", "a.exe", "main."+a)
run("." + string(filepath.Separator) + "a.exe") run("." + string(filepath.Separator) + "a.exe")
os.Remove("slow." + a) os.Remove("slow." + a)
......
...@@ -26,7 +26,7 @@ func main() { ...@@ -26,7 +26,7 @@ func main() {
err = os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) err = os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
check(err) check(err)
out := run("go", "tool", a+"g", "-S", "a.go") out := run("go", "tool", "compile", "-S", "a.go")
os.Remove("a." + a) os.Remove("a." + a)
// 6g/8g print the offset as dec, but 5g/9g print the offset as hex. // 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
......
...@@ -193,7 +193,7 @@ func main() { ...@@ -193,7 +193,7 @@ func main() {
thechar = strings.TrimSpace(string(gochar)) thechar = strings.TrimSpace(string(gochar))
} }
version, err := exec.Command("go", "tool", thechar+"g", "-V").Output() version, err := exec.Command("go", "tool", "compile", "-V").Output()
if err != nil { if err != nil {
bug() bug()
fmt.Printf("running go tool %sg -V: %v\n", thechar, err) fmt.Printf("running go tool %sg -V: %v\n", thechar, err)
......
...@@ -41,9 +41,6 @@ var ( ...@@ -41,9 +41,6 @@ var (
) )
var ( var (
// gc and ld are [568][gl].
gc, ld string
// letter is the build.ArchChar // letter is the build.ArchChar
letter string letter string
...@@ -87,8 +84,6 @@ func main() { ...@@ -87,8 +84,6 @@ func main() {
var err error var err error
letter, err = build.ArchChar(build.Default.GOARCH) letter, err = build.ArchChar(build.Default.GOARCH)
check(err) check(err)
gc = letter + "g"
ld = letter + "l"
var tests []*test var tests []*test
if flag.NArg() > 0 { if flag.NArg() > 0 {
...@@ -192,11 +187,11 @@ func goFiles(dir string) []string { ...@@ -192,11 +187,11 @@ func goFiles(dir string) []string {
type runCmd func(...string) ([]byte, error) type runCmd func(...string) ([]byte, error)
func compileFile(runcmd runCmd, longname string) (out []byte, err error) { func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
return runcmd("go", "tool", gc, "-e", longname) return runcmd("go", "tool", "compile", "-e", longname)
} }
func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) { func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) {
cmd := []string{"go", "tool", gc, "-e", "-D", ".", "-I", "."} cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."}
for _, name := range names { for _, name := range names {
cmd = append(cmd, filepath.Join(dir, name)) cmd = append(cmd, filepath.Join(dir, name))
} }
...@@ -205,7 +200,7 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e ...@@ -205,7 +200,7 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e
func linkFile(runcmd runCmd, goname string) (err error) { func linkFile(runcmd runCmd, goname string) (err error) {
pfile := strings.Replace(goname, ".go", "."+letter, -1) pfile := strings.Replace(goname, ".go", "."+letter, -1)
_, err = runcmd("go", "tool", ld, "-w", "-o", "a.exe", "-L", ".", pfile) _, err = runcmd("go", "tool", "link", "-w", "-o", "a.exe", "-L", ".", pfile)
return return
} }
...@@ -506,7 +501,7 @@ func (t *test) run() { ...@@ -506,7 +501,7 @@ func (t *test) run() {
t.err = fmt.Errorf("unimplemented action %q", action) t.err = fmt.Errorf("unimplemented action %q", action)
case "errorcheck": case "errorcheck":
cmdline := []string{"go", "tool", gc, "-e", "-o", "a." + letter} cmdline := []string{"go", "tool", "compile", "-e", "-o", "a." + letter}
cmdline = append(cmdline, flags...) cmdline = append(cmdline, flags...)
cmdline = append(cmdline, long) cmdline = append(cmdline, long)
out, err := runcmd(cmdline...) out, err := runcmd(cmdline...)
...@@ -669,7 +664,7 @@ func (t *test) run() { ...@@ -669,7 +664,7 @@ func (t *test) run() {
t.err = fmt.Errorf("write tempfile:%s", err) t.err = fmt.Errorf("write tempfile:%s", err)
return return
} }
cmdline := []string{"go", "tool", gc, "-e", "-o", "a." + letter} cmdline := []string{"go", "tool", "compile", "-e", "-o", "a." + letter}
cmdline = append(cmdline, flags...) cmdline = append(cmdline, flags...)
cmdline = append(cmdline, tfile) cmdline = append(cmdline, tfile)
out, err = runcmd(cmdline...) out, err = runcmd(cmdline...)
......
...@@ -24,7 +24,7 @@ func main() { ...@@ -24,7 +24,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
cmd := exec.Command("go", "tool", letter+"g", "-S", "sinit.go") cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
fmt.Println(string(out)) fmt.Println(string(out))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment