From 8bde43e0694ed91565c95b286e3d31a2f43d8d80 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 30 Apr 2019 20:03:06 +0200 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/work/gc.go | 8 ++++---- src/cmd/internal/sys/supported.go | 17 +++++++++++------ src/cmd/link/internal/ld/config.go | 11 +++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index 11108f6411..756a89f3ab 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -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) } } diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go index df26f971f8..4162858ac1 100644 --- a/src/cmd/internal/sys/supported.go +++ b/src/cmd/internal/sys/supported.go @@ -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 } diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go index b404f1897d..7a83d4ef4c 100644 --- a/src/cmd/link/internal/ld/config.go +++ b/src/cmd/link/internal/ld/config.go @@ -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 -- 2.50.0