1
0
mirror of https://github.com/golang/go synced 2024-11-07 09:36:11 -07:00

cmd/dist: omit DWARF in build release toolchain binaries

The vast majority of users of Go toolchains have no need for
binaries like the go command and compiler to include DWARF
information, and the DWARF information is 34% of the size of
the overall Go toolchain zip files (14% when the toolchain is
unzipped on disk, because other parts get bigger).

To save network and disk, disable DWARF in build release binaries.
DWARF remains enabled when developing in the main branch
(signaled by no VERSION file existing), for better debuggability
when actually working on the compiler and go command.

Note that removing DWARF does not break the backtraces shown
when a binary panics, nor does it break other uses of stack traces
from within a Go program, such as runtime.Callers.

To build a release toolchain with DWARF included, people can use

	GO_LDFLAGS=-w=0 ./make.bash

Change-Id: Ib0bbe1446adca4599066b2fb2f2734e6825c1106
Reviewed-on: https://go-review.googlesource.com/c/go/+/475378
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2023-03-08 14:48:41 -05:00 committed by Gopher Robot
parent 91c82ff7c9
commit c67a27bf75
2 changed files with 9 additions and 2 deletions

View File

@ -75,8 +75,15 @@ func TestStmtLines(t *testing.T) {
}
}
// Build cmd/go forcing DWARF enabled, as a large test case.
dir := t.TempDir()
out, err := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-w=0", "-o", dir+"/test.exe", "cmd/go").CombinedOutput()
if err != nil {
t.Fatalf("go build: %v\n%s", err, out)
}
lines := map[Line]bool{}
dw, err := open(testenv.GoToolPath(t))
dw, err := open(dir + "/test.exe")
must(err)
rdr := dw.Reader()
rdr.Seek(0)

View File

@ -1328,7 +1328,7 @@ func toolenv() []string {
// Do not include local development, so that people working in the
// main branch for day-to-day work on the Go toolchain itself can
// still have full paths for stack traces for compiler crashes and the like.
env = append(env, "GOFLAGS=-trimpath")
env = append(env, "GOFLAGS=-trimpath -ldflags=-w -gcflags=cmd/...=-dwarf=false")
}
return env
}