From 505325cf3027f2f2c5be47426867183b935ac85e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 10 Feb 2023 14:47:07 -0800 Subject: [PATCH] cmd/dist: use a copy of platform.BuildModeSupported The dist tool already includes a similar duplicate of BuildModeSupported. Replace it with an exact copy, to make it easier to maintain going forward. Change-Id: Id14a6c5a48f92d843e02218d87cc62c6b001923b Reviewed-on: https://go-review.googlesource.com/c/go/+/467495 Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- src/cmd/dist/test.go | 161 +++++++++++++++++------------ src/internal/platform/supported.go | 1 + 2 files changed, 94 insertions(+), 68 deletions(-) diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 4395d3a33b..bc58f0936b 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -1136,79 +1136,14 @@ func (t *tester) internalLinkPIE() bool { // supportedBuildMode reports whether the given build mode is supported. func (t *tester) supportedBuildmode(mode string) bool { - pair := goos + "-" + goarch switch mode { - case "c-archive": - if !t.extLink() { - return false - } - switch goos { - case "aix", "darwin", "ios", "windows": - return true - case "linux": - switch goarch { - case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64", "ppc64le", "riscv64", "s390x": - return true - default: - // Other targets do not support -shared, - // per ParseFlags in - // cmd/compile/internal/base/flag.go. - // For c-archive the Go tool passes -shared, - // so that the result is suitable for inclusion - // in a PIE or shared library. - return false - } - case "freebsd": - return goarch == "amd64" - } - return false - case "c-shared": - switch pair { - case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x", - "darwin-amd64", "darwin-arm64", - "freebsd-amd64", - "android-arm", "android-arm64", "android-386", "android-amd64", - "windows-amd64", "windows-386", "windows-arm64": - return true - } - return false - case "shared": - switch pair { - case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x": - return true - } - return false - case "plugin": - switch pair { - case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-s390x", "linux-ppc64le": - return true - case "android-386", "android-amd64": - return true - case "darwin-amd64", "darwin-arm64": - return true - case "freebsd-amd64": - return true - } - return false - case "pie": - switch pair { - case "aix-ppc64", - "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x", - "android-amd64", "android-arm", "android-arm64", "android-386": - return true - case "darwin-amd64", "darwin-arm64", "ios-amd64", "ios-arm64": - return true - case "windows-amd64", "windows-386", "windows-arm", "windows-arm64": - return true - case "freebsd-amd64": - return true - } - return false - + case "c-archive", "c-shared", "shared", "plugin", "pie": default: fatalf("internal error: unknown buildmode %s", mode) return false } + + return buildModeSupported("gc", mode, goos, goarch) } func (t *tester) registerCgoTests() { @@ -1737,6 +1672,96 @@ func raceDetectorSupported(goos, goarch string) bool { } } +// buildModeSupports is a copy of the function +// internal/platform.BuildModeSupported, which can't be used here +// because cmd/dist can not import internal packages during bootstrap. +func buildModeSupported(compiler, buildmode, goos, goarch string) bool { + if compiler == "gccgo" { + return true + } + + platform := goos + "/" + goarch + + switch buildmode { + case "archive": + return true + + case "c-archive": + switch goos { + case "aix", "darwin", "ios", "windows": + return true + case "linux": + switch goarch { + case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64le", "riscv64", "s390x": + // linux/ppc64 not supported because it does + // not support external linking mode yet. + return true + default: + // Other targets do not support -shared, + // per ParseFlags in + // cmd/compile/internal/base/flag.go. + // For c-archive the Go tool passes -shared, + // so that the result is suitable for inclusion + // in a PIE or shared library. + return false + } + case "freebsd": + return goarch == "amd64" + } + return false + + case "c-shared": + switch platform { + case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x", + "android/amd64", "android/arm", "android/arm64", "android/386", + "freebsd/amd64", + "darwin/amd64", "darwin/arm64", + "windows/amd64", "windows/386", "windows/arm64": + return true + } + return false + + case "default": + return true + + case "exe": + return true + + case "pie": + switch platform { + case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", + "android/amd64", "android/arm", "android/arm64", "android/386", + "freebsd/amd64", + "darwin/amd64", "darwin/arm64", + "ios/amd64", "ios/arm64", + "aix/ppc64", + "windows/386", "windows/amd64", "windows/arm", "windows/arm64": + return true + } + return false + + case "shared": + switch platform { + case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x": + return true + } + return false + + case "plugin": + switch platform { + case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le", + "android/amd64", "android/386", + "darwin/amd64", "darwin/arm64", + "freebsd/amd64": + return true + } + return false + + default: + return false + } +} + // isUnsupportedVMASize reports whether the failure is caused by an unsupported // VMA for the race detector (for example, running the race detector on an // arm64 machine configured with 39-bit VMA) diff --git a/src/internal/platform/supported.go b/src/internal/platform/supported.go index 4c75b1d849..71bf1c5477 100644 --- a/src/internal/platform/supported.go +++ b/src/internal/platform/supported.go @@ -88,6 +88,7 @@ func MustLinkExternal(goos, goarch string) bool { // BuildModeSupported reports whether goos/goarch supports the given build mode // using the given compiler. +// There is a copy of this function in cmd/dist/test.go. func BuildModeSupported(compiler, buildmode, goos, goarch string) bool { if compiler == "gccgo" { return true -- 2.48.1