mirror of
https://github.com/golang/go
synced 2024-09-29 14:24:32 -06:00
cmd/go,cmd/internal/sys,cmd/link: skip Go build ids for externally linked tools
cmd/go already skips build ids on Android where buildmode=pie is forced. Expand the check to all externally linked tools. Necessary for self-hosted iOS builds where PIE is not forced but external linking is. Updates #31722 Change-Id: Iad796a9411a37eb0c44d365b70a3c5907537e461 Reviewed-on: https://go-review.googlesource.com/c/go/+/174307 Run-TryBot: Elias Naur <mail@eliasnaur.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
88548d0211
commit
8bde43e069
@ -542,11 +542,11 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string)
|
||||
// Store BuildID inside toolchain binaries as a unique identifier of the
|
||||
// tool being run, for use by content-based staleness determination.
|
||||
if root.Package.Goroot && strings.HasPrefix(root.Package.ImportPath, "cmd/") {
|
||||
// When buildmode=pie, external linking will include our build
|
||||
// id in the external linker's build id, which will cause our
|
||||
// build id to not match the next time the tool is built.
|
||||
// External linking will include our build id in the external
|
||||
// linker's build id, which will cause our build id to not
|
||||
// match the next time the tool is built.
|
||||
// Rely on the external build id instead.
|
||||
if ldBuildmode != "pie" || !sys.PIEDefaultsToExternalLink(cfg.Goos, cfg.Goarch) {
|
||||
if !sys.MustLinkExternal(cfg.Goos, cfg.Goarch) {
|
||||
ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.buildID)
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,15 @@ func MSanSupported(goos, goarch string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// PIEDefaultsToExternalLink reports whether goos/goarch defaults
|
||||
// to external linking for buildmode=pie.
|
||||
func PIEDefaultsToExternalLink(goos, goarch string) bool {
|
||||
// Currently all systems external link PIE binaries.
|
||||
// See https://golang.org/issue/18968.
|
||||
return true
|
||||
// MustLinkExternal reports whether goos/goarch requires external linking.
|
||||
func MustLinkExternal(goos, goarch string) bool {
|
||||
switch goos {
|
||||
case "android":
|
||||
return true
|
||||
case "darwin":
|
||||
if goarch == "arm" || goarch == "arm64" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -175,13 +175,8 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
|
||||
}()
|
||||
}
|
||||
|
||||
switch objabi.GOOS {
|
||||
case "android":
|
||||
return true, "android"
|
||||
case "darwin":
|
||||
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
|
||||
return true, "iOS"
|
||||
}
|
||||
if sys.MustLinkExternal(objabi.GOOS, objabi.GOARCH) {
|
||||
return true, fmt.Sprintf("%s/%s requires external linking", objabi.GOOS, objabi.GOARCH)
|
||||
}
|
||||
|
||||
if *flagMsan {
|
||||
@ -256,7 +251,7 @@ func determineLinkMode(ctxt *Link) {
|
||||
ctxt.LinkMode = LinkExternal
|
||||
} else if iscgo && externalobj {
|
||||
ctxt.LinkMode = LinkExternal
|
||||
} else if ctxt.BuildMode == BuildModePIE && sys.PIEDefaultsToExternalLink(objabi.GOOS, objabi.GOARCH) {
|
||||
} else if ctxt.BuildMode == BuildModePIE {
|
||||
ctxt.LinkMode = LinkExternal
|
||||
} else {
|
||||
ctxt.LinkMode = LinkInternal
|
||||
|
Loading…
Reference in New Issue
Block a user