]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: rewrite externalLinkingForced slightly for clarity
authorIan Lance Taylor <iant@golang.org>
Mon, 20 Mar 2023 21:30:09 +0000 (14:30 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 21 Mar 2023 02:19:13 +0000 (02:19 +0000)
Change-Id: I8f8d38c48d4ffe70d15330ea0d4794f264c88f25
Reviewed-on: https://go-review.googlesource.com/c/go/+/477918
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/load/pkg.go

index 240cbc1a21239f8ba074f45dc5ca527f9c868da5..07a53ff3501a15f1a39118f0915f9aa284dbe726 100644 (file)
@@ -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,