]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: build test binaries with -s in addition to -w
authorRuss Cox <rsc@golang.org>
Wed, 29 Mar 2017 14:16:50 +0000 (10:16 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 29 Mar 2017 17:18:16 +0000 (17:18 +0000)
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>
src/cmd/addr2line/addr2line_test.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/run/run.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/build.go

index 2bd2e358c7fec42a4b6a2ffe88d94568dbe67433..22bf1379bb72147c6ccbf72603e4fc8654356478 100644 (file)
@@ -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))
        }
index 1609459ef8ebced0ae8c6faf59e381a9c9b08813..52c2085ef5f0903246c4f1f667f518ea26b8f567 100644 (file)
@@ -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
 }
index 980e160fee8b7446e9fd1393e002b5991fbb2e80..6e276c28ec19f96f59caed7531c4c2dc3e281348 100644 (file)
@@ -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,
index 961466c2ff72bdf500fa1b784de397e6f9ac73cd..62a1ed1ee410a9a1d8ed02e8e9eb7c6d7d8b3ed2 100644 (file)
@@ -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,
                },
        }
 
index c09d8d35130dfb2fc7d1fd4539b2655d2625bacb..870e4d7762d2b1c111abb3ca1c83c63a863e1086 100644 (file)
@@ -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