From 1279f21fc520cc8c91ef4dd3a8938b7aa256d799 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 14 Jun 2017 13:56:04 +0000 Subject: [PATCH] cmd/go: gccgo: consistent results, fix vendoring Pass the -fdebug-prefix-map and -gno-record-gcc-switches compiler options to gccgo to generate consistent results. Fix the vendoring code to look for /vendor/, not just /vendor, to avoid being confused by something like vendor/vendor.org. Tested by the cmd/go tests in a followup CL. Reviewed-on: https://go-review.googlesource.com/45695 From-SVN: r249198 --- gcc/go/gofrontend/MERGE | 2 +- libgo/go/cmd/go/build.go | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 0c1a5cfca69..f1055bcb17d 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -6b08348d905bf84a91b8d693ee01b30e8bf18ccf +bc785455a35bfa7d4b0a66781c7c3ef08a24a845 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/cmd/go/build.go b/libgo/go/cmd/go/build.go index 4b9150583ee..7e98379675f 100644 --- a/libgo/go/cmd/go/build.go +++ b/libgo/go/cmd/go/build.go @@ -2692,6 +2692,8 @@ func (tools gccgoToolchain) gc(b *builder, p *Package, archive, obj string, asmh ofile = obj + out gcargs := []string{"-g"} gcargs = append(gcargs, b.gccArchArgs()...) + gcargs = append(gcargs, "-fdebug-prefix-map="+b.work+"=/tmp/go-build") + gcargs = append(gcargs, "-gno-record-gcc-switches") if pkgpath := gccgoPkgpath(p); pkgpath != "" { gcargs = append(gcargs, "-fgo-pkgpath="+pkgpath) } @@ -2707,14 +2709,14 @@ func (tools gccgoToolchain) gc(b *builder, p *Package, archive, obj string, asmh for _, path := range p.Imports { // If this is a new vendor path, add it to the list of importArgs - if i := strings.LastIndex(path, "/vendor"); i >= 0 { + if i := strings.LastIndex(path, "/vendor/"); i >= 0 { for _, dir := range savedirs { // Check if the vendor path is already included in dir - if strings.HasSuffix(dir, path[:i+len("/vendor")]) { + if strings.HasSuffix(dir, path[:i+len("/vendor/")]) { continue } // Make sure this vendor path is not already in the list for importArgs - vendorPath := dir + "/" + path[:i+len("/vendor")] + vendorPath := dir + "/" + path[:i+len("/vendor/")] for _, imp := range importArgs { if imp == "-I" { continue @@ -2788,7 +2790,12 @@ func (gccgoToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles for _, f := range ofiles { absOfiles = append(absOfiles, mkAbs(objDir, f)) } - return b.run(p.Dir, p.ImportPath, nil, "ar", "rc", mkAbs(objDir, afile), absOfiles) + absAfile := mkAbs(objDir, afile) + // Try with D modifier first, then without if that fails. + if b.run(p.Dir, p.ImportPath, nil, "ar", "rcD", absAfile, absOfiles) != nil { + return b.run(p.Dir, p.ImportPath, nil, "ar", "rc", absAfile, absOfiles) + } + return nil } func (tools gccgoToolchain) link(b *builder, root *action, out string, allactions []*action, mainpkg string, ofiles []string, buildmode, desc string) error { @@ -3080,6 +3087,12 @@ func (tools gccgoToolchain) cc(b *builder, p *Package, objdir, ofile, cfile stri defs = append(defs, "-fsplit-stack") } defs = tools.maybePIC(defs) + if b.gccSupportsFlag("-fdebug-prefix-map=a=b") { + defs = append(defs, "-fdebug-prefix-map="+b.work+"=/tmp/go-build") + } + if b.gccSupportsFlag("-gno-record-gcc-switches") { + defs = append(defs, "-gno-record-gcc-switches") + } return b.run(p.Dir, p.ImportPath, nil, envList("CC", defaultCC), "-Wall", "-g", "-I", objdir, "-I", inc, "-o", ofile, defs, "-c", cfile) } -- 2.30.2