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 <adrian@tetrate.io>
Этот коммит содержится в:
родитель
f52ecf3054
коммит
e91fae5756
2 изменённых файлов: 20 добавлений и 16 удалений
|
@ -700,21 +700,25 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||||
// Add embedded files.
|
// Add embedded files.
|
||||||
linkerDependencies = append(linkerDependencies, embedFileObjects...)
|
linkerDependencies = append(linkerDependencies, embedFileObjects...)
|
||||||
|
|
||||||
|
// Determine whether the compilation configuration would result in debug
|
||||||
|
// (DWARF) information in the object files.
|
||||||
|
var hasDebug = true
|
||||||
|
for _, tag := range config.BuildTags() {
|
||||||
|
if tag == "baremetal" {
|
||||||
|
// Don't use -no-debug on baremetal targets. It makes no sense:
|
||||||
|
// the debug information isn't flashed to the device anyway.
|
||||||
|
hasDebug = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
hasDebug = false
|
||||||
|
}
|
||||||
|
|
||||||
// Strip debug information with -no-debug.
|
// Strip debug information with -no-debug.
|
||||||
if !config.Debug() {
|
if hasDebug && !config.Debug() {
|
||||||
for _, tag := range config.BuildTags() {
|
|
||||||
if tag == "baremetal" {
|
|
||||||
// Don't use -no-debug on baremetal targets. It makes no sense:
|
|
||||||
// the debug information isn't flashed to the device anyway.
|
|
||||||
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" {
|
if config.Target.Linker == "wasm-ld" {
|
||||||
// Don't just strip debug information, also compress relocations
|
// Don't just strip debug information, also compress relocations
|
||||||
// while we're at it. Relocations can only be compressed when debug
|
// while we're at it. Relocations can only be compressed when debug
|
||||||
|
|
|
@ -377,8 +377,8 @@ func (c *Config) VerifyIR() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug returns whether debug (DWARF) information should be retained by the
|
// Debug returns whether debug (DWARF) information should be retained by the
|
||||||
// linker. By default, debug information is retained but it can be removed with
|
// linker. By default, debug information is retained, but it can be removed
|
||||||
// the -no-debug flag.
|
// with the -no-debug flag.
|
||||||
func (c *Config) Debug() bool {
|
func (c *Config) Debug() bool {
|
||||||
return c.Options.Debug
|
return c.Options.Debug
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче