forked from OSchip/llvm-project
[MachOYAML] Allow handcrafting custom contents for DWARF sections.
This patch enables users to handcraft custom contents for DWARF sections. If we specify the contents of DWARF sections both in the 'DWARF' entry and the 'content', yaml2obj will emit an error message. In addition, this patch helps remove the restriction that only the content of sections whose segname are __DWARF can be specified in the "DWARF" entry. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D87126
This commit is contained in:
parent
3404add468
commit
2966d6e80b
|
@ -285,16 +285,20 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
|
|||
return createStringError(
|
||||
errc::invalid_argument,
|
||||
"wrote too much data somewhere, section offsets don't line up");
|
||||
if (0 == strncmp(&Sec.segname[0], "__DWARF", sizeof(Sec.segname))) {
|
||||
StringRef SectName(Sec.sectname,
|
||||
strnlen(Sec.sectname, sizeof(Sec.sectname)));
|
||||
if (Obj.DWARF.getNonEmptySectionNames().count(SectName.substr(2))) {
|
||||
auto EmitFunc =
|
||||
DWARFYAML::getDWARFEmitterByName(SectName.substr(2));
|
||||
if (Error Err = EmitFunc(OS, Obj.DWARF))
|
||||
return Err;
|
||||
}
|
||||
|
||||
StringRef SectName(Sec.sectname,
|
||||
strnlen(Sec.sectname, sizeof(Sec.sectname)));
|
||||
// If the section's content is specified in the 'DWARF' entry, we will
|
||||
// emit it regardless of the section's segname.
|
||||
if (Obj.DWARF.getNonEmptySectionNames().count(SectName.substr(2))) {
|
||||
if (Sec.content)
|
||||
return createStringError(errc::invalid_argument,
|
||||
"cannot specify section '" + SectName +
|
||||
"' contents in the 'DWARF' entry and "
|
||||
"the 'content' at the same time");
|
||||
auto EmitFunc = DWARFYAML::getDWARFEmitterByName(SectName.substr(2));
|
||||
if (Error Err = EmitFunc(OS, Obj.DWARF))
|
||||
return Err;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 011101030E1305110155170000022E00030E110112060000032E00030E11011201000000
|
||||
- sectname: __debug_info
|
||||
segname: __DWARF
|
||||
addr: 0x0000000000000024
|
||||
|
@ -106,7 +105,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 520000000400000000000801010000000400000000000000000000000000020D000000000000000000000020000000031700000000000000000000003000000000000000022100000000100000000000000010000000
|
||||
- sectname: __debug_ranges
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000007A
|
||||
|
@ -119,7 +117,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 0000000000000000200000000000000000000000000000003000000000000000FFFFFFFFFFFFFFFF00100000000000000000000000000000001000000000000000000000000000000000000000000000
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x00000000000000CA
|
||||
|
@ -132,7 +129,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 002F746D702F6D61696E2E630073747269707065643100737472697070656432006D61696E00
|
||||
- cmd: LC_SYMTAB
|
||||
cmdsize: 24
|
||||
symoff: 0
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
## Test that yaml2obj emits an error message if we specify the DWARF section
|
||||
## contents both in the 'DWARF' entry and in the 'content'.
|
||||
|
||||
# RUN: not yaml2obj %s 2>&1 | FileCheck %s --check-prefix=CONFLICT
|
||||
|
||||
# CONFLICT: yaml2obj: error: cannot specify section '__debug_str' contents in the 'DWARF' entry and the 'content' at the same time
|
||||
|
||||
--- !mach-o
|
||||
FileHeader:
|
||||
magic: 0xFEEDFACF
|
||||
cputype: 0x01000007
|
||||
cpusubtype: 0x00000003
|
||||
filetype: 0x0000000A
|
||||
ncmds: 1
|
||||
sizeofcmds: 232
|
||||
flags: 0x00000000
|
||||
reserved: 0x00000000
|
||||
LoadCommands:
|
||||
- cmd: LC_SEGMENT_64
|
||||
cmdsize: 152
|
||||
segname: __DWARF
|
||||
vmaddr: 0x00
|
||||
vmsize: 0x00
|
||||
fileoff: 0x00
|
||||
filesize: 0x00
|
||||
maxprot: 0
|
||||
initprot: 0
|
||||
nsects: 1
|
||||
flags: 0
|
||||
Sections:
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x00
|
||||
size: 12
|
||||
offset: 528
|
||||
align: 0
|
||||
reloff: 0x00000000
|
||||
nreloc: 0
|
||||
flags: 0x00000000
|
||||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1234
|
||||
DWARF:
|
||||
debug_str: [ a, abc ]
|
|
@ -101,7 +101,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 011101030E1305110155170000022E00030E110112060000032E00030E11011201000000
|
||||
- sectname: __debug_info
|
||||
segname: __DWARF
|
||||
addr: 0x0000000000000024
|
||||
|
@ -114,7 +113,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 630000000400000000000801010000000200000000000000000000000000020D0000000000000000000000200000000317000000000000000000000030000000000000000221000000001000000000000000100000022600000000200000000000000010000000
|
||||
- sectname: __debug_ranges
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000008B
|
||||
|
@ -127,7 +125,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: '0020000000000000003000000000000000000000000000002000000000000000000000000000000030000000000000000010000000000000002000000000000000000000000000000000000000000000'
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x00000000000000DB
|
||||
|
@ -140,7 +137,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 002F746D702F6D61696E2E630073747269707065643100737472697070656432006D61696E00666F6F00
|
||||
- cmd: LC_SYMTAB
|
||||
cmdsize: 24
|
||||
symoff: 0
|
||||
|
|
|
@ -139,7 +139,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 37000000040020000000010101FB0E0D000101010100000001000001006D61696E2E6370700000000000000502F0BF00000105020A9F0206000101
|
||||
- sectname: __debug_pubnames
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D03B
|
||||
|
@ -152,7 +151,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1700000002000000000077000000260000006D61696E0000000000
|
||||
- sectname: __debug_pubtypes
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D056
|
||||
|
@ -165,7 +163,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1F0000000200000000007700000059000000696E74006F000000636861720000000000
|
||||
- sectname: __debug_aranges
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D079
|
||||
|
@ -178,7 +175,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1C000000020000000000040000000000F0BF0000100000000000000000000000
|
||||
- sectname: __debug_info
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D099
|
||||
|
@ -191,7 +187,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 73000000040000000000040101000000040031000000000000003A000000F0BF00001000000002F0BF00001000000001573F0000000101590000000103027D044400000001015900000003027D004900000001016000000000044E00000005040565000000056A000000066F0000000452000000060100
|
||||
- sectname: __debug_abbrev
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D110
|
||||
|
@ -204,7 +199,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 011101250E1305030E10171B0EB44219110112060000022E01110112064018030E3A0B3B0B49103F19E37F0C00000305000218030E3A0B3B0B49100000042400030E3E0B0B0B0000050F00491000000626004910000000
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D167
|
||||
|
@ -217,7 +211,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 004170706C6520636C616E672076657273696F6E2031312E302E302028636C616E672D313130302E302E33332E313729006D61696E2E637070002F746D70006D61696E0061726763006172677600696E74006368617200
|
||||
- sectname: __apple_names
|
||||
segname: __DWARF
|
||||
addr: 0x000000000000D1BE
|
||||
|
@ -614,7 +607,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 3B000000040020000000010101FB0E0D000101010100000001000001006D61696E2E63707000000000000009029C7F0000010000000105020AF3020C000101
|
||||
- sectname: __debug_pubnames
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000903F
|
||||
|
@ -627,7 +619,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 170000000200000000007E0000002A0000006D61696E0000000000
|
||||
- sectname: __debug_pubtypes
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000905A
|
||||
|
@ -640,7 +631,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1F0000000200000000007E00000060000000696E740076000000636861720000000000
|
||||
- sectname: __debug_aranges
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000907D
|
||||
|
@ -653,7 +643,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 2C0000000200000000000800000000009C7F0000010000001C0000000000000000000000000000000000000000000000
|
||||
- sectname: __debug_info
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000090AD
|
||||
|
@ -666,7 +655,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 7A000000040000000000080101000000040031000000000000003A0000009C7F0000010000001C000000029C7F0000010000001C000000016F3F0000000101600000000302910844000000010160000000030291004900000001016700000000044E0000000504056C000000057100000006760000000452000000060100
|
||||
- sectname: __debug_abbrev
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000912B
|
||||
|
@ -679,7 +667,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 011101250E1305030E10171B0EB44219110112060000022E01110112064018030E3A0B3B0B49103F1900000305000218030E3A0B3B0B49100000042400030E3E0B0B0B0000050F00491000000626004910000000
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000917F
|
||||
|
@ -692,7 +679,6 @@ Slices:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 004170706C6520636C616E672076657273696F6E2031312E302E302028636C616E672D313130302E302E33332E313729006D61696E2E637070002F746D70006D61696E0061726763006172677600696E74006368617200
|
||||
- sectname: __apple_names
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000091D6
|
||||
|
|
|
@ -215,7 +215,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 66000000040020000000010101FB0E0D000101010100000001000001006D61696E2E6370700000000000000902700F00000100000001050C0A75050B063C05033C0204000101000902900F00000100000015050E0A083D050C63050B063C0506063F05023D0202000101
|
||||
- sectname: __debug_pubnames
|
||||
segname: __DWARF
|
||||
addr: 0x000000010000206A
|
||||
|
@ -228,7 +227,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 2B000000020000000000E00000002A0000005F5A33666F6F69002A000000666F6F00690000006D61696E0000000000
|
||||
- sectname: __debug_pubtypes
|
||||
segname: __DWARF
|
||||
addr: 0x0000000100002099
|
||||
|
@ -241,7 +239,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 1F000000020000000000E000000062000000696E7400D8000000636861720000000000
|
||||
- sectname: __debug_aranges
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000020BC
|
||||
|
@ -254,7 +251,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 3C000000020000000000080000000000700F0000010000001100000000000000900F000001000000250000000000000000000000000000000000000000000000
|
||||
- sectname: __debug_info
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000020FC
|
||||
|
@ -267,7 +263,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: DC000000040000000000080101000000040031000000000000003A000000700F0000010000004500000002700F000001000000110000000156460000000302917C5600000000043F0000004700000001016200000001054B00000001016200000000064D000000050407900F000001000000250000000156510000000104620000000802917456000000010462000000080291685B0000000104C9000000090291644B0000000105620000000A46000000AA0F0000010000000600000001050302917C5600000000000BCE0000000BD30000000CD80000000660000000060100
|
||||
- sectname: __debug_abbrev
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000021DC
|
||||
|
@ -280,7 +275,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 011101250E1305030E10171B0EB44219110112060000022E0111011206401831100000030500021831100000042E016E0E030E3A0B3B0B49103F19200B0000050500030E3A0B3B0B49100000062400030E3E0B0B0B0000072E01110112064018030E3A0B3B0B49103F1900000805000218030E3A0B3B0B491000000934000218030E3A0B3B0B491000000A1D01311011011206580B590B00000B0F00491000000C26004910000000
|
||||
- sectname: __debug_str
|
||||
segname: __DWARF
|
||||
addr: 0x0000000100002284
|
||||
|
@ -293,7 +287,6 @@ LoadCommands:
|
|||
reserved1: 0x00000000
|
||||
reserved2: 0x00000000
|
||||
reserved3: 0x00000000
|
||||
content: 004170706C6520636C616E672076657273696F6E2031312E302E302028636C616E672D313130302E302E33332E313729006D61696E2E637070002F746D70005F5A33666F6F6900666F6F006900696E74006D61696E00617267630061726776006368617200
|
||||
- sectname: __apple_names
|
||||
segname: __DWARF
|
||||
addr: 0x00000001000022E9
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
## Test that macho2yaml dumps the __debug_foo section (unrecognized debug section)
|
||||
## as a raw content section.
|
||||
|
||||
## Due to the current implementation of yaml2macho being buggy, we cannot generate a DWARF section
|
||||
## where the sectname starts with '__debug_' and the segname is '__DWARF', from a raw content section.
|
||||
## We've slightly modified the segname to be '__FOO'. macho2yaml will still treat it as a debug
|
||||
## section.
|
||||
|
||||
# RUN: yaml2obj %s | obj2yaml | FileCheck %s --check-prefix=UNRECOGNIZED
|
||||
|
||||
# UNRECOGNIZED: Sections:
|
||||
# UNRECOGNIZED-NEXT: - sectname: __debug_foo
|
||||
# UNRECOGNIZED-NEXT: segname: __FOO
|
||||
# UNRECOGNIZED-NEXT: segname: __DWARF
|
||||
# UNRECOGNIZED-NEXT: addr: 0x0000000000000000
|
||||
# UNRECOGNIZED-NEXT: size: 5
|
||||
# UNRECOGNIZED-NEXT: offset: 0x00000210
|
||||
|
@ -48,7 +43,7 @@ LoadCommands:
|
|||
flags: 0
|
||||
Sections:
|
||||
- sectname: __debug_foo
|
||||
segname: __FOO
|
||||
segname: __DWARF
|
||||
addr: 0x00
|
||||
size: 5
|
||||
offset: 528
|
||||
|
|
Loading…
Reference in New Issue