// 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)
}
}
}
}
-// 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
}
}()
}
- 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 {
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