]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use DefaultPIE to see if external linking is forced
authorIan Lance Taylor <iant@golang.org>
Mon, 20 Mar 2023 21:20:22 +0000 (14:20 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 20 Mar 2023 23:33:31 +0000 (23:33 +0000)
Before this CL, the code checked whether external linking was
required for -buildmode=pie. This CL changes it to also consider
whether external linking is required if PIE is the default build mode.

Change-Id: I5ac62fc027622576a152a8b7b5d97bc1d112adb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/477917
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/load/pkg.go

index 922dc99e6916a95f6b7988e46a2d92f0e5e05fe7..240cbc1a21239f8ba074f45dc5ca527f9c868da5 100644 (file)
@@ -2636,14 +2636,26 @@ func externalLinkingForced(p *Package) bool {
                return true
        }
 
-       // Currently build modes c-shared, pie (on systems that do not
-       // support PIE with internal linking mode (currently all
-       // systems: issue #18968)), plugin, and -linkshared force
+       // Decide whether we are building a PIE,
+       // bearing in mind that some systems default to PIE.
+       isPIE := false
+       if cfg.BuildBuildmode == "pie" {
+               isPIE = true
+       } else if cfg.BuildBuildmode == "default" && platform.DefaultPIE(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH, cfg.BuildRace) {
+               isPIE = true
+       }
+       // If we are building a PIE, and we are on a system
+       // that does not support PIE with internal linking mode,
+       // then we must use external linking.
+       if isPIE && !platform.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH) {
+               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.
        // If there are multiple -linkmode options, the last one wins.
-       pieCgo := cfg.BuildBuildmode == "pie" && !platform.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
        linkmodeExternal := false
        if p != nil {
                ldflags := BuildLdflags.For(p)
@@ -2660,7 +2672,7 @@ func externalLinkingForced(p *Package) bool {
                }
        }
 
-       return cfg.BuildBuildmode == "c-shared" || cfg.BuildBuildmode == "plugin" || pieCgo || cfg.BuildLinkshared || linkmodeExternal
+       return cfg.BuildBuildmode == "c-shared" || cfg.BuildBuildmode == "plugin" || cfg.BuildLinkshared || linkmodeExternal
 }
 
 // mkAbs rewrites list, which must be paths relative to p.Dir,