Skip to content

Commit 94c95d3

Browse files
committed
cmd/go: build test binaries with -s in addition to -w
Fixes #19753. Change-Id: Ib20a69b1d0bcc42aa9e924918bcb578d6a560a31 Reviewed-on: https://go-review.googlesource.com/38742 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 6983b9a commit 94c95d3

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/cmd/addr2line/addr2line_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,25 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
8989
func TestAddr2Line(t *testing.T) {
9090
testenv.MustHaveGoBuild(t)
9191

92-
syms := loadSyms(t)
93-
9492
tmpDir, err := ioutil.TempDir("", "TestAddr2Line")
9593
if err != nil {
9694
t.Fatal("TempDir failed: ", err)
9795
}
9896
defer os.RemoveAll(tmpDir)
9997

100-
exepath := filepath.Join(tmpDir, "testaddr2line.exe")
101-
out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
98+
// Build copy of test binary with debug symbols,
99+
// since the one running now may not have them.
100+
exepath := filepath.Join(tmpDir, "testaddr2line_test.exe")
101+
out, err := exec.Command(testenv.GoToolPath(t), "test", "-c", "-o", exepath, "cmd/addr2line").CombinedOutput()
102+
if err != nil {
103+
t.Fatalf("go test -c -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
104+
}
105+
os.Args[0] = exepath
106+
107+
syms := loadSyms(t)
108+
109+
exepath = filepath.Join(tmpDir, "testaddr2line.exe")
110+
out, err = exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
102111
if err != nil {
103112
t.Fatalf("go build -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
104113
}

src/cmd/go/internal/load/pkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type PackageInternal struct {
109109
ExeName string // desired name for temporary executable
110110
CoverMode string // preprocess Go source files with the coverage tool in this mode
111111
CoverVars map[string]*CoverVar // variables created by coverage analysis
112-
OmitDWARF bool // tell linker not to write DWARF information
112+
OmitDebug bool // tell linker not to write debug information
113113
BuildID string // expected build ID for generated package
114114
GobinSubdir bool // install target would be subdir of GOBIN
115115
}

src/cmd/go/internal/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func runRun(cmd *base.Command, args []string) {
7676
if p.Error != nil {
7777
base.Fatalf("%s", p.Error)
7878
}
79-
p.Internal.OmitDWARF = true
79+
p.Internal.OmitDebug = true
8080
if len(p.DepsErrors) > 0 {
8181
// Since these are errors in dependencies,
8282
// the same error might show up multiple times,

src/cmd/go/internal/test/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
862862
Build: &build.Package{Name: "main"},
863863
Pkgdir: testDir,
864864
Fake: true,
865-
OmitDWARF: !testC && !testNeedBinary,
865+
OmitDebug: !testC && !testNeedBinary,
866866
},
867867
}
868868

src/cmd/go/internal/work/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,8 +2417,8 @@ func (gcToolchain) ld(b *Builder, root *Action, out string, allactions []*Action
24172417
if cfg.BuildContext.InstallSuffix != "" {
24182418
ldflags = append(ldflags, "-installsuffix", cfg.BuildContext.InstallSuffix)
24192419
}
2420-
if root.Package.Internal.OmitDWARF {
2421-
ldflags = append(ldflags, "-w")
2420+
if root.Package.Internal.OmitDebug {
2421+
ldflags = append(ldflags, "-s", "-w")
24222422
}
24232423
if cfg.BuildBuildmode == "plugin" {
24242424
pluginpath := root.Package.ImportPath

0 commit comments

Comments
 (0)