diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-03-01 16:11:07 +0000 |
|---|---|---|
| committer | Bryan Mills <bcmills@google.com> | 2023-03-02 16:34:21 +0000 |
| commit | 3f8f929d60a90c4e4e2b07c8d1972166c1a783b1 (patch) | |
| tree | 99ab6774006a5bf4d2bf07dce3bb3a7c1a2cad87 /src/internal | |
| parent | b958d4a597a599e22c78d25d83d803ab2a1f2c52 (diff) | |
| download | go-3f8f929d60a90c4e4e2b07c8d1972166c1a783b1.tar.xz | |
cmd/link/internal/ld: move more of mustLinkExternal into internal/platform
internal/platform.MustLinkExternal is used in various places to
determine whether external linking is required. It should always
match what the linker actually requires, but today does not match
because the linker imposes additional constraints.
Updates #31544.
Change-Id: I0cc6ad587e95c607329dea5d60d29a5fb2a9e722
Reviewed-on: https://go-review.googlesource.com/c/go/+/472515
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/internal')
| -rw-r--r-- | src/internal/platform/supported.go | 41 | ||||
| -rw-r--r-- | src/internal/testenv/testenv.go | 11 |
2 files changed, 43 insertions, 9 deletions
diff --git a/src/internal/platform/supported.go b/src/internal/platform/supported.go index 71bf1c5477..8bf68a6d58 100644 --- a/src/internal/platform/supported.go +++ b/src/internal/platform/supported.go @@ -71,8 +71,39 @@ func FuzzInstrumented(goos, goarch string) bool { } } -// MustLinkExternal reports whether goos/goarch requires external linking. -func MustLinkExternal(goos, goarch string) bool { +// MustLinkExternal reports whether goos/goarch requires external linking +// with or without cgo dependencies. +func MustLinkExternal(goos, goarch string, withCgo bool) bool { + if withCgo { + switch goarch { + case "loong64", + "mips", "mipsle", "mips64", "mips64le", + "riscv64": + // Internally linking cgo is incomplete on some architectures. + // https://go.dev/issue/14449 + return true + case "arm64": + if goos == "windows" { + // windows/arm64 internal linking is not implemented. + return true + } + case "ppc64": + // Big Endian PPC64 cgo internal linking is not implemented for aix or linux. + // https://go.dev/issue/8912 + return true + } + + switch goos { + case "android": + return true + case "dragonfly": + // It seems that on Dragonfly thread local storage is + // set up by the dynamic linker, so internal cgo linking + // doesn't work. Test case is "go test runtime/cgo". + return true + } + } + switch goos { case "android": if goarch != "arm64" { @@ -178,10 +209,10 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool { func InternalLinkPIESupported(goos, goarch string) bool { switch goos + "/" + goarch { - case "darwin/amd64", "darwin/arm64", + case "android/arm64", + "darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "linux/ppc64le", - "android/arm64", - "windows-amd64", "windows-386", "windows-arm": + "windows/386", "windows/amd64", "windows/arm", "windows/arm64": return true } return false diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 65a82fd5f7..816a1a100f 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -288,15 +288,18 @@ func MustHaveCGO(t testing.TB) { // CanInternalLink reports whether the current system can link programs with // internal linking. -func CanInternalLink() bool { - return !platform.MustLinkExternal(runtime.GOOS, runtime.GOARCH) +func CanInternalLink(withCgo bool) bool { + return !platform.MustLinkExternal(runtime.GOOS, runtime.GOARCH, withCgo) } // MustInternalLink checks that the current system can link programs with internal // linking. // If not, MustInternalLink calls t.Skip with an explanation. -func MustInternalLink(t testing.TB) { - if !CanInternalLink() { +func MustInternalLink(t testing.TB, withCgo bool) { + if !CanInternalLink(withCgo) { + if withCgo && CanInternalLink(false) { + t.Skipf("skipping test: internal linking on %s/%s is not supported with cgo", runtime.GOOS, runtime.GOARCH) + } t.Skipf("skipping test: internal linking on %s/%s is not supported", runtime.GOOS, runtime.GOARCH) } } |
