Skip to content

Commit

Permalink
cmd/go: build test binaries with -s in addition to -w
Browse files Browse the repository at this point in the history
Fixes #19753.

Change-Id: Ib20a69b1d0bcc42aa9e924918bcb578d6a560a31
Reviewed-on: https://go-review.googlesource.com/38742
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
rsc committed Mar 29, 2017
1 parent 6983b9a commit 94c95d3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/cmd/addr2line/addr2line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,25 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
func TestAddr2Line(t *testing.T) {
testenv.MustHaveGoBuild(t)

syms := loadSyms(t)

tmpDir, err := ioutil.TempDir("", "TestAddr2Line")
if err != nil {
t.Fatal("TempDir failed: ", err)
}
defer os.RemoveAll(tmpDir)

exepath := filepath.Join(tmpDir, "testaddr2line.exe")
out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
// Build copy of test binary with debug symbols,
// since the one running now may not have them.
exepath := filepath.Join(tmpDir, "testaddr2line_test.exe")
out, err := exec.Command(testenv.GoToolPath(t), "test", "-c", "-o", exepath, "cmd/addr2line").CombinedOutput()
if err != nil {
t.Fatalf("go test -c -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
}
os.Args[0] = exepath

syms := loadSyms(t)

exepath = filepath.Join(tmpDir, "testaddr2line.exe")
out, err = exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
if err != nil {
t.Fatalf("go build -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type PackageInternal 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
OmitDebug bool // tell linker not to write debug information
BuildID string // expected build ID for generated package
GobinSubdir bool // install target would be subdir of GOBIN
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runRun(cmd *base.Command, args []string) {
if p.Error != nil {
base.Fatalf("%s", p.Error)
}
p.Internal.OmitDWARF = true
p.Internal.OmitDebug = true
if len(p.DepsErrors) > 0 {
// Since these are errors in dependencies,
// the same error might show up multiple times,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
Build: &build.Package{Name: "main"},
Pkgdir: testDir,
Fake: true,
OmitDWARF: !testC && !testNeedBinary,
OmitDebug: !testC && !testNeedBinary,
},
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,8 @@ func (gcToolchain) ld(b *Builder, root *Action, out string, allactions []*Action
if cfg.BuildContext.InstallSuffix != "" {
ldflags = append(ldflags, "-installsuffix", cfg.BuildContext.InstallSuffix)
}
if root.Package.Internal.OmitDWARF {
ldflags = append(ldflags, "-w")
if root.Package.Internal.OmitDebug {
ldflags = append(ldflags, "-s", "-w")
}
if cfg.BuildBuildmode == "plugin" {
pluginpath := root.Package.ImportPath
Expand Down

0 comments on commit 94c95d3

Please sign in to comment.