From 3cdd5c3bcc53298dd7de39cb6e2bd600308988b8 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Thu, 12 Nov 2020 16:02:55 +0100 Subject: [PATCH] cmd/link: regression test for issue #42484 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 Run-TryBot: Emmanuel Odeke Trust: Emmanuel Odeke Reviewed-by: Than McIntosh --- src/cmd/link/internal/ld/dwarf_test.go | 71 +++++++++++++++++++ .../internal/ld/testdata/issue42484/main.go | 16 +++++ 2 files changed, 87 insertions(+) create mode 100644 src/cmd/link/internal/ld/testdata/issue42484/main.go diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go index f5f2258451..5e4151885a 100644 --- a/src/cmd/link/internal/ld/dwarf_test.go +++ b/src/cmd/link/internal/ld/dwarf_test.go @@ -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 index 0000000000..60fc110ffa --- /dev/null +++ b/src/cmd/link/internal/ld/testdata/issue42484/main.go @@ -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) +}