]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: skip writing dwarf debug info for ephemeral binaries
authorRuss Cox <rsc@golang.org>
Wed, 19 Feb 2014 15:01:15 +0000 (10:01 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 19 Feb 2014 15:01:15 +0000 (10:01 -0500)
Update #6853

For an ephemeral binary - one created, run, and then deleted -
there is no need to write dwarf debug information, since the
binary will not be used with gdb. In this case, instruct the linker
not to spend time and disk space generating the debug information
by passing the -w flag to the linker.

Omitting dwarf information reduces the size of most binaries by 25%.
We may be more aggressive about this in the future.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/65890043

src/cmd/go/build.go
src/cmd/go/pkg.go
src/cmd/go/run.go
src/cmd/go/test.go
test/run.go

index 824351b7e61c39107209cc4bbdff3cda1e1da009..dcc24d99c42979ca97afdeeef9c92571e93581b4 100644 (file)
@@ -1714,6 +1714,10 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
        if buildContext.InstallSuffix != "" {
                ldflags = append(ldflags, "-installsuffix", buildContext.InstallSuffix)
        }
+       if p.omitDWARF {
+               ldflags = append(ldflags, "-w")
+       }
+
        // If the user has not specified the -extld option, then specify the
        // appropriate linker. In case of C++ code, use the compiler named
        // by the CXX environment variable or defaultCXX if CXX is not set.
index 0190b6784f02f0df87b22173c1a8ec22c0ee7249..3ff3862700ca105cf9a10ada13d283cf32a19faf 100644 (file)
@@ -89,6 +89,7 @@ type Package struct {
        exeName      string               // desired name for temporary executable
        coverMode    string               // preprocess Go source files with the coverage tool in this mode
        coverVars    map[string]*CoverVar // variables created by coverage analysis
+       omitDWARF    bool                 // tell linker not to write DWARF information
 }
 
 // CoverVar holds the name of the generated coverage variables targeting the named file.
index e6dadd2296e37258fb4e46940caf9984324ae12a..8d42622b8660168c52f546d52a882f420f912013 100644 (file)
@@ -58,6 +58,7 @@ func runRun(cmd *Command, args []string) {
        if p.Error != nil {
                fatalf("%s", p.Error)
        }
+       p.omitDWARF = true
        for _, err := range p.DepsErrors {
                errorf("%s", err)
        }
index dcba12e11cd9f1b89f13d68852f6d4440539e407..26b7f87f48f5cb60a1d494e9b877be2d93a3597d 100644 (file)
@@ -654,6 +654,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                pkgdir:     testDir,
                fake:       true,
                Stale:      true,
+               omitDWARF:  !testC && !testNeedBinary,
        }
        if pxtest != nil {
                pmain.imports = append(pmain.imports, pxtest)
index e5190e4e79bee36f20c31f9c92e25f25ae68cc92..9a4d794ad2fb2a7974aa07ce7f24cfa5b1f53185 100644 (file)
@@ -200,7 +200,7 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e
 
 func linkFile(runcmd runCmd, goname string) (err error) {
        pfile := strings.Replace(goname, ".go", "."+letter, -1)
-       _, err = runcmd("go", "tool", ld, "-o", "a.exe", "-L", ".", pfile)
+       _, err = runcmd("go", "tool", ld, "-w", "-o", "a.exe", "-L", ".", pfile)
        return
 }