diff options
| author | Heschi Kreinick <heschi@google.com> | 2018-06-19 15:41:45 -0400 |
|---|---|---|
| committer | Heschi Kreinick <heschi@google.com> | 2018-06-19 22:13:51 +0000 |
| commit | 2036f16247c6702a95d6c5e876a35c8ef484dbf8 (patch) | |
| tree | ea19351688d7dec0d13f199c900f929a7faaac21 /src/debug/elf | |
| parent | 83515df3f31cc70eab2ea4af77e675cabe1eefd5 (diff) | |
| download | go-2036f16247c6702a95d6c5e876a35c8ef484dbf8.tar.xz | |
debug/elf,macho,pe: support compressed DWARF
Since we're going to start compressing DWARF on Windows and maybe
Darwin, copy the ELF support for .zdebug sections to macho and pe. The
code is almost completely the same across the three.
While I was here I added support for compressed .debug_type sections,
which I presume were overlooked before.
Tests will come in a later CL once we can actually generate compressed
PE/Mach-O binaries, since there's no other good way to get test data.
Updates #25927, #11799
Change-Id: Ie920b6a16e9270bc3df214ce601a263837810376
Reviewed-on: https://go-review.googlesource.com/119815
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/debug/elf')
| -rw-r--r-- | src/debug/elf/file.go | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index 25b72642d8..b2adc2834f 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -1112,6 +1112,17 @@ func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error { } func (f *File) DWARF() (*dwarf.Data, error) { + dwarfSuffix := func(s *Section) string { + switch { + case strings.HasPrefix(s.Name, ".debug_"): + return s.Name[7:] + case strings.HasPrefix(s.Name, ".zdebug_"): + return s.Name[8:] + default: + return "" + } + + } // sectionData gets the data for s, checks its size, and // applies any applicable relations. sectionData := func(i int, s *Section) ([]byte, error) { @@ -1160,13 +1171,8 @@ func (f *File) DWARF() (*dwarf.Data, error) { // Don't bother loading others. var dat = map[string][]byte{"abbrev": nil, "info": nil, "str": nil, "line": nil, "ranges": nil} for i, s := range f.Sections { - suffix := "" - switch { - case strings.HasPrefix(s.Name, ".debug_"): - suffix = s.Name[7:] - case strings.HasPrefix(s.Name, ".zdebug_"): - suffix = s.Name[8:] - default: + suffix := dwarfSuffix(s) + if suffix == "" { continue } if _, ok := dat[suffix]; !ok { @@ -1186,16 +1192,19 @@ func (f *File) DWARF() (*dwarf.Data, error) { // Look for DWARF4 .debug_types sections. for i, s := range f.Sections { - if s.Name == ".debug_types" { - b, err := sectionData(i, s) - if err != nil { - return nil, err - } + suffix := dwarfSuffix(s) + if suffix != "types" { + continue + } - err = d.AddTypes(fmt.Sprintf("types-%d", i), b) - if err != nil { - return nil, err - } + b, err := sectionData(i, s) + if err != nil { + return nil, err + } + + err = d.AddTypes(fmt.Sprintf("types-%d", i), b) + if err != nil { + return nil, err } } |
