From 98f1bfbb180b30e899b27ef5c5f53d16138dbd86 Mon Sep 17 00:00:00 2001
From: Russ Cox <rsc@golang.org>
Date: Tue, 7 Nov 2017 20:39:54 -0500
Subject: [PATCH] cmd/go: move cfg.ExternalLinkingForced to internal/load

It needs to refer to packages, so it can no longer be in cfg.
No semantic changes here.

Can now be unexported, so that was a net win anyway.

Change-Id: I58bf6cdcd435e6e019291bb8dcd5d5b7f1ac03a3
Reviewed-on: https://go-review.googlesource.com/76550
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
---
 src/cmd/go/internal/cfg/cfg.go  | 37 -------------------------------
 src/cmd/go/internal/load/pkg.go | 39 ++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index 5f93f39f90..ab20c20e2f 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -151,40 +151,3 @@ func isGOROOT(path string) bool {
 	}
 	return stat.IsDir()
 }
-
-// ExternalLinkingForced reports whether external linking is being
-// forced even for programs that do not use cgo.
-func ExternalLinkingForced() bool {
-	// Some targets must use external linking even inside GOROOT.
-	switch BuildContext.GOOS {
-	case "android":
-		return true
-	case "darwin":
-		switch BuildContext.GOARCH {
-		case "arm", "arm64":
-			return true
-		}
-	}
-
-	if !BuildContext.CgoEnabled {
-		return false
-	}
-	// Currently build modes c-shared, pie (on systems that do not
-	// support PIE with internal linking mode (currently all
-	// systems: issue #18968)), plugin, and -linkshared force
-	// external linking mode, as of course does
-	// -ldflags=-linkmode=external. External linking mode forces
-	// an import of runtime/cgo.
-	pieCgo := BuildBuildmode == "pie"
-	linkmodeExternal := false
-	for i, a := range BuildLdflags {
-		if a == "-linkmode=external" {
-			linkmodeExternal = true
-		}
-		if a == "-linkmode" && i+1 < len(BuildLdflags) && BuildLdflags[i+1] == "external" {
-			linkmodeExternal = true
-		}
-	}
-
-	return BuildBuildmode == "c-shared" || BuildBuildmode == "plugin" || pieCgo || BuildLinkshared || linkmodeExternal
-}
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index dfc5fa51f4..1752f7de66 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -1103,7 +1103,7 @@ func LinkerDeps(p *Package) []string {
 	deps := []string{"runtime"}
 
 	// External linking mode forces an import of runtime/cgo.
-	if cfg.ExternalLinkingForced() {
+	if externalLinkingForced() {
 		deps = append(deps, "runtime/cgo")
 	}
 	// On ARM with GOARM=5, it forces an import of math, for soft floating point.
@@ -1122,6 +1122,43 @@ func LinkerDeps(p *Package) []string {
 	return deps
 }
 
+// externalLinkingForced reports whether external linking is being
+// forced even for programs that do not use cgo.
+func externalLinkingForced() bool {
+	// Some targets must use external linking even inside GOROOT.
+	switch cfg.BuildContext.GOOS {
+	case "android":
+		return true
+	case "darwin":
+		switch cfg.BuildContext.GOARCH {
+		case "arm", "arm64":
+			return true
+		}
+	}
+
+	if !cfg.BuildContext.CgoEnabled {
+		return false
+	}
+	// Currently build modes c-shared, pie (on systems that do not
+	// support PIE with internal linking mode (currently all
+	// systems: issue #18968)), plugin, and -linkshared force
+	// external linking mode, as of course does
+	// -ldflags=-linkmode=external. External linking mode forces
+	// an import of runtime/cgo.
+	pieCgo := cfg.BuildBuildmode == "pie"
+	linkmodeExternal := false
+	for i, a := range cfg.BuildLdflags {
+		if a == "-linkmode=external" {
+			linkmodeExternal = true
+		}
+		if a == "-linkmode" && i+1 < len(cfg.BuildLdflags) && cfg.BuildLdflags[i+1] == "external" {
+			linkmodeExternal = true
+		}
+	}
+
+	return cfg.BuildBuildmode == "c-shared" || cfg.BuildBuildmode == "plugin" || pieCgo || cfg.BuildLinkshared || linkmodeExternal
+}
+
 // mkAbs rewrites list, which must be paths relative to p.Dir,
 // into a sorted list of absolute paths. It edits list in place but for
 // convenience also returns list back to its caller.
-- 
2.30.9