summaryrefslogtreecommitdiff
path: root/src/cmd/go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-02-19 10:01:15 -0500
committerRuss Cox <rsc@golang.org>2014-02-19 10:01:15 -0500
commit7209150602573c53ebaa2325ec582043b8abcf4e (patch)
tree8878e7a03f4e16e1cf3280a16f3c7e36f5f76a0c /src/cmd/go
parenta9abe9b9cb53da1d07751c3a37718af06298c52b (diff)
downloadgo-7209150602573c53ebaa2325ec582043b8abcf4e.tar.gz
cmd/go: skip writing dwarf debug info for ephemeral binaries
Update issue 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://codereview.appspot.com/65890043
Diffstat (limited to 'src/cmd/go')
-rw-r--r--src/cmd/go/build.go4
-rw-r--r--src/cmd/go/pkg.go1
-rw-r--r--src/cmd/go/run.go1
-rw-r--r--src/cmd/go/test.go1
4 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index 824351b7e..dcc24d99c 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -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.
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 0190b6784..3ff386270 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -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.
diff --git a/src/cmd/go/run.go b/src/cmd/go/run.go
index e6dadd229..8d42622b8 100644
--- a/src/cmd/go/run.go
+++ b/src/cmd/go/run.go
@@ -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)
}
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index dcba12e11..26b7f87f4 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -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)