Skip to content

Commit 283fed1

Browse files
aykevldeadprogram
authored andcommitted
builder: fix -no-debug linker flags
Show the correct error message when trying to strip debug information. Also, remove the special case for GOOS=linux that was probably dead code: it was only reachable on baremetal systems which were already checked before.
1 parent 76bba13 commit 283fed1

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

builder/build.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
709709
return fmt.Errorf("stripping debug information is unnecessary for baremetal targets")
710710
}
711711
}
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")
717+
}
712718
if config.Target.Linker == "wasm-ld" {
713719
// Don't just strip debug information, also compress relocations
714720
// while we're at it. Relocations can only be compressed when debug
@@ -718,21 +724,8 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
718724
// ld.lld is also used on Linux.
719725
ldflags = append(ldflags, "--strip-debug")
720726
} else {
721-
switch config.GOOS() {
722-
case "linux":
723-
// Either real linux or an embedded system (like AVR) that
724-
// pretends to be Linux. It's a ELF linker wrapped by GCC in any
725-
// case (not ld.lld - that case is handled above).
726-
ldflags = append(ldflags, "-Wl,--strip-debug")
727-
case "darwin":
728-
// MacOS (darwin) doesn't have a linker flag to strip debug
729-
// information. Apple expects you to use the strip command
730-
// instead.
731-
return errors.New("cannot remove debug information: MacOS doesn't suppor this linker flag")
732-
default:
733-
// Other OSes may have different flags.
734-
return errors.New("cannot remove debug information: unknown OS: " + config.GOOS())
735-
}
727+
// Other linkers may have different flags.
728+
return errors.New("cannot remove debug information: unknown linker: " + config.Target.Linker)
736729
}
737730
}
738731

0 commit comments

Comments
 (0)