Files
clang-p2996/llvm/test/ObjectYAML/MachO/section_data.yaml
Vitaly Buka 66e49e38ae [YAML] Don't validate Fill::Size after error (#123280)
Size is required, so we don't know if it's in
uninitialized state after the previous error.

Triggers msan on llvm/test/tools/yaml2obj/ELF/custom-fill.yaml NOSIZE
test.

We have `Fill` Section with Pattern, but no size. Before the fix it
produced error:
```
YAML:169:5: error: missing required key 'Size'
  - Type:    Fill
    ^
YAML:169:5: error: "Size" can't be 0 when "Pattern" is not empty
  - Type:    Fill
```

The same applies to `MachOYAML::Section` fields `content` and `size`.
However `MachOYAML::Section` matches size first, so on error,
content is not set anyway. Added error checking just in case.
2025-01-23 09:52:34 -08:00

203 lines
6.0 KiB
YAML

## Show that yaml2obj supports custom section data for Mach-O YAML inputs.
## Case 1: The size of content is greater than the section size.
# RUN: not yaml2obj --docnum=1 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE1
# CASE1: error: Section size must be greater than or equal to the content size
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 232
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x0000000000000000
size: 0
offset: 0x00000188
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: CDAB3412
## Case 2: The content size equals the section size.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CASE2
# CASE2: Index: 0
# CASE2-NEXT: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT: Address: 0x0
# CASE2-NEXT: Size: 0x4
# CASE2-NEXT: Offset: 392
# CASE2-NEXT: Alignment: 2
# CASE2-NEXT: RelocationOffset: 0x0
# CASE2-NEXT: RelocationCount: 0
# CASE2-NEXT: Type: Regular (0x0)
# CASE2-NEXT: Attributes [ (0x0)
# CASE2-NEXT: ]
# CASE2-NEXT: Reserved1: 0x0
# CASE2-NEXT: Reserved2: 0x0
# CASE2-NEXT: Reserved3: 0x0
# CASE2-NEXT: SectionData (
# CASE2-NEXT: 0000: CDAB3412 |..4.|
# CASE2-NEXT: )
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 232
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x0000000000000000
size: 4
offset: 0x00000188
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: CDAB3412
## Case 3: The content size is less than the section size. In this case, the area
## after the custom content is filled with zeroes.
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=CASE3
# CASE3: Index: 0
# CASE3-NEXT: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
# CASE3-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
# CASE3-NEXT: Address: 0x0
# CASE3-NEXT: Size: 0x4
# CASE3-NEXT: Offset: 392
# CASE3-NEXT: Alignment: 2
# CASE3-NEXT: RelocationOffset: 0x0
# CASE3-NEXT: RelocationCount: 0
# CASE3-NEXT: Type: Regular (0x0)
# CASE3-NEXT: Attributes [ (0x0)
# CASE3-NEXT: ]
# CASE3-NEXT: Reserved1: 0x0
# CASE3-NEXT: Reserved2: 0x0
# CASE3-NEXT: Reserved3: 0x0
# CASE3-NEXT: SectionData (
# CASE3-NEXT: 0000: AA000000 |....|
# CASE3-NEXT: )
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 232
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x0000000000000000
size: 4
offset: 0x00000188
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: AA
## Case 4: Don't validate if size is missing.
# RUN: not yaml2obj --docnum=4 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE4 --implicit-check-not=error:
# CASE4: error: missing required key 'size'
# CASE4: error: failed to parse YAML
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 232
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x0000000000000000
content: AA
offset: 0x00000188
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000