Commit 98f1bfbb authored by Russ Cox's avatar Russ Cox

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: default avatarDavid Crawshaw <crawshaw@golang.org>
parent d8ee5d11
...@@ -151,40 +151,3 @@ func isGOROOT(path string) bool { ...@@ -151,40 +151,3 @@ func isGOROOT(path string) bool {
} }
return stat.IsDir() 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
}
...@@ -1103,7 +1103,7 @@ func LinkerDeps(p *Package) []string { ...@@ -1103,7 +1103,7 @@ func LinkerDeps(p *Package) []string {
deps := []string{"runtime"} deps := []string{"runtime"}
// External linking mode forces an import of runtime/cgo. // External linking mode forces an import of runtime/cgo.
if cfg.ExternalLinkingForced() { if externalLinkingForced() {
deps = append(deps, "runtime/cgo") deps = append(deps, "runtime/cgo")
} }
// On ARM with GOARM=5, it forces an import of math, for soft floating point. // On ARM with GOARM=5, it forces an import of math, for soft floating point.
...@@ -1122,6 +1122,43 @@ func LinkerDeps(p *Package) []string { ...@@ -1122,6 +1122,43 @@ func LinkerDeps(p *Package) []string {
return deps 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, // 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 // into a sorted list of absolute paths. It edits list in place but for
// convenience also returns list back to its caller. // convenience also returns list back to its caller.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment