@@ -86,7 +86,11 @@ func instrumentInit() {
86
86
func buildModeInit () {
87
87
gccgo := cfg .BuildToolchainName == "gccgo"
88
88
var codegenArg string
89
- platform := cfg .Goos + "/" + cfg .Goarch
89
+
90
+ // Configure the build mode first, then verify that it is supported.
91
+ // That way, if the flag is completely bogus we will prefer to error out with
92
+ // "-buildmode=%s not supported" instead of naming the specific platform.
93
+
90
94
switch cfg .BuildBuildmode {
91
95
case "archive" :
92
96
pkgsFilter = pkgsNotMain
@@ -95,20 +99,18 @@ func buildModeInit() {
95
99
if gccgo {
96
100
codegenArg = "-fPIC"
97
101
} else {
98
- switch platform {
99
- case "darwin/arm" , "darwin/arm64" :
100
- codegenArg = "-shared"
101
- default :
102
- switch cfg .Goos {
103
- case "dragonfly" , "freebsd" , "illumos" , "linux" , "netbsd" , "openbsd" , "solaris" :
104
- if platform == "linux/ppc64" {
105
- base .Fatalf ("-buildmode=c-archive not supported on %s\n " , platform )
106
- }
107
- // Use -shared so that the result is
108
- // suitable for inclusion in a PIE or
109
- // shared library.
102
+ switch cfg .Goos {
103
+ case "darwin" :
104
+ switch cfg .Goarch {
105
+ case "arm" , "arm64" :
110
106
codegenArg = "-shared"
111
107
}
108
+
109
+ case "dragonfly" , "freebsd" , "illumos" , "linux" , "netbsd" , "openbsd" , "solaris" :
110
+ // Use -shared so that the result is
111
+ // suitable for inclusion in a PIE or
112
+ // shared library.
113
+ codegenArg = "-shared"
112
114
}
113
115
}
114
116
cfg .ExeSuffix = ".a"
@@ -118,27 +120,25 @@ func buildModeInit() {
118
120
if gccgo {
119
121
codegenArg = "-fPIC"
120
122
} else {
121
- switch platform {
122
- case "linux/amd64" , "linux/arm" , "linux/arm64" , "linux/386" , "linux/ppc64le" , "linux/s390x" ,
123
- "android/amd64" , "android/arm" , "android/arm64" , "android/386" ,
124
- "freebsd/amd64" :
123
+ switch cfg .Goos {
124
+ case "linux" , "android" , "freebsd" :
125
125
codegenArg = "-shared"
126
- case "darwin/amd64" , "darwin/386" :
127
- case "windows/amd64" , "windows/386" :
126
+ case "windows" :
128
127
// Do not add usual .exe suffix to the .dll file.
129
128
cfg .ExeSuffix = ""
130
- default :
131
- base .Fatalf ("-buildmode=c-shared not supported on %s\n " , platform )
132
129
}
133
130
}
134
131
ldBuildmode = "c-shared"
135
132
case "default" :
136
- switch platform {
137
- case "android/arm" , "android/arm64" , "android/amd64" , "android/386 " :
133
+ switch cfg . Goos {
134
+ case "android" :
138
135
codegenArg = "-shared"
139
136
ldBuildmode = "pie"
140
- case "darwin/arm" , "darwin/arm64" :
141
- codegenArg = "-shared"
137
+ case "darwin" :
138
+ switch cfg .Goarch {
139
+ case "arm" , "arm64" :
140
+ codegenArg = "-shared"
141
+ }
142
142
fallthrough
143
143
default :
144
144
ldBuildmode = "exe"
@@ -161,30 +161,15 @@ func buildModeInit() {
161
161
}
162
162
if gccgo {
163
163
codegenArg = "-fPIE"
164
- } else {
165
- switch platform {
166
- case "linux/386" , "linux/amd64" , "linux/arm" , "linux/arm64" , "linux/ppc64le" , "linux/s390x" ,
167
- "android/amd64" , "android/arm" , "android/arm64" , "android/386" ,
168
- "freebsd/amd64" :
169
- codegenArg = "-shared"
170
- case "darwin/amd64" :
171
- codegenArg = "-shared"
172
- case "aix/ppc64" :
173
- default :
174
- base .Fatalf ("-buildmode=pie not supported on %s\n " , platform )
175
- }
164
+ } else if cfg .Goos != "aix" {
165
+ codegenArg = "-shared"
176
166
}
177
167
ldBuildmode = "pie"
178
168
case "shared" :
179
169
pkgsFilter = pkgsNotMain
180
170
if gccgo {
181
171
codegenArg = "-fPIC"
182
172
} else {
183
- switch platform {
184
- case "linux/386" , "linux/amd64" , "linux/arm" , "linux/arm64" , "linux/ppc64le" , "linux/s390x" :
185
- default :
186
- base .Fatalf ("-buildmode=shared not supported on %s\n " , platform )
187
- }
188
173
codegenArg = "-dynlink"
189
174
}
190
175
if cfg .BuildO != "" {
@@ -196,31 +181,26 @@ func buildModeInit() {
196
181
if gccgo {
197
182
codegenArg = "-fPIC"
198
183
} else {
199
- switch platform {
200
- case "linux/amd64" , "linux/arm" , "linux/arm64" , "linux/386" , "linux/s390x" , "linux/ppc64le" ,
201
- "android/amd64" , "android/arm" , "android/arm64" , "android/386" :
202
- case "darwin/amd64" :
203
- case "freebsd/amd64" :
204
- default :
205
- base .Fatalf ("-buildmode=plugin not supported on %s\n " , platform )
206
- }
207
184
codegenArg = "-dynlink"
208
185
}
209
186
cfg .ExeSuffix = ".so"
210
187
ldBuildmode = "plugin"
211
188
default :
212
189
base .Fatalf ("buildmode=%s not supported" , cfg .BuildBuildmode )
213
190
}
191
+
192
+ if ! sys .BuildModeSupported (cfg .BuildToolchainName , cfg .BuildBuildmode , cfg .Goos , cfg .Goarch ) {
193
+ base .Fatalf ("-buildmode=%s not supported on %s/%s\n " , cfg .BuildBuildmode , cfg .Goos , cfg .Goarch )
194
+ }
195
+
214
196
if cfg .BuildLinkshared {
197
+ if ! sys .BuildModeSupported (cfg .BuildToolchainName , "shared" , cfg .Goos , cfg .Goarch ) {
198
+ base .Fatalf ("-linkshared not supported on %s/%s\n " , cfg .Goos , cfg .Goarch )
199
+ }
215
200
if gccgo {
216
201
codegenArg = "-fPIC"
217
202
} else {
218
- switch platform {
219
- case "linux/386" , "linux/amd64" , "linux/arm" , "linux/arm64" , "linux/ppc64le" , "linux/s390x" :
220
- forcedAsmflags = append (forcedAsmflags , "-D=GOBUILDMODE_shared=1" )
221
- default :
222
- base .Fatalf ("-linkshared not supported on %s\n " , platform )
223
- }
203
+ forcedAsmflags = append (forcedAsmflags , "-D=GOBUILDMODE_shared=1" )
224
204
codegenArg = "-dynlink"
225
205
forcedGcflags = append (forcedGcflags , "-linkshared" )
226
206
// TODO(mwhudson): remove -w when that gets fixed in linker.
0 commit comments