Commit 7bdb77af authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/cgo: don't depend on runtime/cgo if !CgoEnabled

Fixes the build when CGO_ENABLED=0.

Change-Id: I7f3c67d61e156e69536558fda0a0a4b429b82bbd
Reviewed-on: https://go-review.googlesource.com/33104
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 35ea53dc
...@@ -913,23 +913,25 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package ...@@ -913,23 +913,25 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
importPaths = append(importPaths, "syscall") importPaths = append(importPaths, "syscall")
} }
// Currently build modes c-shared, pie (on systems that do not if buildContext.CgoEnabled && p.Name == "main" && !p.Goroot {
// support PIE with internal linking mode), plugin, and // Currently build modes c-shared, pie (on systems that do not
// -linkshared force external linking mode, as of course does // support PIE with internal linking mode), plugin, and
// -ldflags=-linkmode=external. External linking mode forces // -linkshared force external linking mode, as of course does
// an import of runtime/cgo. // -ldflags=-linkmode=external. External linking mode forces
pieCgo := buildBuildmode == "pie" && (buildContext.GOOS != "linux" || buildContext.GOARCH != "amd64") // an import of runtime/cgo.
linkmodeExternal := false pieCgo := buildBuildmode == "pie" && (buildContext.GOOS != "linux" || buildContext.GOARCH != "amd64")
for i, a := range buildLdflags { linkmodeExternal := false
if a == "-linkmode=external" { for i, a := range buildLdflags {
linkmodeExternal = true if a == "-linkmode=external" {
} linkmodeExternal = true
if a == "-linkmode" && i+1 < len(buildLdflags) && buildLdflags[i+1] == "external" { }
linkmodeExternal = true if a == "-linkmode" && i+1 < len(buildLdflags) && buildLdflags[i+1] == "external" {
} linkmodeExternal = true
} }
if p.Name == "main" && !p.Goroot && (buildBuildmode == "c-shared" || buildBuildmode == "plugin" || pieCgo || buildLinkshared || linkmodeExternal) { }
importPaths = append(importPaths, "runtime/cgo") if buildBuildmode == "c-shared" || buildBuildmode == "plugin" || pieCgo || buildLinkshared || linkmodeExternal {
importPaths = append(importPaths, "runtime/cgo")
}
} }
// Everything depends on runtime, except runtime, its internal // Everything depends on runtime, except runtime, its internal
......
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