Commit 79877e5f authored by Joel Sing's avatar Joel Sing

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/+/195078Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 98aa9780
......@@ -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" {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment