From: Joel Sing Date: Thu, 12 Sep 2019 18:33:06 +0000 (+1000) Subject: cmd/link: simplify determineLinkMode X-Git-Tag: go1.14beta1~1101 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=79877e5f91fb77362235d9160ddbeada5878a9c5;p=gostls13.git cmd/link: simplify determineLinkMode 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go index e119599317..3f5b6d4fdf 100644 --- a/src/cmd/link/internal/ld/config.go +++ b/src/cmd/link/internal/ld/config.go @@ -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" {