mirror of
https://github.com/golang/go
synced 2024-11-24 02:50:11 -07:00
cmd/go: depend on runtime/cgo if external linking mode is forced
In external linking mode, the linker automatically imports runtime/cgo. When the user uses non-standard compilation options, they have to know to run go install runtime/cgo. When the go tool adds non-standard compilation options itself, we can't force the user to do that. So add the dependency ourselves. Bad news: we don't currently have a clean way to know whether we are going to use external linking mode. This CL duplicates logic split between cmd/6l and cmd/internal/ld. Good news: adding an unnecessary dependency on runtime/cgo does no real harm. We aren't going to force the linker to pull it in, we're just going to build it so that its available if the linker wants it. Change-Id: Ide676339d4e8b1c3d9792884a2cea921abb281b7 Reviewed-on: https://go-review.googlesource.com/9115 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
e00e65638a
commit
af161c577c
@ -425,6 +425,16 @@ func runBuild(cmd *Command, args []string) {
|
|||||||
if buildBuildmode == "shared" {
|
if buildBuildmode == "shared" {
|
||||||
a = b.libaction(libname(args))
|
a = b.libaction(libname(args))
|
||||||
mode = depMode
|
mode = depMode
|
||||||
|
|
||||||
|
// Currently build mode shared forces external linking
|
||||||
|
// mode, and external linking mode forces an import of
|
||||||
|
// runtime/cgo.
|
||||||
|
var stk importStack
|
||||||
|
p := loadPackage("runtime/cgo", &stk)
|
||||||
|
if p.Error != nil {
|
||||||
|
fatalf("load runtime/cgo: %v", p.Error)
|
||||||
|
}
|
||||||
|
a.deps = append(a.deps, b.action(mode, depMode, p))
|
||||||
} else {
|
} else {
|
||||||
a = &action{}
|
a = &action{}
|
||||||
}
|
}
|
||||||
|
@ -534,6 +534,14 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
|
|||||||
if len(p.CgoFiles) > 0 && (!p.Standard || !cgoSyscallExclude[p.ImportPath]) {
|
if len(p.CgoFiles) > 0 && (!p.Standard || !cgoSyscallExclude[p.ImportPath]) {
|
||||||
importPaths = append(importPaths, "syscall")
|
importPaths = append(importPaths, "syscall")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently build mode c-shared, or -linkshared, forces
|
||||||
|
// external linking mode, and external linking mode forces an
|
||||||
|
// import of runtime/cgo.
|
||||||
|
if p.Name == "main" && !p.Goroot && (buildBuildmode == "c-shared" || buildLinkshared) {
|
||||||
|
importPaths = append(importPaths, "runtime/cgo")
|
||||||
|
}
|
||||||
|
|
||||||
// Everything depends on runtime, except runtime and unsafe.
|
// Everything depends on runtime, except runtime and unsafe.
|
||||||
if !p.Standard || (p.ImportPath != "runtime" && p.ImportPath != "unsafe") {
|
if !p.Standard || (p.ImportPath != "runtime" && p.ImportPath != "unsafe") {
|
||||||
importPaths = append(importPaths, "runtime")
|
importPaths = append(importPaths, "runtime")
|
||||||
|
Loading…
Reference in New Issue
Block a user