@@ -100,7 +100,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
100
100
AutomaticStackSize : config .AutomaticStackSize (),
101
101
DefaultStackSize : config .Target .DefaultStackSize ,
102
102
NeedsStackObjects : config .NeedsStackObjects (),
103
- Debug : config . Debug () ,
103
+ Debug : true ,
104
104
LLVMFeatures : config .LLVMFeatures (),
105
105
}
106
106
@@ -470,33 +470,10 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
470
470
linkerDependencies = append (linkerDependencies , job )
471
471
}
472
472
473
- // Add libc dependency if needed.
474
- root := goenv .Get ("TINYGOROOT" )
475
- switch config .Target .Libc {
476
- case "picolibc" :
477
- job , err := Picolibc .load (config .Triple (), config .CPU (), dir )
478
- if err != nil {
479
- return err
480
- }
481
- // The library needs to be compiled (cache miss).
482
- jobs = append (jobs , job .dependencies ... )
483
- jobs = append (jobs , job )
484
- linkerDependencies = append (linkerDependencies , job )
485
- case "wasi-libc" :
486
- path := filepath .Join (root , "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" )
487
- if _ , err := os .Stat (path ); os .IsNotExist (err ) {
488
- return errors .New ("could not find wasi-libc, perhaps you need to run `make wasi-libc`?" )
489
- }
490
- ldflags = append (ldflags , path )
491
- case "" :
492
- // no library specified, so nothing to do
493
- default :
494
- return fmt .Errorf ("unknown libc: %s" , config .Target .Libc )
495
- }
496
-
497
473
// Add jobs to compile extra files. These files are in C or assembly and
498
474
// contain things like the interrupt vector table and low level operations
499
475
// such as stack switching.
476
+ root := goenv .Get ("TINYGOROOT" )
500
477
for _ , path := range config .ExtraFiles () {
501
478
abspath := filepath .Join (root , path )
502
479
job := & compileJob {
@@ -537,6 +514,64 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
537
514
ldflags = append (ldflags , lprogram .LDFlags ... )
538
515
}
539
516
517
+ // Add libc dependency if needed.
518
+ switch config .Target .Libc {
519
+ case "picolibc" :
520
+ job , err := Picolibc .load (config .Triple (), config .CPU (), dir )
521
+ if err != nil {
522
+ return err
523
+ }
524
+ // The library needs to be compiled (cache miss).
525
+ jobs = append (jobs , job .dependencies ... )
526
+ jobs = append (jobs , job )
527
+ linkerDependencies = append (linkerDependencies , job )
528
+ case "wasi-libc" :
529
+ path := filepath .Join (root , "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" )
530
+ if _ , err := os .Stat (path ); os .IsNotExist (err ) {
531
+ return errors .New ("could not find wasi-libc, perhaps you need to run `make wasi-libc`?" )
532
+ }
533
+ job := dummyCompileJob (path )
534
+ jobs = append (jobs , job )
535
+ linkerDependencies = append (linkerDependencies , job )
536
+ case "" :
537
+ // no library specified, so nothing to do
538
+ default :
539
+ return fmt .Errorf ("unknown libc: %s" , config .Target .Libc )
540
+ }
541
+
542
+ // Strip debug information with -no-debug.
543
+ if ! config .Debug () {
544
+ for _ , tag := range config .BuildTags () {
545
+ if tag == "baremetal" {
546
+ // Don't use -no-debug on baremetal targets. It makes no sense:
547
+ // the debug information isn't flashed to the device anyway.
548
+ return fmt .Errorf ("stripping debug information is unnecessary for baremetal targets" )
549
+ }
550
+ }
551
+ if config .Target .Linker == "wasm-ld" {
552
+ // Don't just strip debug information, also compress relocations
553
+ // while we're at it. Relocations can only be compressed when debug
554
+ // information is stripped.
555
+ ldflags = append (ldflags , "--strip-debug" , "--compress-relocations" )
556
+ } else {
557
+ switch config .GOOS () {
558
+ case "linux" :
559
+ // Either real linux or an embedded system (like AVR) that
560
+ // pretends to be Linux. It's a ELF linker wrapped by GCC in any
561
+ // case.
562
+ ldflags = append (ldflags , "-Wl,--strip-debug" )
563
+ case "darwin" :
564
+ // MacOS (darwin) doesn't have a linker flag to strip debug
565
+ // information. Apple expects you to use the strip command
566
+ // instead.
567
+ return errors .New ("cannot remove debug information: MacOS doesn't suppor this linker flag" )
568
+ default :
569
+ // Other OSes may have different flags.
570
+ return errors .New ("cannot remove debug information: unknown OS: " + config .GOOS ())
571
+ }
572
+ }
573
+ }
574
+
540
575
// Create a linker job, which links all object files together and does some
541
576
// extra stuff that can only be done after linking.
542
577
jobs = append (jobs , & compileJob {
0 commit comments