Commit 8bde43e0 authored by Elias Naur's avatar Elias Naur

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: default avatarIan Lance Taylor <iant@golang.org>
parent 88548d02
...@@ -542,11 +542,11 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string) ...@@ -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 // Store BuildID inside toolchain binaries as a unique identifier of the
// tool being run, for use by content-based staleness determination. // tool being run, for use by content-based staleness determination.
if root.Package.Goroot && strings.HasPrefix(root.Package.ImportPath, "cmd/") { if root.Package.Goroot && strings.HasPrefix(root.Package.ImportPath, "cmd/") {
// When buildmode=pie, external linking will include our build // External linking will include our build id in the external
// id in the external linker's build id, which will cause our // linker's build id, which will cause our build id to not
// build id to not match the next time the tool is built. // match the next time the tool is built.
// Rely on the external build id instead. // 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) ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.buildID)
} }
} }
......
...@@ -31,10 +31,15 @@ func MSanSupported(goos, goarch string) bool { ...@@ -31,10 +31,15 @@ func MSanSupported(goos, goarch string) bool {
} }
} }
// PIEDefaultsToExternalLink reports whether goos/goarch defaults // MustLinkExternal reports whether goos/goarch requires external linking.
// to external linking for buildmode=pie. func MustLinkExternal(goos, goarch string) bool {
func PIEDefaultsToExternalLink(goos, goarch string) bool { switch goos {
// Currently all systems external link PIE binaries. case "android":
// See https://golang.org/issue/18968. return true
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) { ...@@ -175,13 +175,8 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
}() }()
} }
switch objabi.GOOS { if sys.MustLinkExternal(objabi.GOOS, objabi.GOARCH) {
case "android": return true, fmt.Sprintf("%s/%s requires external linking", objabi.GOOS, objabi.GOARCH)
return true, "android"
case "darwin":
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
return true, "iOS"
}
} }
if *flagMsan { if *flagMsan {
...@@ -256,7 +251,7 @@ func determineLinkMode(ctxt *Link) { ...@@ -256,7 +251,7 @@ func determineLinkMode(ctxt *Link) {
ctxt.LinkMode = LinkExternal ctxt.LinkMode = LinkExternal
} else if iscgo && externalobj { } else if iscgo && externalobj {
ctxt.LinkMode = LinkExternal ctxt.LinkMode = LinkExternal
} else if ctxt.BuildMode == BuildModePIE && sys.PIEDefaultsToExternalLink(objabi.GOOS, objabi.GOARCH) { } else if ctxt.BuildMode == BuildModePIE {
ctxt.LinkMode = LinkExternal ctxt.LinkMode = LinkExternal
} else { } else {
ctxt.LinkMode = LinkInternal ctxt.LinkMode = LinkInternal
......
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