aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-03-20 14:20:22 -0700
committerGopher Robot <gobot@golang.org>2023-03-20 23:33:31 +0000
commit9279a9af8b878a1d516539ac882833fe3e7cc202 (patch)
treedb273b8f27776b1d530df7ffad347f180a087d14 /src/cmd/go/internal/load/pkg.go
parentc7ea9969f8112721edc0a128277f8e5943e21a49 (diff)
downloadgo-9279a9af8b878a1d516539ac882833fe3e7cc202.tar.gz
go-9279a9af8b878a1d516539ac882833fe3e7cc202.zip
cmd/go: use DefaultPIE to see if external linking is forced
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>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 922dc99e69..240cbc1a21 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -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,