cmd/go: pass down testing gccgo in TestScript

This permits TestScript to work when gccgo is not installed.
Previous testing was using a previously installed gccgo, not the newly
built one.

This revealed that the testing of whether an internal package is
permitted was incorrect for standard library packages, since the
uninstalled gccgo can see internal packages in the uninstalled libgo.
Fix the internal package tests.

This permitted removing a couple of gccgo-specific changes in the
testsuite.

Change-Id: I8029cd73eba94c0b711f47af0df96f673489efc2
Reviewed-on: https://go-review.googlesource.com/137255
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/libgo/go/cmd/go/internal/load/pkg.go b/libgo/go/cmd/go/internal/load/pkg.go
index 0579fd5..b6c9037 100644
--- a/libgo/go/cmd/go/internal/load/pkg.go
+++ b/libgo/go/cmd/go/internal/load/pkg.go
@@ -953,8 +953,14 @@
 	}
 
 	// We can't check standard packages with gccgo.
-	if cfg.BuildContext.Compiler == "gccgo" && p.Standard {
-		return p
+	if cfg.BuildContext.Compiler == "gccgo" {
+		if importer == nil {
+			if p.Standard {
+				return p
+			}
+		} else if importer.Standard || strings.HasPrefix(importerPath, "cmd/") {
+			return p
+		}
 	}
 
 	// The stack includes p.ImportPath.
diff --git a/libgo/go/cmd/go/script_test.go b/libgo/go/cmd/go/script_test.go
index 02cb17b..9e958e0 100644
--- a/libgo/go/cmd/go/script_test.go
+++ b/libgo/go/cmd/go/script_test.go
@@ -78,6 +78,7 @@
 
 	// For gccgo testing.
 	"GO_TESTING_GOTOOLS",
+	"GCCGO",
 	"GCCGOTOOLDIR",
 }
 
diff --git a/libgo/go/cmd/go/testdata/script/mod_internal.txt b/libgo/go/cmd/go/testdata/script/mod_internal.txt
index 84e77c6..72706fd 100644
--- a/libgo/go/cmd/go/testdata/script/mod_internal.txt
+++ b/libgo/go/cmd/go/testdata/script/mod_internal.txt
@@ -16,11 +16,11 @@
 
 # Internal packages in the standard library should not leak into modules.
 ! go build ./fromstd
-[!gccgo] stderr 'use of internal package internal/testenv not allowed'
+stderr 'use of internal package internal/testenv not allowed'
 
 # Packages found via standard-library vendoring should not leak.
 ! go build ./fromstdvendor
-[!gccgo] stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
+stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
 
 env GO111MODULE=off
 ! go build ./fromstdvendor