]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: don't crash when running "go version" in deleted directory
authorPhilipp Sauter <sauterp@protonmail.com>
Sun, 8 Nov 2020 21:12:38 +0000 (22:12 +0100)
committerBryan C. Mills <bcmills@google.com>
Wed, 5 May 2021 01:28:34 +0000 (01:28 +0000)
If the go command is executed on Linux in a deleted directory,
it fails. This behavior is reasonable for commands which depend on
the CWD, but it's unexpected for commands like `go version`.
This change delays initialization of a global CWD variable.

Fixed #34499

Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/268261
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

19 files changed:
src/cmd/go/go_test.go
src/cmd/go/internal/base/path.go
src/cmd/go/internal/envcmd/env.go
src/cmd/go/internal/fsys/fsys.go
src/cmd/go/internal/get/get.go
src/cmd/go/internal/load/flag.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/search/search.go
src/cmd/go/internal/test/cover.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/test/testflag.go
src/cmd/go/internal/work/action.go
src/cmd/go/internal/work/build_test.go
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/gccgo.go
src/cmd/go/internal/work/init.go

index 5a657bcfcafaa24113b900819df58fcfee327707..ff397a1995d7ee13622421d4cd6db6ec418c8999 100644 (file)
@@ -2832,3 +2832,25 @@ func TestCoverpkgTestOnly(t *testing.T) {
        tg.grepStderrNot("no packages being tested depend on matches", "bad match message")
        tg.grepStdout("coverage: 100", "no coverage")
 }
+
+// Regression test for golang.org/issue/34499: version command should not crash
+// when executed in a deleted directory on Linux.
+func TestExecInDeletedDir(t *testing.T) {
+       // The crash has only been reproduced on Linux.
+       if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
+               t.Skip()
+       }
+       tg := testgo(t)
+       defer tg.cleanup()
+
+       wd, err := os.Getwd()
+       tg.check(err)
+       tg.makeTempdir()
+       tg.check(os.Chdir(tg.tempdir))
+       defer func() { tg.check(os.Chdir(wd)) }()
+
+       tg.check(os.Remove(tg.tempdir))
+
+       // `go version` should not fail
+       tg.run("version")
+}
index cb4adbde42a2dad323159f85731faccf2c7529e3..4d8715ef5fe002a349d83e956eb4493e9c698fe0 100644 (file)
@@ -8,21 +8,27 @@ import (
        "os"
        "path/filepath"
        "strings"
+       "sync"
 )
 
-func getwd() string {
-       wd, err := os.Getwd()
-       if err != nil {
-               Fatalf("cannot determine current directory: %v", err)
-       }
-       return wd
-}
+var cwd string
+var cwdOnce sync.Once
 
-var Cwd = getwd()
+// Cwd returns the current working directory at the time of the first call.
+func Cwd() string {
+       cwdOnce.Do(func() {
+               var err error
+               cwd, err = os.Getwd()
+               if err != nil {
+                       Fatalf("cannot determine current directory: %v", err)
+               }
+       })
+       return cwd
+}
 
 // ShortPath returns an absolute or relative name for path, whatever is shorter.
 func ShortPath(path string) string {
-       if rel, err := filepath.Rel(Cwd, path); err == nil && len(rel) < len(path) {
+       if rel, err := filepath.Rel(Cwd(), path); err == nil && len(rel) < len(path) {
                return rel
        }
        return path
@@ -33,7 +39,7 @@ func ShortPath(path string) string {
 func RelPaths(paths []string) []string {
        var out []string
        for _, p := range paths {
-               rel, err := filepath.Rel(Cwd, p)
+               rel, err := filepath.Rel(Cwd(), p)
                if err == nil && len(rel) < len(p) {
                        p = rel
                }
index 8dbb8af1e75b5bcbaa3c9579ec97c8470ec3a425..b30c37ab27c1a4c14791fd841accbe29f5f9c311 100644 (file)
@@ -200,7 +200,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
        env := cfg.CmdEnv
        env = append(env, ExtraEnvVars()...)
 
-       if err := fsys.Init(base.Cwd); err != nil {
+       if err := fsys.Init(base.Cwd()); err != nil {
                base.Fatalf("go: %v", err)
        }
 
index ae10946fb1a686cec4003363306c519b27375822..0b806027e6469a3cac3b19e2e5e162b7ead8e92d 100644 (file)
@@ -44,7 +44,7 @@ func (n *node) isDeleted() bool {
 
 // TODO(matloob): encapsulate these in an io/fs-like interface
 var overlay map[string]*node // path -> file or directory node
-var cwd string               // copy of base.Cwd to avoid dependency
+var cwd string               // copy of base.Cwd() to avoid dependency
 
 // Canonicalize a path for looking it up in the overlay.
 // Important: filepath.Join(cwd, path) doesn't always produce
index c28bce8cfcdd31c3c0e1ecbed625f840448009d9..3c16dc3040facba13a7a59416268ae7944250599 100644 (file)
@@ -258,7 +258,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
        load1 := func(path string, mode int) *load.Package {
                if parent == nil {
                        mode := 0 // don't do module or vendor resolution
-                       return load.LoadImport(context.TODO(), load.PackageOpts{}, path, base.Cwd, nil, stk, nil, mode)
+                       return load.LoadImport(context.TODO(), load.PackageOpts{}, path, base.Cwd(), nil, stk, nil, mode)
                }
                return load.LoadImport(context.TODO(), load.PackageOpts{}, path, parent.Dir, parent, stk, nil, mode|load.ResolveModule)
        }
index 7534e65f54c75309ee5fc3bcbe4fa3222481f9d0..440cb86134489a7e023ce516629fe9bccc00fe0c 100644 (file)
@@ -34,7 +34,7 @@ type ppfValue struct {
 
 // Set is called each time the flag is encountered on the command line.
 func (f *PerPackageFlag) Set(v string) error {
-       return f.set(v, base.Cwd)
+       return f.set(v, base.Cwd())
 }
 
 // set is the implementation of Set, taking a cwd (current working directory) for easier testing.
index 2d91d1058366f351212a2372ae670b8b98baf371..153399d83e6ac68412c695cfa0253922713ca546 100644 (file)
@@ -603,7 +603,7 @@ func ReloadPackageNoFlags(arg string, stk *ImportStack) *Package {
                })
                packageDataCache.Delete(p.ImportPath)
        }
-       return LoadImport(context.TODO(), PackageOpts{}, arg, base.Cwd, nil, stk, nil, 0)
+       return LoadImport(context.TODO(), PackageOpts{}, arg, base.Cwd(), nil, stk, nil, 0)
 }
 
 // dirToImportPath returns the pseudo-import path we use for a package
@@ -991,7 +991,7 @@ func (pre *preload) preloadMatches(ctx context.Context, opts PackageOpts, matche
                        case pre.sema <- struct{}{}:
                                go func(pkg string) {
                                        mode := 0 // don't use vendoring or module import resolution
-                                       bp, loaded, err := loadPackageData(ctx, pkg, "", base.Cwd, "", false, mode)
+                                       bp, loaded, err := loadPackageData(ctx, pkg, "", base.Cwd(), "", false, mode)
                                        <-pre.sema
                                        if bp != nil && loaded && err == nil && !opts.IgnoreImports {
                                                pre.preloadImports(ctx, opts, bp.Imports, bp)
@@ -2456,7 +2456,7 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
                        if pkg == "" {
                                panic(fmt.Sprintf("ImportPaths returned empty package for pattern %s", m.Pattern()))
                        }
-                       p := loadImport(ctx, opts, pre, pkg, base.Cwd, nil, &stk, nil, 0)
+                       p := loadImport(ctx, opts, pre, pkg, base.Cwd(), nil, &stk, nil, 0)
                        p.Match = append(p.Match, m.Pattern())
                        p.Internal.CmdlinePkg = true
                        if m.IsLiteral() {
@@ -2670,7 +2670,7 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa
 
        var err error
        if dir == "" {
-               dir = base.Cwd
+               dir = base.Cwd()
        }
        dir, err = filepath.Abs(dir)
        if err != nil {
index 99c0c2b9811aaca1918954ea5d1731810f4603c7..5cdea12cd3e2be5eebbe414dc1948f44f98e802f 100644 (file)
@@ -135,7 +135,7 @@ func Init() {
                return
        }
 
-       if err := fsys.Init(base.Cwd); err != nil {
+       if err := fsys.Init(base.Cwd()); err != nil {
                base.Fatalf("go: %v", err)
        }
 
@@ -179,7 +179,7 @@ func Init() {
                }
                modRoot = ""
        } else {
-               modRoot = findModuleRoot(base.Cwd)
+               modRoot = findModuleRoot(base.Cwd())
                if modRoot == "" {
                        if cfg.ModFile != "" {
                                base.Fatalf("go: cannot find main module, but -modfile was set.\n\t-modfile cannot be used to set the module root directory.")
@@ -276,7 +276,7 @@ func WillBeEnabled() bool {
                return false
        }
 
-       if modRoot := findModuleRoot(base.Cwd); modRoot == "" {
+       if modRoot := findModuleRoot(base.Cwd()); modRoot == "" {
                // GO111MODULE is 'auto', and we can't find a module root.
                // Stay in GOPATH mode.
                return false
@@ -335,8 +335,8 @@ func die() {
        if cfg.Getenv("GO111MODULE") == "off" {
                base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
        }
-       if dir, name := findAltConfig(base.Cwd); dir != "" {
-               rel, err := filepath.Rel(base.Cwd, dir)
+       if dir, name := findAltConfig(base.Cwd()); dir != "" {
+               rel, err := filepath.Rel(base.Cwd(), dir)
                if err != nil {
                        rel = dir
                }
@@ -479,7 +479,7 @@ func loadModFile(ctx context.Context) (rs *Requirements, needCommit bool) {
 // exactly the same as in the legacy configuration (for example, we can't get
 // packages at multiple versions from the same module).
 func CreateModFile(ctx context.Context, modPath string) {
-       modRoot = base.Cwd
+       modRoot = base.Cwd()
        Init()
        modFilePath := ModFilePath()
        if _, err := fsys.Stat(modFilePath); err == nil {
@@ -646,7 +646,7 @@ func initTarget(m module.Version) {
        Target = m
        targetPrefix = m.Path
 
-       if rel := search.InDir(base.Cwd, cfg.GOROOTsrc); rel != "" {
+       if rel := search.InDir(base.Cwd(), cfg.GOROOTsrc); rel != "" {
                targetInGorootSrc = true
                if m.Path == "std" {
                        // The "std" module in GOROOT/src is the Go standard library. Unlike other
index c811029ab57548cb8518ac76d4982c222af2de64..f30ac6e0c8bf77f4fb964c5e8f58de46c2efd9bf 100644 (file)
@@ -407,7 +407,7 @@ func matchLocalDirs(ctx context.Context, m *search.Match, rs *Requirements) {
                dir := filepath.Dir(filepath.Clean(m.Pattern()[:i+3]))
                absDir := dir
                if !filepath.IsAbs(dir) {
-                       absDir = filepath.Join(base.Cwd, dir)
+                       absDir = filepath.Join(base.Cwd(), dir)
                }
                if search.InDir(absDir, cfg.GOROOTsrc) == "" && search.InDir(absDir, ModRoot()) == "" && pathInModuleCache(ctx, absDir, rs) == "" {
                        m.Dirs = []string{}
@@ -425,7 +425,7 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str
        if filepath.IsAbs(dir) {
                absDir = filepath.Clean(dir)
        } else {
-               absDir = filepath.Join(base.Cwd, dir)
+               absDir = filepath.Join(base.Cwd(), dir)
        }
 
        bp, err := cfg.BuildContext.ImportDir(absDir, 0)
@@ -632,7 +632,7 @@ func DirImportPath(ctx context.Context, dir string) string {
        LoadModFile(ctx) // Sets targetPrefix.
 
        if !filepath.IsAbs(dir) {
-               dir = filepath.Join(base.Cwd, dir)
+               dir = filepath.Join(base.Cwd(), dir)
        } else {
                dir = filepath.Clean(dir)
        }
index f1152080a7e7293a4999e42fc182c05bdf6adbb1..a0c806a259329c27c2f45739e1250550bec04f06 100644 (file)
@@ -445,7 +445,7 @@ func ImportPathsQuiet(patterns []string) []*Match {
                        for i, dir := range m.Dirs {
                                absDir := dir
                                if !filepath.IsAbs(dir) {
-                                       absDir = filepath.Join(base.Cwd, dir)
+                                       absDir = filepath.Join(base.Cwd(), dir)
                                }
                                if bp, _ := cfg.BuildContext.ImportDir(absDir, build.FindOnly); bp.ImportPath != "" && bp.ImportPath != "." {
                                        m.Pkgs[i] = bp.ImportPath
index 9841791552dbbc125afa5b3fa4e193a62d4aaad1..657d22a6b4d2ff8a7a1d69c6e2ed76e6c869c3e6 100644 (file)
@@ -26,8 +26,8 @@ func initCoverProfile() {
        if testCoverProfile == "" || testC {
                return
        }
-       if !filepath.IsAbs(testCoverProfile) && testOutputDir != "" {
-               testCoverProfile = filepath.Join(testOutputDir, testCoverProfile)
+       if !filepath.IsAbs(testCoverProfile) {
+               testCoverProfile = filepath.Join(testOutputDir.getAbs(), testCoverProfile)
        }
 
        // No mutex - caller's responsibility to call with no racing goroutines.
index c2f8aed00407983add251eb46ab470e70def8c3d..59ea1ef5445178f052006dd37af2d8b0b209b9ef 100644 (file)
@@ -486,7 +486,7 @@ var (
        testJSON         bool                              // -json flag
        testList         string                            // -list flag
        testO            string                            // -o flag
-       testOutputDir    = base.Cwd                        // -outputdir flag
+       testOutputDir    outputdirFlag                     // -outputdir flag
        testShuffle      shuffleFlag                       // -shuffle flag
        testTimeout      time.Duration                     // -timeout flag
        testV            bool                              // -v flag
@@ -710,7 +710,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
                match := make([]func(*load.Package) bool, len(testCoverPaths))
                matched := make([]bool, len(testCoverPaths))
                for i := range testCoverPaths {
-                       match[i] = load.MatchPackage(testCoverPaths[i], base.Cwd)
+                       match[i] = load.MatchPackage(testCoverPaths[i], base.Cwd())
                }
 
                // Select for coverage all dependencies matching the testCoverPaths patterns.
@@ -945,11 +945,11 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
        var installAction, cleanAction *work.Action
        if testC || testNeedBinary() {
                // -c or profiling flag: create action to copy binary to ./test.out.
-               target := filepath.Join(base.Cwd, testBinary+cfg.ExeSuffix)
+               target := filepath.Join(base.Cwd(), testBinary+cfg.ExeSuffix)
                if testO != "" {
                        target = testO
                        if !filepath.IsAbs(target) {
-                               target = filepath.Join(base.Cwd, target)
+                               target = filepath.Join(base.Cwd(), target)
                        }
                }
                if target == os.DevNull {
index 6ed96a36d0a541fff3fc8f455581d3391c30da69..08f1efa2c0d26a0cf398f2b778c0adde90fc97ae 100644 (file)
@@ -62,7 +62,7 @@ func init() {
        cf.String("memprofilerate", "", "")
        cf.StringVar(&testMutexProfile, "mutexprofile", "", "")
        cf.String("mutexprofilefraction", "", "")
-       cf.Var(outputdirFlag{&testOutputDir}, "outputdir", "")
+       cf.Var(&testOutputDir, "outputdir", "")
        cf.Int("parallel", 0, "")
        cf.String("run", "", "")
        cf.Bool("short", false, "")
@@ -71,7 +71,7 @@ func init() {
        cf.BoolVar(&testV, "v", false, "")
        cf.Var(&testShuffle, "shuffle", "")
 
-       for name, _ := range passFlagToTest {
+       for name := range passFlagToTest {
                cf.Var(cf.Lookup(name).Value, "test."+name, "")
        }
 }
@@ -128,19 +128,26 @@ func (f stringFlag) Set(value string) error {
 // outputdirFlag implements the -outputdir flag.
 // It interprets an empty value as the working directory of the 'go' command.
 type outputdirFlag struct {
-       resolved *string
+       abs string
 }
 
-func (f outputdirFlag) String() string { return *f.resolved }
-func (f outputdirFlag) Set(value string) (err error) {
+func (f *outputdirFlag) String() string {
+       return f.abs
+}
+func (f *outputdirFlag) Set(value string) (err error) {
        if value == "" {
-               // The empty string implies the working directory of the 'go' command.
-               *f.resolved = base.Cwd
+               f.abs = ""
        } else {
-               *f.resolved, err = filepath.Abs(value)
+               f.abs, err = filepath.Abs(value)
        }
        return err
 }
+func (f *outputdirFlag) getAbs() string {
+       if f.abs == "" {
+               return base.Cwd()
+       }
+       return f.abs
+}
 
 // vetFlag implements the special parsing logic for the -vet flag:
 // a comma-separated list, with a distinguished value "off" and
@@ -404,7 +411,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
        // command. Set it explicitly if it is needed due to some other flag that
        // requests output.
        if testProfile() != "" && !outputDirSet {
-               injectedFlags = append(injectedFlags, "-test.outputdir="+testOutputDir)
+               injectedFlags = append(injectedFlags, "-test.outputdir="+testOutputDir.getAbs())
        }
 
        // If the user is explicitly passing -help or -h, show output
index 9d141ae233dfcdb1410d3633007f5698ea2a0365..69940cb00159b64c60024a9f248e5a0db337b266 100644 (file)
@@ -344,7 +344,7 @@ func readpkglist(shlibpath string) (pkgs []*load.Package) {
                        if strings.HasPrefix(t, "pkgpath ") {
                                t = strings.TrimPrefix(t, "pkgpath ")
                                t = strings.TrimSuffix(t, ";")
-                               pkgs = append(pkgs, load.LoadImportWithFlags(t, base.Cwd, nil, &stk, nil, 0))
+                               pkgs = append(pkgs, load.LoadImportWithFlags(t, base.Cwd(), nil, &stk, nil, 0))
                        }
                }
        } else {
@@ -355,7 +355,7 @@ func readpkglist(shlibpath string) (pkgs []*load.Package) {
                scanner := bufio.NewScanner(bytes.NewBuffer(pkglistbytes))
                for scanner.Scan() {
                        t := scanner.Text()
-                       pkgs = append(pkgs, load.LoadImportWithFlags(t, base.Cwd, nil, &stk, nil, 0))
+                       pkgs = append(pkgs, load.LoadImportWithFlags(t, base.Cwd(), nil, &stk, nil, 0))
                }
        }
        return
@@ -776,7 +776,7 @@ func (b *Builder) linkSharedAction(mode, depMode BuildMode, shlib string, a1 *Ac
                                        }
                                }
                                var stk load.ImportStack
-                               p := load.LoadImportWithFlags(pkg, base.Cwd, nil, &stk, nil, 0)
+                               p := load.LoadImportWithFlags(pkg, base.Cwd(), nil, &stk, nil, 0)
                                if p.Error != nil {
                                        base.Fatalf("load %s: %v", pkg, p.Error)
                                }
index eaf2639e9e0deaa5e43f1acadb279bc146c4d1b7..600fc3083f0d506228fe1e26797013f94e11607b 100644 (file)
@@ -173,10 +173,11 @@ func TestSharedLibName(t *testing.T) {
                                if err != nil {
                                        t.Fatal(err)
                                }
+                               cwd := base.Cwd()
                                oldGopath := cfg.BuildContext.GOPATH
                                defer func() {
                                        cfg.BuildContext.GOPATH = oldGopath
-                                       os.Chdir(base.Cwd)
+                                       os.Chdir(cwd)
                                        err := os.RemoveAll(tmpGopath)
                                        if err != nil {
                                                t.Error(err)
index 994c4dafcf5156a9d4671043223299500dc4b292..b506b836561cb3465008e8586efbe432d19709e4 100644 (file)
@@ -2377,7 +2377,7 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag
 
        cmdargs := []interface{}{cmd, "-o", outfile, objs, flags}
        dir := p.Dir
-       out, err := b.runOut(a, base.Cwd, b.cCompilerEnv(), cmdargs...)
+       out, err := b.runOut(a, base.Cwd(), b.cCompilerEnv(), cmdargs...)
 
        if len(out) > 0 {
                // Filter out useless linker warnings caused by bugs outside Go.
@@ -2991,7 +2991,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
        if p.Standard && p.ImportPath == "runtime/cgo" {
                cgoflags = []string{"-dynlinker"} // record path to dynamic linker
        }
-       return b.run(a, base.Cwd, p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
+       return b.run(a, base.Cwd(), p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
 }
 
 // Run SWIG on all SWIG input files.
index 9adcf3035f43d69f153f37c0f410ad14f7f7bed4..85da4f89f991f48e4ad9a3aad4b145f622363cb1 100644 (file)
@@ -197,7 +197,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg
                args = append(args, f)
        }
 
-       output, err = b.runOut(a, base.Cwd, nil, args...)
+       output, err = b.runOut(a, base.Cwd(), nil, args...)
        return ofile, output, err
 }
 
index b58c8aa8854a459a53f5226a322eee342af296ab..1499536932d2cf94fef56715aec3b08c39be0022 100644 (file)
@@ -102,7 +102,7 @@ func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg,
 
        if b.gccSupportsFlag(args[:1], "-ffile-prefix-map=a=b") {
                if cfg.BuildTrimpath {
-                       args = append(args, "-ffile-prefix-map="+base.Cwd+"=.")
+                       args = append(args, "-ffile-prefix-map="+base.Cwd()+"=.")
                        args = append(args, "-ffile-prefix-map="+b.WorkDir+"=/tmp/go-build")
                }
                if fsys.OverlayFile != "" {
@@ -114,9 +114,9 @@ func (tools gccgoToolchain) gc(b *Builder, a *Action, archive string, importcfg,
                                }
                                toPath := absPath
                                // gccgo only applies the last matching rule, so also handle the case where
-                               // BuildTrimpath is true and the path is relative to base.Cwd.
-                               if cfg.BuildTrimpath && str.HasFilePathPrefix(toPath, base.Cwd) {
-                                       toPath = "." + toPath[len(base.Cwd):]
+                               // BuildTrimpath is true and the path is relative to base.Cwd().
+                               if cfg.BuildTrimpath && str.HasFilePathPrefix(toPath, base.Cwd()) {
+                                       toPath = "." + toPath[len(base.Cwd()):]
                                }
                                args = append(args, "-ffile-prefix-map="+overlayPath+"="+toPath)
                        }
@@ -572,7 +572,7 @@ func (tools gccgoToolchain) cc(b *Builder, a *Action, ofile, cfile string) error
        }
        defs = tools.maybePIC(defs)
        if b.gccSupportsFlag(compiler, "-ffile-prefix-map=a=b") {
-               defs = append(defs, "-ffile-prefix-map="+base.Cwd+"=.")
+               defs = append(defs, "-ffile-prefix-map="+base.Cwd()+"=.")
                defs = append(defs, "-ffile-prefix-map="+b.WorkDir+"=/tmp/go-build")
        } else if b.gccSupportsFlag(compiler, "-fdebug-prefix-map=a=b") {
                defs = append(defs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build")
index ca7e04d280bfaecb5461aa838456ed675f9a4d10..37a3e2d0ffd1232368863992603432fbd783e828 100644 (file)
@@ -23,7 +23,7 @@ func BuildInit() {
        modload.Init()
        instrumentInit()
        buildModeInit()
-       if err := fsys.Init(base.Cwd); err != nil {
+       if err := fsys.Init(base.Cwd()); err != nil {
                base.Fatalf("go: %v", err)
        }