Skip to content

Commit e91fae5

Browse files
codefromthecryptdeadprogram
authored andcommitted
compileopts: silently succeed when there's no debug info to strip
Before, on the baremetal target or MacOS, we errored if the user provided configuration to strip debug info. Ex. ```bash $ $ tinygo build -o main.go -scheduler=none --no-debug main.go error: cannot remove debug information: MacOS doesn't store debug info in the executable by default ``` This is a poor experience which results in having OS-specific CLI behavior. Silently succeeding is good keeping with the Linux philosophy and less distracting than logging the same without failing. Signed-off-by: Adrian Cole <[email protected]>
1 parent f52ecf3 commit e91fae5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

builder/build.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -700,21 +700,25 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
700700
// Add embedded files.
701701
linkerDependencies = append(linkerDependencies, embedFileObjects...)
702702

703-
// Strip debug information with -no-debug.
704-
if !config.Debug() {
705-
for _, tag := range config.BuildTags() {
706-
if tag == "baremetal" {
707-
// Don't use -no-debug on baremetal targets. It makes no sense:
708-
// the debug information isn't flashed to the device anyway.
709-
return fmt.Errorf("stripping debug information is unnecessary for baremetal targets")
710-
}
711-
}
712-
if config.GOOS() == "darwin" {
713-
// Debug information isn't stored in the binary itself on MacOS but
714-
// is left in the object files by default. The binary does store the
715-
// path to these object files though.
716-
return errors.New("cannot remove debug information: MacOS doesn't store debug info in the executable by default")
703+
// Determine whether the compilation configuration would result in debug
704+
// (DWARF) information in the object files.
705+
var hasDebug = true
706+
for _, tag := range config.BuildTags() {
707+
if tag == "baremetal" {
708+
// Don't use -no-debug on baremetal targets. It makes no sense:
709+
// the debug information isn't flashed to the device anyway.
710+
hasDebug = false
717711
}
712+
}
713+
if config.GOOS() == "darwin" {
714+
// Debug information isn't stored in the binary itself on MacOS but
715+
// is left in the object files by default. The binary does store the
716+
// path to these object files though.
717+
hasDebug = false
718+
}
719+
720+
// Strip debug information with -no-debug.
721+
if hasDebug && !config.Debug() {
718722
if config.Target.Linker == "wasm-ld" {
719723
// Don't just strip debug information, also compress relocations
720724
// while we're at it. Relocations can only be compressed when debug

compileopts/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ func (c *Config) VerifyIR() bool {
377377
}
378378

379379
// Debug returns whether debug (DWARF) information should be retained by the
380-
// linker. By default, debug information is retained but it can be removed with
381-
// the -no-debug flag.
380+
// linker. By default, debug information is retained, but it can be removed
381+
// with the -no-debug flag.
382382
func (c *Config) Debug() bool {
383383
return c.Options.Debug
384384
}

0 commit comments

Comments
 (0)