Skip to content

Commit 026e469

Browse files
committed
MachOYAML::Section
Created using spr 1.3.4
1 parent de17118 commit 026e469

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

llvm/lib/ObjectYAML/MachOYAML.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
346346
std::string
347347
MappingTraits<MachOYAML::Section>::validate(IO &IO,
348348
MachOYAML::Section &Section) {
349-
if (Section.content && Section.size < Section.content->binary_size())
349+
if (!IO.error() && Section.content &&
350+
Section.size < Section.content->binary_size())
350351
return "Section size must be greater than or equal to the content size";
351352
return "";
352353
}

llvm/test/ObjectYAML/MachO/section_data.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,44 @@ LoadCommands:
159159
reserved2: 0x00000000
160160
reserved3: 0x00000000
161161
content: AA
162+
163+
## Case 4: Don't validate if size is missing.
164+
# RUN: not yaml2obj --docnum=4 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE4
165+
# CASE4: missing required key 'size'
166+
# CASE4-NOT: error: Section size must be greater
167+
168+
--- !mach-o
169+
FileHeader:
170+
magic: 0xFEEDFACF
171+
cputype: 0x01000007
172+
cpusubtype: 0x00000003
173+
filetype: 0x00000001
174+
ncmds: 1
175+
sizeofcmds: 232
176+
flags: 0x00002000
177+
reserved: 0x00000000
178+
LoadCommands:
179+
- cmd: LC_SEGMENT_64
180+
cmdsize: 232
181+
segname: ''
182+
vmaddr: 0
183+
vmsize: 4
184+
fileoff: 392
185+
filesize: 4
186+
maxprot: 7
187+
initprot: 7
188+
nsects: 1
189+
flags: 0
190+
Sections:
191+
- sectname: __data
192+
segname: __DATA
193+
addr: 0x0000000000000000
194+
content: AA
195+
offset: 0x00000188
196+
align: 2
197+
reloff: 0x00000000
198+
nreloc: 0
199+
flags: 0x00000000
200+
reserved1: 0x00000000
201+
reserved2: 0x00000000
202+
reserved3: 0x00000000

0 commit comments

Comments
 (0)