@@ -30,6 +30,7 @@ type TargetSpec struct {
30
30
Features string `json:"features,omitempty"`
31
31
GOOS string `json:"goos,omitempty"`
32
32
GOARCH string `json:"goarch,omitempty"`
33
+ SoftFloat bool // used for non-baremetal systems (GOMIPS=softfloat etc)
33
34
BuildTags []string `json:"build-tags,omitempty"`
34
35
GC string `json:"gc,omitempty"`
35
36
Scheduler string `json:"scheduler,omitempty"`
@@ -86,6 +87,10 @@ func (spec *TargetSpec) overrideProperties(child *TargetSpec) error {
86
87
if src .Uint () != 0 {
87
88
dst .Set (src )
88
89
}
90
+ case reflect .Bool :
91
+ if src .Bool () {
92
+ dst .Set (src )
93
+ }
89
94
case reflect .Ptr : // for pointers, copy if not nil
90
95
if ! src .IsNil () {
91
96
dst .Set (src )
@@ -228,7 +233,7 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
228
233
} else if options .GOARCH == "arm" {
229
234
target += "-gnueabihf"
230
235
}
231
- return defaultTarget (options . GOOS , options . GOARCH , target )
236
+ return defaultTarget (options , target )
232
237
}
233
238
234
239
// See whether there is a target specification for this target (e.g.
@@ -289,22 +294,22 @@ func GetTargetSpecs() (map[string]*TargetSpec, error) {
289
294
return maps , nil
290
295
}
291
296
292
- func defaultTarget (goos , goarch , triple string ) (* TargetSpec , error ) {
297
+ func defaultTarget (options * Options , triple string ) (* TargetSpec , error ) {
293
298
// No target spec available. Use the default one, useful on most systems
294
299
// with a regular OS.
295
300
spec := TargetSpec {
296
301
Triple : triple ,
297
- GOOS : goos ,
298
- GOARCH : goarch ,
299
- BuildTags : []string {goos , goarch },
302
+ GOOS : options . GOOS ,
303
+ GOARCH : options . GOARCH ,
304
+ BuildTags : []string {options . GOOS , options . GOARCH },
300
305
GC : "precise" ,
301
306
Scheduler : "tasks" ,
302
307
Linker : "cc" ,
303
308
DefaultStackSize : 1024 * 64 , // 64kB
304
309
GDB : []string {"gdb" },
305
310
PortReset : "false" ,
306
311
}
307
- switch goarch {
312
+ switch options . GOARCH {
308
313
case "386" :
309
314
spec .CPU = "pentium4"
310
315
spec .Features = "+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87"
@@ -324,17 +329,26 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
324
329
}
325
330
case "arm64" :
326
331
spec .CPU = "generic"
327
- if goos == "darwin" {
332
+ if options . GOOS == "darwin" {
328
333
spec .Features = "+fp-armv8,+neon"
329
- } else if goos == "windows" {
334
+ } else if options . GOOS == "windows" {
330
335
spec .Features = "+fp-armv8,+neon,-fmv"
331
336
} else { // linux
332
337
spec .Features = "+fp-armv8,+neon,-fmv,-outline-atomics"
333
338
}
334
339
case "mips" , "mipsle" :
335
340
spec .CPU = "mips32r2"
336
- spec .Features = "+fpxx,+mips32r2,+nooddspreg,-noabicalls"
337
341
spec .CFlags = append (spec .CFlags , "-fno-pic" )
342
+ switch options .GOMIPS {
343
+ case "hardfloat" :
344
+ spec .Features = "+fpxx,+mips32r2,+nooddspreg,-noabicalls"
345
+ case "softfloat" :
346
+ spec .SoftFloat = true
347
+ spec .Features = "+mips32r2,+soft-float,-noabicalls"
348
+ spec .CFlags = append (spec .CFlags , "-msoft-float" )
349
+ default :
350
+ return nil , errors .New ("invalid GOMIPS: must be hardfloat or softfloat" )
351
+ }
338
352
case "wasm" :
339
353
spec .CPU = "generic"
340
354
spec .Features = "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext"
@@ -345,7 +359,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
345
359
"-msign-ext" ,
346
360
)
347
361
}
348
- if goos == "darwin" {
362
+ if options . GOOS == "darwin" {
349
363
spec .Linker = "ld.lld"
350
364
spec .Libc = "darwin-libSystem"
351
365
arch := strings .Split (triple , "-" )[0 ]
@@ -356,12 +370,12 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
356
370
"-arch" , arch ,
357
371
"-platform_version" , "macos" , platformVersion , platformVersion ,
358
372
)
359
- } else if goos == "linux" {
373
+ } else if options . GOOS == "linux" {
360
374
spec .Linker = "ld.lld"
361
375
spec .RTLib = "compiler-rt"
362
376
spec .Libc = "musl"
363
377
spec .LDFlags = append (spec .LDFlags , "--gc-sections" )
364
- if goarch == "arm64" {
378
+ if options . GOARCH == "arm64" {
365
379
// Disable outline atomics. For details, see:
366
380
// https://cpufun.substack.com/p/atomics-in-aarch64
367
381
// A better way would be to fully support outline atomics, which
@@ -375,7 +389,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
375
389
// proper threading.
376
390
spec .CFlags = append (spec .CFlags , "-mno-outline-atomics" )
377
391
}
378
- } else if goos == "windows" {
392
+ } else if options . GOOS == "windows" {
379
393
spec .Linker = "ld.lld"
380
394
spec .Libc = "mingw-w64"
381
395
// Note: using a medium code model, low image base and no ASLR
@@ -384,7 +398,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
384
398
// normally present in Go (without explicitly opting in).
385
399
// For more discussion:
386
400
// https://groups.google.com/g/Golang-nuts/c/Jd9tlNc6jUE/m/Zo-7zIP_m3MJ?pli=1
387
- switch goarch {
401
+ switch options . GOARCH {
388
402
case "amd64" :
389
403
spec .LDFlags = append (spec .LDFlags ,
390
404
"-m" , "i386pep" ,
@@ -401,7 +415,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
401
415
"--no-insert-timestamp" ,
402
416
"--no-dynamicbase" ,
403
417
)
404
- } else if goos == "wasip1" {
418
+ } else if options . GOOS == "wasip1" {
405
419
spec .GC = "" // use default GC
406
420
spec .Scheduler = "asyncify"
407
421
spec .Linker = "wasm-ld"
@@ -420,25 +434,25 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
420
434
} else {
421
435
spec .LDFlags = append (spec .LDFlags , "-no-pie" , "-Wl,--gc-sections" ) // WARNING: clang < 5.0 requires -nopie
422
436
}
423
- if goarch != "wasm" {
437
+ if options . GOARCH != "wasm" {
424
438
suffix := ""
425
- if goos == "windows" && goarch == "amd64" {
439
+ if options . GOOS == "windows" && options . GOARCH == "amd64" {
426
440
// Windows uses a different calling convention on amd64 from other
427
441
// operating systems so we need separate assembly files.
428
442
suffix = "_windows"
429
443
}
430
- asmGoarch := goarch
431
- if goarch == "mips" || goarch == "mipsle" {
444
+ asmGoarch := options . GOARCH
445
+ if options . GOARCH == "mips" || options . GOARCH == "mipsle" {
432
446
asmGoarch = "mipsx"
433
447
}
434
448
spec .ExtraFiles = append (spec .ExtraFiles , "src/runtime/asm_" + asmGoarch + suffix + ".S" )
435
449
spec .ExtraFiles = append (spec .ExtraFiles , "src/internal/task/task_stack_" + asmGoarch + suffix + ".S" )
436
450
}
437
- if goarch != runtime .GOARCH {
451
+ if options . GOARCH != runtime .GOARCH {
438
452
// Some educated guesses as to how to invoke helper programs.
439
453
spec .GDB = []string {"gdb-multiarch" }
440
- if goos == "linux" {
441
- switch goarch {
454
+ if options . GOOS == "linux" {
455
+ switch options . GOARCH {
442
456
case "386" :
443
457
// amd64 can _usually_ run 32-bit programs, so skip the emulator in that case.
444
458
if runtime .GOARCH != "amd64" {
@@ -457,8 +471,8 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
457
471
}
458
472
}
459
473
}
460
- if goos != runtime .GOOS {
461
- if goos == "windows" {
474
+ if options . GOOS != runtime .GOOS {
475
+ if options . GOOS == "windows" {
462
476
spec .Emulator = "wine {}"
463
477
}
464
478
}
0 commit comments