1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:generate go test . -run=TestGenerated -fix
9 // An OSArch is a pair of GOOS and GOARCH values indicating a platform.
14 func (p OSArch) String() string {
15 return p.GOOS + "/" + p.GOARCH
18 // RaceDetectorSupported reports whether goos/goarch supports the race
19 // detector. There is a copy of this function in cmd/dist/test.go.
20 // Race detector only supports 48-bit VMA on arm64. But it will always
21 // return true for arm64, because we don't have VMA size information during
23 func RaceDetectorSupported(goos, goarch string) bool {
26 return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64" || goarch == "s390x"
28 return goarch == "amd64" || goarch == "arm64"
29 case "freebsd", "netbsd", "openbsd", "windows":
30 return goarch == "amd64"
36 // MSanSupported reports whether goos/goarch supports the memory
38 func MSanSupported(goos, goarch string) bool {
41 return goarch == "amd64" || goarch == "arm64"
43 return goarch == "amd64"
49 // ASanSupported reports whether goos/goarch supports the address
51 func ASanSupported(goos, goarch string) bool {
54 return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
60 // FuzzSupported reports whether goos/goarch supports fuzzing
61 // ('go test -fuzz=.').
62 func FuzzSupported(goos, goarch string) bool {
64 case "darwin", "freebsd", "linux", "windows":
71 // FuzzInstrumented reports whether fuzzing on goos/goarch uses coverage
72 // instrumentation. (FuzzInstrumented implies FuzzSupported.)
73 func FuzzInstrumented(goos, goarch string) bool {
75 case "amd64", "arm64":
76 // TODO(#14565): support more architectures.
77 return FuzzSupported(goos, goarch)
83 // MustLinkExternal reports whether goos/goarch requires external linking
84 // with or without cgo dependencies.
85 func MustLinkExternal(goos, goarch string, withCgo bool) bool {
89 "mips", "mipsle", "mips64", "mips64le",
91 // Internally linking cgo is incomplete on some architectures.
92 // https://go.dev/issue/14449
95 if goos == "windows" {
96 // windows/arm64 internal linking is not implemented.
100 // Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
101 // https://go.dev/issue/8912
109 // It seems that on Dragonfly thread local storage is
110 // set up by the dynamic linker, so internal cgo linking
111 // doesn't work. Test case is "go test runtime/cgo".
118 if goarch != "arm64" {
122 if goarch == "arm64" {
129 // BuildModeSupported reports whether goos/goarch supports the given build mode
130 // using the given compiler.
131 // There is a copy of this function in cmd/dist/test.go.
132 func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
133 if compiler == "gccgo" {
137 if _, ok := distInfo[OSArch{goos, goarch}]; !ok {
138 return false // platform unrecognized
141 platform := goos + "/" + goarch
148 case "aix", "darwin", "ios", "windows":
152 case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "loong64", "ppc64le", "riscv64", "s390x":
153 // linux/ppc64 not supported because it does
154 // not support external linking mode yet.
157 // Other targets do not support -shared,
159 // cmd/compile/internal/base/flag.go.
160 // For c-archive the Go tool passes -shared,
161 // so that the result is suitable for inclusion
162 // in a PIE or shared library.
166 return goarch == "amd64"
172 case "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
173 "android/amd64", "android/arm", "android/arm64", "android/386",
175 "darwin/amd64", "darwin/arm64",
176 "windows/amd64", "windows/386", "windows/arm64":
189 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
190 "android/amd64", "android/arm", "android/arm64", "android/386",
192 "darwin/amd64", "darwin/arm64",
193 "ios/amd64", "ios/arm64",
195 "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
202 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
209 case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
210 "android/amd64", "android/386",
211 "darwin/amd64", "darwin/arm64",
222 func InternalLinkPIESupported(goos, goarch string) bool {
223 switch goos + "/" + goarch {
224 case "android/arm64",
225 "darwin/amd64", "darwin/arm64",
226 "linux/amd64", "linux/arm64", "linux/ppc64le",
227 "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
233 // DefaultPIE reports whether goos/goarch produces a PIE binary when using the
234 // "default" buildmode. On Windows this is affected by -race,
235 // so force the caller to pass that in to centralize that choice.
236 func DefaultPIE(goos, goarch string, isRace bool) bool {
238 case "android", "ios":
242 // PIE is not supported with -race on windows;
243 // see https://go.dev/cl/416174.
248 return goarch == "arm64"
253 // ExecutableHasDWARF reports whether the linked executable includes DWARF
254 // symbols on goos/goarch.
255 func ExecutableHasDWARF(goos, goarch string) bool {
263 // osArchInfo describes information about an OSArch extracted from cmd/dist and
264 // stored in the generated distInfo map.
265 type osArchInfo struct {
271 // CgoSupported reports whether goos/goarch supports cgo.
272 func CgoSupported(goos, goarch string) bool {
273 return distInfo[OSArch{goos, goarch}].CgoSupported
276 // FirstClass reports whether goos/goarch is considered a “first class” port.
277 // (See https://go.dev/wiki/PortingPolicy#first-class-ports.)
278 func FirstClass(goos, goarch string) bool {
279 return distInfo[OSArch{goos, goarch}].FirstClass
282 // Broken reportsr whether goos/goarch is considered a broken port.
283 // (See https://go.dev/wiki/PortingPolicy#broken-ports.)
284 func Broken(goos, goarch string) bool {
285 return distInfo[OSArch{goos, goarch}].Broken