]> Cypherpunks.ru repositories - gostls13.git/blob - src/internal/platform/supported.go
01524fbcd77d1dd61e584c333b57be139c6755c8
[gostls13.git] / src / internal / platform / supported.go
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 platform
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" || goarch == "s390x"
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         case "freebsd":
33                 return goarch == "amd64"
34         default:
35                 return false
36         }
37 }
38
39 // ASanSupported reports whether goos/goarch supports the address
40 // sanitizer option.
41 // There is a copy of this function in misc/cgo/testsanitizers/cc_test.go.
42 func ASanSupported(goos, goarch string) bool {
43         switch goos {
44         case "linux":
45                 return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
46         default:
47                 return false
48         }
49 }
50
51 // FuzzSupported reports whether goos/goarch supports fuzzing
52 // ('go test -fuzz=.').
53 func FuzzSupported(goos, goarch string) bool {
54         switch goos {
55         case "darwin", "freebsd", "linux", "windows":
56                 return true
57         default:
58                 return false
59         }
60 }
61
62 // FuzzInstrumented reports whether fuzzing on goos/goarch uses coverage
63 // instrumentation. (FuzzInstrumented implies FuzzSupported.)
64 func FuzzInstrumented(goos, goarch string) bool {
65         switch goarch {
66         case "amd64", "arm64":
67                 // TODO(#14565): support more architectures.
68                 return FuzzSupported(goos, goarch)
69         default:
70                 return false
71         }
72 }
73
74 // MustLinkExternal reports whether goos/goarch requires external linking
75 // with or without cgo dependencies.
76 func MustLinkExternal(goos, goarch string, withCgo bool) bool {
77         if withCgo {
78                 switch goarch {
79                 case "loong64",
80                         "mips", "mipsle", "mips64", "mips64le",
81                         "riscv64":
82                         // Internally linking cgo is incomplete on some architectures.
83                         // https://go.dev/issue/14449
84                         return true
85                 case "arm64":
86                         if goos == "windows" {
87                                 // windows/arm64 internal linking is not implemented.
88                                 return true
89                         }
90                 case "ppc64":
91                         // Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
92                         // https://go.dev/issue/8912
93                         return true
94                 }
95
96                 switch goos {
97                 case "android":
98                         return true
99                 case "dragonfly":
100                         // It seems that on Dragonfly thread local storage is
101                         // set up by the dynamic linker, so internal cgo linking
102                         // doesn't work. Test case is "go test runtime/cgo".
103                         return true
104                 }
105         }
106
107         switch goos {
108         case "android":
109                 if goarch != "arm64" {
110                         return true
111                 }
112         case "ios":
113                 if goarch == "arm64" {
114                         return true
115                 }
116         }
117         return false
118 }
119
120 // BuildModeSupported reports whether goos/goarch supports the given build mode
121 // using the given compiler.
122 // There is a copy of this function in cmd/dist/test.go.
123 func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
124         if compiler == "gccgo" {
125                 return true
126         }
127
128         platform := goos + "/" + goarch
129
130         switch buildmode {
131         case "archive":
132                 return true
133
134         case "c-archive":
135                 switch goos {
136                 case "aix", "darwin", "ios", "windows":
137                         return true
138                 case "linux":
139                         switch goarch {
140                         case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64le", "riscv64", "s390x":
141                                 // linux/ppc64 not supported because it does
142                                 // not support external linking mode yet.
143                                 return true
144                         default:
145                                 // Other targets do not support -shared,
146                                 // per ParseFlags in
147                                 // cmd/compile/internal/base/flag.go.
148                                 // For c-archive the Go tool passes -shared,
149                                 // so that the result is suitable for inclusion
150                                 // in a PIE or shared library.
151                                 return false
152                         }
153                 case "freebsd":
154                         return goarch == "amd64"
155                 }
156                 return false
157
158         case "c-shared":
159                 switch platform {
160                 case "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
161                         "android/amd64", "android/arm", "android/arm64", "android/386",
162                         "freebsd/amd64",
163                         "darwin/amd64", "darwin/arm64",
164                         "windows/amd64", "windows/386", "windows/arm64":
165                         return true
166                 }
167                 return false
168
169         case "default":
170                 return true
171
172         case "exe":
173                 return true
174
175         case "pie":
176                 switch platform {
177                 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
178                         "android/amd64", "android/arm", "android/arm64", "android/386",
179                         "freebsd/amd64",
180                         "darwin/amd64", "darwin/arm64",
181                         "ios/amd64", "ios/arm64",
182                         "aix/ppc64",
183                         "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
184                         return true
185                 }
186                 return false
187
188         case "shared":
189                 switch platform {
190                 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
191                         return true
192                 }
193                 return false
194
195         case "plugin":
196                 switch platform {
197                 case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
198                         "android/amd64", "android/386",
199                         "darwin/amd64", "darwin/arm64",
200                         "freebsd/amd64":
201                         return true
202                 }
203                 return false
204
205         default:
206                 return false
207         }
208 }
209
210 func InternalLinkPIESupported(goos, goarch string) bool {
211         switch goos + "/" + goarch {
212         case "android/arm64",
213                 "darwin/amd64", "darwin/arm64",
214                 "linux/amd64", "linux/arm64", "linux/ppc64le",
215                 "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
216                 return true
217         }
218         return false
219 }
220
221 // DefaultPIE reports whether goos/goarch produces a PIE binary when using the
222 // "default" buildmode. On Windows this is affected by -race,
223 // so force the caller to pass that in to centralize that choice.
224 func DefaultPIE(goos, goarch string, isRace bool) bool {
225         switch goos {
226         case "android", "ios":
227                 return true
228         case "windows":
229                 if isRace {
230                         // PIE is not supported with -race on windows;
231                         // see https://go.dev/cl/416174.
232                         return false
233                 }
234                 return true
235         case "darwin":
236                 return goarch == "arm64"
237         }
238         return false
239 }