Skip to content

Commit

Permalink
[dwarfdump] Recognize __apple sections as debug info sections
Browse files Browse the repository at this point in the history
Recognize the __apple_ sections as debug info sections and make sure
they're included in the --show-sections-sizes output.

Differential revision: https://reviews.llvm.org/D90433
  • Loading branch information
JDevlieghere committed Oct 30, 2020
1 parent 29f9db7 commit db3dba5
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 32 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Object/MachOObjectFile.cpp
Expand Up @@ -2032,7 +2032,8 @@ bool MachOObjectFile::isSectionBSS(DataRefImpl Sec) const {

bool MachOObjectFile::isDebugSection(StringRef SectionName) const {
return SectionName.startswith("__debug") ||
SectionName.startswith("__zdebug") || SectionName == "__gdb_index";
SectionName.startswith("__zdebug") ||
SectionName.startswith("__apple") || SectionName == "__gdb_index";
}

unsigned MachOObjectFile::getSectionID(SectionRef Sec) const {
Expand Down
223 changes: 192 additions & 31 deletions llvm/test/tools/llvm-dwarfdump/X86/section_sizes_macho.test
Expand Up @@ -7,12 +7,19 @@
# CHECK:----------------------------------------------------
# CHECK-NEXT:file: {{.*}}
# CHECK-NEXT:----------------------------------------------------
# CHECK-NEXT:SECTION SIZE (b)
# CHECK-NEXT:------------ --------
# CHECK-NEXT:__debug_info 4 (0.93%)
# CHECK-NEXT:SECTION SIZE (b)
# CHECK-NEXT:---------------- --------
# CHECK-NEXT:__debug_info 83 (4.43%)
# CHECK-NEXT:__apple_names 60 (3.21%)
# CHECK-NEXT:__apple_types 71 (3.79%)
# CHECK-NEXT:__debug_abbrev 58 (3.10%)
# CHECK-NEXT:__apple_namespac 36 (1.92%)
# CHECK-NEXT:__debug_line 61 (3.26%)
# CHECK-NEXT:__debug_str 183 (9.78%)
# CHECK-NEXT:__apple_objc 36 (1.92%)
# CHECK-EMPTY:
# CHECK-NEXT: Total Size: 4 (0.93%)
# CHECK-NEXT: Total File Size: 432
# CHECK-NEXT: Total Size: 588 (31.41%)
# CHECK-NEXT: Total File Size: 1872
# CHECK-NEXT:----------------------------------------------------

--- !mach-o
Expand All @@ -22,69 +29,218 @@ FileHeader:
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 4
sizeofcmds: 360
sizeofcmds: 1080
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
cmdsize: 952
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 0
vmsize: 701
fileoff: 1112
filesize: 701
maxprot: 7
initprot: 7
nsects: 2
nsects: 11
flags: 0
Sections:
## This is a debug section following the ELF naming style, and is used
## to show that such sections are not included in the report.
- sectname: .debug_line
segname: __DWARF
addr: 0x0000000000000000
size: 0
offset: 0x00000188
size: 15
offset: 0x00000458
align: 4
reloff: 0x00000000
nreloc: 0
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 554889E531C0C745FC000000005DC3
- sectname: __debug_str
segname: __DWARF
addr: 0x000000000000000F
size: 183
offset: 0x00000467
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __debug_abbrev
segname: __DWARF
addr: 0x00000000000000C6
size: 58
offset: 0x0000051E
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000000
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: ''
- sectname: __debug_info
segname: __DWARF
addr: 0x0000000000000000
size: 4
offset: 0x00000000
align: 2
addr: 0x0000000000000100
size: 83
offset: 0x00000558
align: 0
reloff: 0x00000718
nreloc: 2
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
relocations:
- address: 0x00000033
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- address: 0x00000026
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- sectname: __apple_names
segname: __DWARF
addr: 0x0000000000000153
size: 60
offset: 0x000005AB
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 485341480100000001000000010000000C000000000000000100000001000600000000006A7F9A7C2C000000AE000000010000003200000000000000
- sectname: __apple_objc
segname: __DWARF
addr: 0x000000000000018F
size: 36
offset: 0x000005E7
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x00000001
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
- sectname: __apple_namespac
segname: __DWARF
addr: 0x00000000000001B3
size: 36
offset: 0x0000060B
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
- sectname: __apple_types
segname: __DWARF
addr: 0x00000000000001D7
size: 71
offset: 0x0000062F
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 48534148010000000100000001000000140000000000000003000000010006000300050004000B00000000003080880B34000000B3000000010000004B00000024000000000000
- sectname: __compact_unwind
segname: __LD
addr: 0x0000000000000220
size: 32
offset: 0x00000678
align: 3
reloff: 0x00000728
nreloc: 1
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 00000000000000000F0000000000000100000000000000000000000000000000
relocations:
- address: 0x00000000
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- sectname: __eh_frame
segname: __TEXT
addr: 0x0000000000000240
size: 64
offset: 0x00000698
align: 3
reloff: 0x00000000
nreloc: 0
flags: 0x6800000B
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 1400000000000000017A520001781001100C070890010000240000001C000000A0FDFFFFFFFFFFFF0F0000000000000000410E108602430D0600000000000000
- sectname: __debug_line
segname: __DWARF
addr: 0x0000000000000280
size: 61
offset: 0x000006D8
align: 0
reloff: 0x00000730
nreloc: 1
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
relocations:
- address: 0x0000002B
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- cmd: LC_BUILD_VERSION
cmdsize: 24
platform: 1
minos: 658944
sdk: 658944
minos: 720896
sdk: 720896
ntools: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 392
nsyms: 2
stroff: 424
symoff: 1848
nsyms: 1
stroff: 1864
strsize: 8
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 1
iextdefsym: 1
nextdefsym: 0
nlocalsym: 0
iextdefsym: 0
nextdefsym: 1
iundefsym: 1
nundefsym: 1
nundefsym: 0
tocoff: 0
ntoc: 0
modtaboff: 0
Expand All @@ -98,9 +254,14 @@ LoadCommands:
locreloff: 0
nlocrel: 0
LinkEditData:
NameList:
- n_strx: 1
n_type: 0x0F
n_sect: 1
n_desc: 0
n_value: 0
StringTable:
- ''
- _b
- _a
- _main
- ''
...
4 changes: 4 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
Expand Up @@ -56,9 +56,13 @@
; CHECK: "#bytes within inlined functions": [[INLINESIZE:[0-9]+]]
; CHECK: "#bytes in __debug_info": 459,
; CHECK-NEXT: "#bytes in __debug_loc": 35,
; CHECK-NEXT: "#bytes in __apple_names": 348,
; CHECK-NEXT: "#bytes in __apple_types": 133,
; CHECK-NEXT: "#bytes in __debug_abbrev": 384,
; CHECK-NEXT: "#bytes in __apple_namespac": 60,
; CHECK-NEXT: "#bytes in __debug_line": 126,
; CHECK-NEXT: "#bytes in __debug_str": 231,
; CHECK-NEXT: "#bytes in __apple_objc": 36,

; ModuleID = '/tmp/quality.cpp'
source_filename = "/tmp/quality.cpp"
Expand Down

0 comments on commit db3dba5

Please sign in to comment.