]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: regression test for issue #42484
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>
Thu, 12 Nov 2020 15:02:55 +0000 (16:02 +0100)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Sun, 14 Mar 2021 21:10:45 +0000 (21:10 +0000)
Adds test to check that the compiler does not emit duplicate debug_line
entries for the end of sequence address.

Updates #42484

Change-Id: I3c5d1d606fcfd758aa1fd83ecc51d8edc054398b
Reviewed-on: https://go-review.googlesource.com/c/go/+/270197
TryBot-Result: Go Bot <gobot@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/dwarf_test.go
src/cmd/link/internal/ld/testdata/issue42484/main.go [new file with mode: 0644]

index f5f2258451bffdaaf7d7a9ea69065b450e53d087..5e4151885ab61d7bca2891fca2b145e0961c825c 100644 (file)
@@ -1570,3 +1570,74 @@ func TestIssue39757(t *testing.T) {
                }
        }
 }
+
+func TestIssue42484(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
+       if runtime.GOOS == "plan9" {
+               t.Skip("skipping on plan9; no DWARF symbol table in executables")
+       }
+
+       t.Parallel()
+
+       tmpdir, err := ioutil.TempDir("", "TestIssue42484")
+       if err != nil {
+               t.Fatalf("could not create directory: %v", err)
+       }
+       defer os.RemoveAll(tmpdir)
+       wd, err := os.Getwd()
+       if err != nil {
+               t.Fatalf("where am I? %v", err)
+       }
+       pdir := filepath.Join(wd, "testdata", "issue42484")
+       f := gobuildTestdata(t, tmpdir, pdir, NoOpt)
+
+       var lastAddr uint64
+       var lastFile string
+       var lastLine int
+
+       dw, err := f.DWARF()
+       if err != nil {
+               t.Fatalf("error parsing DWARF: %v", err)
+       }
+       rdr := dw.Reader()
+       for {
+               e, err := rdr.Next()
+               if err != nil {
+                       t.Fatalf("error reading DWARF: %v", err)
+               }
+               if e == nil {
+                       break
+               }
+               if e.Tag != dwarf.TagCompileUnit {
+                       continue
+               }
+               lnrdr, err := dw.LineReader(e)
+               if err != nil {
+                       t.Fatalf("error creating DWARF line reader: %v", err)
+               }
+               if lnrdr != nil {
+                       var lne dwarf.LineEntry
+                       for {
+                               err := lnrdr.Next(&lne)
+                               if err == io.EOF {
+                                       break
+                               }
+                               if err != nil {
+                                       t.Fatalf("error reading next DWARF line: %v", err)
+                               }
+                               if lne.EndSequence {
+                                       continue
+                               }
+                               if lne.Address == lastAddr && (lne.File.Name != lastFile || lne.Line != lastLine) {
+                                       t.Errorf("address %#x is assigned to both %s:%d and %s:%d", lastAddr, lastFile, lastLine, lne.File.Name, lne.Line)
+                               }
+                               lastAddr = lne.Address
+                               lastFile = lne.File.Name
+                               lastLine = lne.Line
+                       }
+               }
+               rdr.SkipChildren()
+       }
+       f.Close()
+}
diff --git a/src/cmd/link/internal/ld/testdata/issue42484/main.go b/src/cmd/link/internal/ld/testdata/issue42484/main.go
new file mode 100644 (file)
index 0000000..60fc110
--- /dev/null
@@ -0,0 +1,16 @@
+package main
+
+import (
+       "fmt"
+)
+
+func main() {
+       a := 0
+       a++
+       b := 0
+       f1(a, b)
+}
+
+func f1(a, b int) {
+       fmt.Printf("%d %d\n", a, b)
+}