]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: simplify determineLinkMode
authorJoel Sing <joel@sing.id.au>
Thu, 12 Sep 2019 18:33:06 +0000 (04:33 +1000)
committerJoel Sing <joel@sing.id.au>
Fri, 13 Sep 2019 09:40:36 +0000 (09:40 +0000)
Simplify determineLinkMode by calling mustLinkExternal upfront,
then doing a first pass for LinkModeAuto, followed by a second pass
that determines if the link mode is valid.

Change-Id: I9d7668107c159f8fe330b8c05fee035bbe9875fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/195078
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

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

index e119599317bc3acf786b9956cb62db42ef16bead..3f5b6d4fdff8489aa374a18d7c6db1402535a9a0 100644 (file)
@@ -228,40 +228,34 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
 // so the ctxt.LinkMode variable has an initial value from the -linkmode
 // flag and the iscgo externalobj variables are set.
 func determineLinkMode(ctxt *Link) {
-       switch ctxt.LinkMode {
-       case LinkAuto:
+       extNeeded, extReason := mustLinkExternal(ctxt)
+       via := ""
+
+       if ctxt.LinkMode == LinkAuto {
                // The environment variable GO_EXTLINK_ENABLED controls the
                // default value of -linkmode. If it is not set when the
                // linker is called we take the value it was set to when
                // cmd/link was compiled. (See make.bash.)
                switch objabi.Getgoextlinkenabled() {
                case "0":
-                       if needed, reason := mustLinkExternal(ctxt); needed {
-                               Exitf("internal linking requested via GO_EXTLINK_ENABLED, but external linking required: %s", reason)
-                       }
                        ctxt.LinkMode = LinkInternal
+                       via = "via GO_EXTLINK_ENABLED "
                case "1":
-                       if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {
-                               Exitf("external linking requested via GO_EXTLINK_ENABLED but not supported for %s/ppc64", objabi.GOOS)
-                       }
                        ctxt.LinkMode = LinkExternal
+                       via = "via GO_EXTLINK_ENABLED "
                default:
-                       if needed, _ := mustLinkExternal(ctxt); needed {
-                               ctxt.LinkMode = LinkExternal
-                       } else if iscgo && externalobj {
-                               ctxt.LinkMode = LinkExternal
-                       } else if ctxt.BuildMode == BuildModePIE {
+                       if extNeeded || (iscgo && externalobj) || ctxt.BuildMode == BuildModePIE {
                                ctxt.LinkMode = LinkExternal
                        } else {
                                ctxt.LinkMode = LinkInternal
                        }
-                       if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && ctxt.LinkMode == LinkExternal {
-                               Exitf("external linking is not supported for %s/ppc64", objabi.GOOS)
-                       }
                }
+       }
+
+       switch ctxt.LinkMode {
        case LinkInternal:
-               if needed, reason := mustLinkExternal(ctxt); needed {
-                       Exitf("internal linking requested but external linking required: %s", reason)
+               if extNeeded {
+                       Exitf("internal linking requested %sbut external linking required: %s", via, extReason)
                }
        case LinkExternal:
                if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {