From bf1814bc9e4bcda4706627f64391947147b37954 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 20 Mar 2023 14:30:09 -0700 Subject: [PATCH] cmd/go: rewrite externalLinkingForced slightly for clarity Change-Id: I8f8d38c48d4ffe70d15330ea0d4794f264c88f25 Reviewed-on: https://go-review.googlesource.com/c/go/+/477918 TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Bryan Mills --- src/cmd/go/internal/load/pkg.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 240cbc1a21..07a53ff350 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -2636,6 +2636,17 @@ func externalLinkingForced(p *Package) bool { return true } + // Some build modes always require external linking. + switch cfg.BuildBuildmode { + case "c-shared", "plugin": + return true + } + + // Using -linkshared always requires external linking. + if cfg.BuildLinkshared { + return true + } + // Decide whether we are building a PIE, // bearing in mind that some systems default to PIE. isPIE := false @@ -2651,10 +2662,7 @@ func externalLinkingForced(p *Package) bool { return true } - // Currently build modes c-shared, plugin, and -linkshared force - // external linking mode, as of course does - // -ldflags=-linkmode=external. External linking mode forces - // an import of runtime/cgo. + // Using -ldflags=-linkmode=external forces external linking. // If there are multiple -linkmode options, the last one wins. linkmodeExternal := false if p != nil { @@ -2671,8 +2679,7 @@ func externalLinkingForced(p *Package) bool { } } } - - return cfg.BuildBuildmode == "c-shared" || cfg.BuildBuildmode == "plugin" || cfg.BuildLinkshared || linkmodeExternal + return linkmodeExternal } // mkAbs rewrites list, which must be paths relative to p.Dir, -- 2.50.0