Skip to content

Commit 8bde43e

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 88548d0 commit 8bde43e

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/cmd/go/internal/work/gc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,11 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string)
542542
// Store BuildID inside toolchain binaries as a unique identifier of the
543543
// tool being run, for use by content-based staleness determination.
544544
if root.Package.Goroot && strings.HasPrefix(root.Package.ImportPath, "cmd/") {
545-
// When buildmode=pie, external linking will include our build
546-
// id in the external linker's build id, which will cause our
547-
// build id to not match the next time the tool is built.
545+
// External linking will include our build id in the external
546+
// linker's build id, which will cause our build id to not
547+
// match the next time the tool is built.
548548
// Rely on the external build id instead.
549-
if ldBuildmode != "pie" || !sys.PIEDefaultsToExternalLink(cfg.Goos, cfg.Goarch) {
549+
if !sys.MustLinkExternal(cfg.Goos, cfg.Goarch) {
550550
ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.buildID)
551551
}
552552
}

src/cmd/internal/sys/supported.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ func MSanSupported(goos, goarch string) bool {
3131
}
3232
}
3333

34-
// PIEDefaultsToExternalLink reports whether goos/goarch defaults
35-
// to external linking for buildmode=pie.
36-
func PIEDefaultsToExternalLink(goos, goarch string) bool {
37-
// Currently all systems external link PIE binaries.
38-
// See https://golang.org/issue/18968.
39-
return true
34+
// MustLinkExternal reports whether goos/goarch requires external linking.
35+
func MustLinkExternal(goos, goarch string) bool {
36+
switch goos {
37+
case "android":
38+
return true
39+
case "darwin":
40+
if goarch == "arm" || goarch == "arm64" {
41+
return true
42+
}
43+
}
44+
return false
4045
}

src/cmd/link/internal/ld/config.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,8 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
175175
}()
176176
}
177177

178-
switch objabi.GOOS {
179-
case "android":
180-
return true, "android"
181-
case "darwin":
182-
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
183-
return true, "iOS"
184-
}
178+
if sys.MustLinkExternal(objabi.GOOS, objabi.GOARCH) {
179+
return true, fmt.Sprintf("%s/%s requires external linking", objabi.GOOS, objabi.GOARCH)
185180
}
186181

187182
if *flagMsan {
@@ -256,7 +251,7 @@ func determineLinkMode(ctxt *Link) {
256251
ctxt.LinkMode = LinkExternal
257252
} else if iscgo && externalobj {
258253
ctxt.LinkMode = LinkExternal
259-
} else if ctxt.BuildMode == BuildModePIE && sys.PIEDefaultsToExternalLink(objabi.GOOS, objabi.GOARCH) {
254+
} else if ctxt.BuildMode == BuildModePIE {
260255
ctxt.LinkMode = LinkExternal
261256
} else {
262257
ctxt.LinkMode = LinkInternal

0 commit comments

Comments
 (0)