From 283fed16a5c112b1e6682b08ed61552059c90ccc Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 11 Jun 2022 12:23:53 +0200 Subject: [PATCH] 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. --- builder/build.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/builder/build.go b/builder/build.go index cb936857..ab5b2b44 100644 --- a/builder/build.go +++ b/builder/build.go @@ -709,6 +709,12 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil return fmt.Errorf("stripping debug information is unnecessary for baremetal targets") } } + if config.GOOS() == "darwin" { + // Debug information isn't stored in the binary itself on MacOS but + // is left in the object files by default. The binary does store the + // path to these object files though. + return errors.New("cannot remove debug information: MacOS doesn't store debug info in the executable by default") + } if config.Target.Linker == "wasm-ld" { // Don't just strip debug information, also compress relocations // 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 // ld.lld is also used on Linux. ldflags = append(ldflags, "--strip-debug") } else { - switch config.GOOS() { - case "linux": - // Either real linux or an embedded system (like AVR) that - // pretends to be Linux. It's a ELF linker wrapped by GCC in any - // case (not ld.lld - that case is handled above). - ldflags = append(ldflags, "-Wl,--strip-debug") - case "darwin": - // MacOS (darwin) doesn't have a linker flag to strip debug - // information. Apple expects you to use the strip command - // instead. - return errors.New("cannot remove debug information: MacOS doesn't suppor this linker flag") - default: - // Other OSes may have different flags. - return errors.New("cannot remove debug information: unknown OS: " + config.GOOS()) - } + // Other linkers may have different flags. + return errors.New("cannot remove debug information: unknown linker: " + config.Target.Linker) } }