Skip to content

Commit 6da58e7

Browse files
[Object][MachO] Rewrite macho-invalid-fat-arch-size into YAML
Summary: Rewrite one of the invalid macho test input file with YAML file. The original invalid macho is breaking our internal test infrastusture because it is too broken to be copy around. Need to relax an assertion in the YAML/MachoEmitter to allow yaml2obj to write an invalid object like this. rdar://problem/56879982 Reviewers: beanz, mtrent Reviewed By: beanz Subscribers: hiraditya, jkorous, dexonsmith, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69856
1 parent dad7a18 commit 6da58e7

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

llvm/lib/ObjectYAML/MachOEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ void UniversalWriter::writeMachO(raw_ostream &OS) {
494494
writeFatArchs(OS);
495495

496496
auto &FatFile = *ObjectFile.FatMachO;
497-
assert(FatFile.FatArchs.size() == FatFile.Slices.size());
497+
assert(FatFile.FatArchs.size() > FatFile.Slices.size() &&
498+
"Cannot write Slices if not decribed in FatArches");
498499
for (size_t i = 0; i < FatFile.Slices.size(); i++) {
499500
ZeroToOffset(OS, FatFile.FatArchs[i].offset);
500501
MachOWriter Writer(FatFile.Slices[i]);
-56 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- !fat-mach-o
2+
FatHeader:
3+
magic: 0xCAFEBABE
4+
nfat_arch: 1
5+
FatArchs:
6+
- cputype: 0x00000007
7+
cpusubtype: 0x00000003
8+
offset: 0x000000000000020
9+
size: 32
10+
align: 2
11+
Slices:
12+
...

llvm/test/Object/macho-invalid.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ INVALID-EXPORT-OVERLAP: macho-invalid-export-overlap': truncated or malformed ob
491491
RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-header 2>&1 | FileCheck -check-prefix INVALID-FAT-HEADER %s
492492
INVALID-FAT-HEADER: macho-invalid-fat-header': truncated or malformed fat file (contains zero architecture types)
493493

494-
RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-arch-size 2>&1 | FileCheck -check-prefix INVALID-FAT-ARCH-SIZE %s
495-
INVALID-FAT-ARCH-SIZE: macho-invalid-fat-arch-size': truncated or malformed fat file (offset plus size of cputype (7) cpusubtype (3) extends past the end of the file)
494+
RUN: yaml2obj %p/Inputs/macho-invalid-fat-arch-size.yaml -o - | not llvm-objdump --macho --universal-headers - 2>&1 | FileCheck -check-prefix INVALID-FAT-ARCH-SIZE %s
495+
INVALID-FAT-ARCH-SIZE: '-': truncated or malformed fat file (offset plus size of cputype (7) cpusubtype (3) extends past the end of the file)
496496

497497
RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-arch-bigalign 2>&1 | FileCheck -check-prefix INVALID-FAT-ARCH-BIGALIGN %s
498498
INVALID-FAT-ARCH-BIGALIGN: macho-invalid-fat-arch-bigalign': truncated or malformed fat file (align (2^212) too large for cputype (7) cpusubtype (3) (maximum 2^15))

0 commit comments

Comments
 (0)