]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't always link in cgo for PIE
authorCherry Zhang <cherryyz@google.com>
Sun, 11 Oct 2020 20:27:25 +0000 (16:27 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 12 Oct 2020 22:37:15 +0000 (22:37 +0000)
Internal linking for PIE is now supported and enabled by default
on some platforms, for which cgo is not needed. Don't always
bring in cgo.

Change-Id: I043ed436f0e6a3acbcc53ec543f06e193d614b36
Reviewed-on: https://go-review.googlesource.com/c/go/+/261498
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/internal/load/pkg.go
src/cmd/internal/sys/supported.go

index 5b3c2f0ff2c31b61ec6d5c7decccde566378efa1..db2434260fa60a3fc19023c1a5790e18dc16287a 100644 (file)
@@ -33,6 +33,7 @@ import (
        "cmd/go/internal/search"
        "cmd/go/internal/str"
        "cmd/go/internal/trace"
+       "cmd/internal/sys"
 )
 
 var IgnoreImports bool // control whether we ignore imports in packages
@@ -1968,7 +1969,7 @@ func externalLinkingForced(p *Package) bool {
        // external linking mode, as of course does
        // -ldflags=-linkmode=external. External linking mode forces
        // an import of runtime/cgo.
-       pieCgo := cfg.BuildBuildmode == "pie"
+       pieCgo := cfg.BuildBuildmode == "pie" && !sys.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
        linkmodeExternal := false
        if p != nil {
                ldflags := BuildLdflags.For(p)
index 41e5ec1432ce3feaadae05e6885fb053673b1195..55709f39151967c68755b83df184de0e83d5ebaf 100644 (file)
@@ -115,3 +115,13 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
                return false
        }
 }
+
+func InternalLinkPIESupported(goos, goarch string) bool {
+       switch goos + "/" + goarch {
+       case "linux/amd64", "linux/arm64",
+               "android/arm64",
+               "windows-amd64", "windows-386", "windows-arm":
+               return true
+       }
+       return false
+}