mirror of https://github.com/golang/go.git
cmd/go: don't always link in cgo for PIE
Internal linking for PIE is now supported and enabled by default on some platforms, for which cgo is not needed. Don't always bring in cgo. Change-Id: I043ed436f0e6a3acbcc53ec543f06e193d614b36 Reviewed-on: https://go-review.googlesource.com/c/go/+/261498 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
027367ac50
commit
6c0135d377
|
|
@ -33,6 +33,7 @@ import (
|
|||
"cmd/go/internal/search"
|
||||
"cmd/go/internal/str"
|
||||
"cmd/go/internal/trace"
|
||||
"cmd/internal/sys"
|
||||
)
|
||||
|
||||
var IgnoreImports bool // control whether we ignore imports in packages
|
||||
|
|
@ -1968,7 +1969,7 @@ func externalLinkingForced(p *Package) bool {
|
|||
// external linking mode, as of course does
|
||||
// -ldflags=-linkmode=external. External linking mode forces
|
||||
// an import of runtime/cgo.
|
||||
pieCgo := cfg.BuildBuildmode == "pie"
|
||||
pieCgo := cfg.BuildBuildmode == "pie" && !sys.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
|
||||
linkmodeExternal := false
|
||||
if p != nil {
|
||||
ldflags := BuildLdflags.For(p)
|
||||
|
|
|
|||
|
|
@ -115,3 +115,13 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func InternalLinkPIESupported(goos, goarch string) bool {
|
||||
switch goos + "/" + goarch {
|
||||
case "linux/amd64", "linux/arm64",
|
||||
"android/arm64",
|
||||
"windows-amd64", "windows-386", "windows-arm":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue