]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: omit DWARF in build release toolchain binaries
authorRuss Cox <rsc@golang.org>
Wed, 8 Mar 2023 19:48:41 +0000 (14:48 -0500)
committerGopher Robot <gobot@golang.org>
Mon, 13 Mar 2023 16:49:42 +0000 (16:49 +0000)
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>

src/cmd/compile/internal/ssa/stmtlines_test.go
src/cmd/dist/build.go

index 4dadfe863079ed1342e79af1b85e94a46611d400..dd3ce7c1d87d8c1768a9649f5efc8ffc6c1a7c9d 100644 (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)
index 343f0ce332f82b4db2deb90f19b6a33b44f5e2b2..25f75804e04550f25ebdd0559b8e2e0553134a84 100644 (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
 }