]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go,cmd/internal/sys,cmd/link: skip Go build ids for externally linked tools
authorElias Naur <mail@eliasnaur.com>
Tue, 30 Apr 2019 18:03:06 +0000 (20:03 +0200)
committerElias Naur <mail@eliasnaur.com>
Tue, 30 Apr 2019 19:38:46 +0000 (19:38 +0000)
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>
src/cmd/go/internal/work/gc.go
src/cmd/internal/sys/supported.go
src/cmd/link/internal/ld/config.go

index 11108f6411f00066baaeadc591af77bf1223487f..756a89f3abad4ca773c99ed29509672e71efbfc8 100644 (file)
@@ -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)
                }
        }
index df26f971f832c4cbb99c85be3238feeeb56163e4..4162858ac1b8bfe3f38f553307858f74cbfe5c33 100644 (file)
@@ -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
 }
index b404f1897d17a355fb8ec07a610086ec044178e6..7a83d4ef4c4c3f5ed1ec1036201329ae9cb3882a 100644 (file)
@@ -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