Skip to content

Commit 79877e5

Browse files
committed
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 98aa978 commit 79877e5

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

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

+12-18
Original file line numberDiff line numberDiff line change
@@ -228,40 +228,34 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
228228
// so the ctxt.LinkMode variable has an initial value from the -linkmode
229229
// flag and the iscgo externalobj variables are set.
230230
func determineLinkMode(ctxt *Link) {
231-
switch ctxt.LinkMode {
232-
case LinkAuto:
231+
extNeeded, extReason := mustLinkExternal(ctxt)
232+
via := ""
233+
234+
if ctxt.LinkMode == LinkAuto {
233235
// The environment variable GO_EXTLINK_ENABLED controls the
234236
// default value of -linkmode. If it is not set when the
235237
// linker is called we take the value it was set to when
236238
// cmd/link was compiled. (See make.bash.)
237239
switch objabi.Getgoextlinkenabled() {
238240
case "0":
239-
if needed, reason := mustLinkExternal(ctxt); needed {
240-
Exitf("internal linking requested via GO_EXTLINK_ENABLED, but external linking required: %s", reason)
241-
}
242241
ctxt.LinkMode = LinkInternal
242+
via = "via GO_EXTLINK_ENABLED "
243243
case "1":
244-
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {
245-
Exitf("external linking requested via GO_EXTLINK_ENABLED but not supported for %s/ppc64", objabi.GOOS)
246-
}
247244
ctxt.LinkMode = LinkExternal
245+
via = "via GO_EXTLINK_ENABLED "
248246
default:
249-
if needed, _ := mustLinkExternal(ctxt); needed {
250-
ctxt.LinkMode = LinkExternal
251-
} else if iscgo && externalobj {
252-
ctxt.LinkMode = LinkExternal
253-
} else if ctxt.BuildMode == BuildModePIE {
247+
if extNeeded || (iscgo && externalobj) || ctxt.BuildMode == BuildModePIE {
254248
ctxt.LinkMode = LinkExternal
255249
} else {
256250
ctxt.LinkMode = LinkInternal
257251
}
258-
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" && ctxt.LinkMode == LinkExternal {
259-
Exitf("external linking is not supported for %s/ppc64", objabi.GOOS)
260-
}
261252
}
253+
}
254+
255+
switch ctxt.LinkMode {
262256
case LinkInternal:
263-
if needed, reason := mustLinkExternal(ctxt); needed {
264-
Exitf("internal linking requested but external linking required: %s", reason)
257+
if extNeeded {
258+
Exitf("internal linking requested %sbut external linking required: %s", via, extReason)
265259
}
266260
case LinkExternal:
267261
if objabi.GOARCH == "ppc64" && objabi.GOOS != "aix" {

0 commit comments

Comments
 (0)