Skip to content

Commit 5f5cae7

Browse files
author
Bryan C. Mills
committed
cmd/go: avoid indexing GOROOT packages when the compiler is 'gccgo'
The gccgo compiler does not load standard-library packages from GOROOT/src, so we cannot load those packages from the GOROOT/src index when using that compiler. This fixes TestScript/gccgo_link_c (and perhaps other gccgo tests) when a 'gccgo' executable is present. Unfortunately, only a few builders caught the broken test because 'gccgo' is not installed on most Go project builders (see #35786). For #53577. Fixes #53815. Change-Id: I11a5cf6dbf4ac9893c4d02bd6ab7ef60f67b1e87 Reviewed-on: https://go-review.googlesource.com/c/go/+/417094 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent c2edb2c commit 5f5cae7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/cmd/go/internal/modindex/read.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func GetPackage(modroot, pkgdir string) (*IndexPackage, error) {
139139
if !errors.Is(err, errNotFromModuleCache) {
140140
return nil, err
141141
}
142+
if cfg.BuildContext.Compiler == "gccgo" && str.HasPathPrefix(modroot, cfg.GOROOTsrc) {
143+
return nil, err // gccgo has no sources for GOROOT packages.
144+
}
142145
return openIndexPackage(modroot, pkgdir)
143146
}
144147

src/go/build/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
715715
tried.goroot = dir
716716
}
717717
if ctxt.Compiler == "gccgo" && goroot.IsStandardPackage(ctxt.GOROOT, ctxt.Compiler, path) {
718+
// TODO(bcmills): Setting p.Dir here is misleading, because gccgo
719+
// doesn't actually load its standard-library packages from this
720+
// directory. See if we can leave it unset.
718721
p.Dir = ctxt.joinPath(ctxt.GOROOT, "src", path)
719722
p.Goroot = true
720723
p.Root = ctxt.GOROOT

0 commit comments

Comments
 (0)