From 2036f16247c6702a95d6c5e876a35c8ef484dbf8 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Tue, 19 Jun 2018 15:41:45 -0400 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Austin Clements --- src/debug/elf/file.go | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/debug/elf') 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 } } -- cgit v1.3-5-g9baa