mirror of
https://github.com/golang/go
synced 2024-11-19 14:24:47 -07:00
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>
This commit is contained in:
parent
d8ee5d11e5
commit
98f1bfbb18
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user