aboutsummaryrefslogtreecommitdiff
path: root/src/debug/macho
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug/macho')
-rw-r--r--src/debug/macho/file.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go
index 7b11bb2954..fcf28c4b25 100644
--- a/src/debug/macho/file.go
+++ b/src/debug/macho/file.go
@@ -610,15 +610,33 @@ func (f *File) Section(name string) *Section {
// DWARF returns the DWARF debug information for the Mach-O file.
func (f *File) DWARF() (*dwarf.Data, error) {
dwarfSuffix := func(s *Section) string {
+ sectname := s.Name
+ var pfx int
switch {
- case strings.HasPrefix(s.Name, "__debug_"):
- return s.Name[8:]
- case strings.HasPrefix(s.Name, "__zdebug_"):
- return s.Name[9:]
+ case strings.HasPrefix(sectname, "__debug_"):
+ pfx = 8
+ case strings.HasPrefix(sectname, "__zdebug_"):
+ pfx = 9
default:
return ""
}
-
+ // Mach-O executables truncate section names to 16 characters, mangling some DWARF sections.
+ // As of DWARFv5 these are the only problematic section names (see DWARFv5 Appendix G).
+ for _, longname := range []string{
+ "__debug_str_offsets",
+ "__zdebug_line_str",
+ "__zdebug_loclists",
+ "__zdebug_pubnames",
+ "__zdebug_pubtypes",
+ "__zdebug_rnglists",
+ "__zdebug_str_offsets",
+ } {
+ if sectname == longname[:16] {
+ sectname = longname
+ break
+ }
+ }
+ return sectname[pfx:]
}
sectionData := func(s *Section) ([]byte, error) {
b, err := s.Data()