This patch to libgo modifies the gccgo version of the go tool to use a
builtin constant to set the gccgo compiler to use.  This will permit
the go tool built as part of a GCC build to use the gccgo compiler
built as part of the same build, rather than whatever gccgo happens to
be on PATH.  This patch also fixes assembly with the Go tool to pass
-c to the gccgo driver.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff -r 5155573fcd09 libgo/go/cmd/go/build.go
--- a/libgo/go/cmd/go/build.go  Wed Jan 07 07:37:24 2015 -0800
+++ b/libgo/go/cmd/go/build.go  Thu Jan 08 12:26:03 2015 -0800
@@ -1783,17 +1783,18 @@
 // The Gccgo toolchain.
 type gccgoToolchain struct{}
 
-var gccgoBin, _ = exec.LookPath("gccgo")
-
 func (gccgoToolchain) compiler() string {
-       return gccgoBin
+       if v := os.Getenv("GOC"); v != "" {
+               return v
+       }
+       return defaultGOC
 }
 
-func (gccgoToolchain) linker() string {
-       return gccgoBin
+func (tools gccgoToolchain) linker() string {
+       return tools.compiler()
 }
 
-func (gccgoToolchain) gc(b *builder, p *Package, archive, obj string, 
importArgs []string, gofiles []string) (ofile string, output []byte, err error) 
{
+func (tools gccgoToolchain) gc(b *builder, p *Package, archive, obj string, 
importArgs []string, gofiles []string) (ofile string, output []byte, err error) 
{
        out := p.Name + ".o"
        ofile = obj + out
        gcargs := []string{"-g"}
@@ -1804,7 +1805,7 @@
        if p.localPrefix != "" {
                gcargs = append(gcargs, 
"-fgo-relative-import-path="+p.localPrefix)
        }
-       args := stringList("gccgo", importArgs, "-c", gcargs, "-o", ofile, 
buildGccgoflags)
+       args := stringList(tools.compiler(), importArgs, "-c", gcargs, "-o", 
ofile, buildGccgoflags)
        for _, f := range gofiles {
                args = append(args, mkAbs(p.Dir, f))
        }
@@ -1813,14 +1814,14 @@
        return ofile, output, err
 }
 
-func (gccgoToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) 
error {
+func (tools gccgoToolchain) asm(b *builder, p *Package, obj, ofile, sfile 
string) error {
        sfile = mkAbs(p.Dir, sfile)
        defs := []string{"-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch}
        if pkgpath := gccgoCleanPkgpath(p); pkgpath != "" {
                defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`)
        }
        defs = append(defs, b.gccArchArgs()...)
-       return b.run(p.Dir, p.ImportPath, nil, "gccgo", "-I", obj, "-o", ofile, 
defs, sfile)
+       return b.run(p.Dir, p.ImportPath, nil, tools.compiler(), "-c", "-I", 
obj, "-o", ofile, defs, sfile)
 }
 
 func (gccgoToolchain) pkgpath(basedir string, p *Package) string {
@@ -1897,7 +1898,7 @@
        if objc {
                ldflags = append(ldflags, "-lobjc")
        }
-       return b.run(".", p.ImportPath, nil, "gccgo", "-o", out, ofiles, 
"-Wl,-(", ldflags, "-Wl,-)", buildGccgoflags)
+       return b.run(".", p.ImportPath, nil, tools.linker(), "-o", out, ofiles, 
"-Wl,-(", ldflags, "-Wl,-)", buildGccgoflags)
 }
 
 func (gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) 
error {

Reply via email to