]> Cypherpunks.ru repositories - gostls13.git/blob - src/internal/platform/supported.go
cmd/dist,internal/platform: reenable the c-archive build mode on ios
[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 func MustLinkExternal(goos, goarch string) bool {
76         switch goos {
77         case "android":
78                 if goarch != "arm64" {
79                         return true
80                 }
81         case "ios":
82                 if goarch == "arm64" {
83                         return true
84                 }
85         }
86         return false
87 }
88
89 // BuildModeSupported reports whether goos/goarch supports the given build mode
90 // using the given compiler.
91 func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
92         if compiler == "gccgo" {
93                 return true
94         }
95
96         platform := goos + "/" + goarch
97
98         switch buildmode {
99         case "archive":
100                 return true
101
102         case "c-archive":
103                 switch goos {
104                 case "aix", "darwin", "ios", "windows":
105                         return true
106                 case "linux":
107                         switch goarch {
108                         case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64le", "riscv64", "s390x":
109                                 // linux/ppc64 not supported because it does
110                                 // not support external linking mode yet.
111                                 return true
112                         default:
113                                 // Other targets do not support -shared,
114                                 // per ParseFlags in
115                                 // cmd/compile/internal/base/flag.go.
116                                 // For c-archive the Go tool passes -shared,
117                                 // so that the result is suitable for inclusion
118                                 // in a PIE or shared library.
119                                 return false
120                         }
121                 case "freebsd":
122                         return goarch == "amd64"
123                 }
124                 return false
125
126         case "c-shared":
127                 switch platform {
128                 case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
129                         "android/amd64", "android/arm", "android/arm64", "android/386",
130                         "freebsd/amd64",
131                         "darwin/amd64", "darwin/arm64",
132                         "windows/amd64", "windows/386", "windows/arm64":
133                         return true
134                 }
135                 return false
136
137         case "default":
138                 return true
139
140         case "exe":
141                 return true
142
143         case "pie":
144                 switch platform {
145                 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
146                         "android/amd64", "android/arm", "android/arm64", "android/386",
147                         "freebsd/amd64",
148                         "darwin/amd64", "darwin/arm64",
149                         "ios/amd64", "ios/arm64",
150                         "aix/ppc64",
151                         "windows/386", "windows/amd64", "windows/arm", "windows/arm64":
152                         return true
153                 }
154                 return false
155
156         case "shared":
157                 switch platform {
158                 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
159                         return true
160                 }
161                 return false
162
163         case "plugin":
164                 switch platform {
165                 case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
166                         "android/amd64", "android/386",
167                         "darwin/amd64", "darwin/arm64",
168                         "freebsd/amd64":
169                         return true
170                 }
171                 return false
172
173         default:
174                 return false
175         }
176 }
177
178 func InternalLinkPIESupported(goos, goarch string) bool {
179         switch goos + "/" + goarch {
180         case "darwin/amd64", "darwin/arm64",
181                 "linux/amd64", "linux/arm64", "linux/ppc64le",
182                 "android/arm64",
183                 "windows-amd64", "windows-386", "windows-arm":
184                 return true
185         }
186         return false
187 }