| 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. |
| 4 |
|
| 5 |
package sys |
| 6 |
|
| 7 |
// RaceDetectorSupported reports whether goos/goarch supports the race |
| 8 |
// detector. There is a copy of this function in cmd/dist/test.go. |
| 9 |
// Race detector only supports 48-bit VMA on arm64. But it will always |
| 10 |
// return true for arm64, because we don't have VMA size information during |
| 11 |
// the compile time. |
| 12 |
func RaceDetectorSupported(goos, goarch string) bool { |
| 13 |
switch goos { |
| 14 |
case "linux": |
| 15 |
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64" |
| 16 |
case "darwin": |
| 17 |
return goarch == "amd64" || goarch == "arm64" |
| 18 |
case "freebsd", "netbsd", "openbsd", "windows": |
| 19 |
return goarch == "amd64" |
| 20 |
default: |
| 21 |
return false |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
// MSanSupported reports whether goos/goarch supports the memory |
| 26 |
// sanitizer option. |
| 27 |
// There is a copy of this function in misc/cgo/testsanitizers/cc_test.go. |
| 28 |
func MSanSupported(goos, goarch string) bool { |
| 29 |
switch goos { |
| 30 |
case "linux": |
| 31 |
return goarch == "amd64" || goarch == "arm64" |
| 32 |
default: |
| 33 |
return false |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// ASanSupported reports whether goos/goarch supports the address |
| 38 |
// sanitizer option. |
| 39 |
// There is a copy of this function in misc/cgo/testsanitizers/cc_test.go. |
| 40 |
func ASanSupported(goos, goarch string) bool { |
| 41 |
switch goos { |
| 42 |
case "linux": |
| 43 |
return goarch == "arm64" || goarch == "amd64" |
| 44 |
default: |
| 45 |
return false |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// FuzzSupported reports whether goos/goarch supports fuzzing |
| 50 |
// ('go test -fuzz=.'). |
| 51 |
func FuzzSupported(goos, goarch string) bool { |
| 52 |
switch goos { |
| 53 |
case "darwin", "freebsd", "linux", "windows": |
| 54 |
return true |
| 55 |
default: |
| 56 |
return false |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
// FuzzInstrumented reports whether fuzzing on goos/goarch uses coverage |
| 61 |
// instrumentation. (FuzzInstrumented implies FuzzSupported.) |
| 62 |
func FuzzInstrumented(goos, goarch string) bool { |
| 63 |
switch goarch { |
| 64 |
case "amd64", "arm64": |
| 65 |
// TODO(#14565): support more architectures. |
| 66 |
return FuzzSupported(goos, goarch) |
| 67 |
default: |
| 68 |
return false |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
// MustLinkExternal reports whether goos/goarch requires external linking. |
| 73 |
// (This is the opposite of internal/testenv.CanInternalLink. Keep them in sync.) |
| 74 |
func MustLinkExternal(goos, goarch string) bool { |
| 75 |
switch goos { |
| 76 |
case "android": |
| 77 |
if goarch != "arm64" { |
| 78 |
return true |
| 79 |
} |
| 80 |
case "ios": |
| 81 |
if goarch == "arm64" { |
| 82 |
return true |
| 83 |
} |
| 84 |
} |
| 85 |
return false |
| 86 |
} |
| 87 |
|
| 88 |
// BuildModeSupported reports whether goos/goarch supports the given build mode |
| 89 |
// using the given compiler. |
| 90 |
func BuildModeSupported(compiler, buildmode, goos, goarch string) bool { |
| 91 |
if compiler == "gccgo" { |
| 92 |
return true |
| 93 |
} |
| 94 |
|
| 95 |
platform := goos + "/" + goarch |
| 96 |
|
| 97 |
switch buildmode { |
| 98 |
case "archive": |
| 99 |
return true |
| 100 |
|
| 101 |
case "c-archive": |
| 102 |
// TODO(bcmills): This seems dubious. |
| 103 |
// Do we really support c-archive mode on js/wasm‽ |
| 104 |
return platform != "linux/ppc64" |
| 105 |
|
| 106 |
case "c-shared": |
| 107 |
switch platform { |
| 108 |
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x", |
| 109 |
"android/amd64", "android/arm", "android/arm64", "android/386", |
| 110 |
"freebsd/amd64", |
| 111 |
"darwin/amd64", "darwin/arm64", |
| 112 |
"windows/amd64", "windows/386", "windows/arm64": |
| 113 |
return true |
| 114 |
} |
| 115 |
return false |
| 116 |
|
| 117 |
case "default": |
| 118 |
return true |
| 119 |
|
| 120 |
case "exe": |
| 121 |
return true |
| 122 |
|
| 123 |
case "pie": |
| 124 |
switch platform { |
| 125 |
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x", |
| 126 |
"android/amd64", "android/arm", "android/arm64", "android/386", |
| 127 |
"freebsd/amd64", |
| 128 |
"darwin/amd64", "darwin/arm64", |
| 129 |
"ios/amd64", "ios/arm64", |
| 130 |
"aix/ppc64", |
| 131 |
"windows/386", "windows/amd64", "windows/arm": |
| 132 |
return true |
| 133 |
} |
| 134 |
return false |
| 135 |
|
| 136 |
case "shared": |
| 137 |
switch platform { |
| 138 |
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x": |
| 139 |
return true |
| 140 |
} |
| 141 |
return false |
| 142 |
|
| 143 |
case "plugin": |
| 144 |
switch platform { |
| 145 |
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le", |
| 146 |
"android/amd64", "android/arm", "android/arm64", "android/386", |
| 147 |
"darwin/amd64", "darwin/arm64", |
| 148 |
"freebsd/amd64": |
| 149 |
return true |
| 150 |
} |
| 151 |
return false |
| 152 |
|
| 153 |
default: |
| 154 |
return false |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
func InternalLinkPIESupported(goos, goarch string) bool { |
| 159 |
switch goos + "/" + goarch { |
| 160 |
case "darwin/amd64", "darwin/arm64", |
| 161 |
"linux/amd64", "linux/arm64", "linux/ppc64le", |
| 162 |
"android/arm64", |
| 163 |
"windows-amd64", "windows-386", "windows-arm": |
| 164 |
return true |
| 165 |
} |
| 166 |
return false |
| 167 |
} |