summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Wu <stevenwu@apple.com>2019-11-06 11:25:50 -0800
committerSteven Wu <stevenwu@apple.com>2019-11-06 11:26:25 -0800
commit6da58e7e0fac1e421d6a5a6e48ed8836c67ac543 (patch)
tree826ee4c3096371f734b5babdb5d4b9652f4b881c
parentdad7a185101d23598d82147a4feed486ba0abafb (diff)
downloadbcm5719-llvm-6da58e7e0fac1e421d6a5a6e48ed8836c67ac543.tar.gz
bcm5719-llvm-6da58e7e0fac1e421d6a5a6e48ed8836c67ac543.zip
[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
-rw-r--r--llvm/lib/ObjectYAML/MachOEmitter.cpp3
-rw-r--r--llvm/test/Object/Inputs/macho-invalid-fat-arch-sizebin56 -> 0 bytes
-rw-r--r--llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml12
-rw-r--r--llvm/test/Object/macho-invalid.test4
4 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index b56f811ce67..e0885e0b206 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -494,7 +494,8 @@ void UniversalWriter::writeMachO(raw_ostream &OS) {
writeFatArchs(OS);
auto &FatFile = *ObjectFile.FatMachO;
- assert(FatFile.FatArchs.size() == FatFile.Slices.size());
+ assert(FatFile.FatArchs.size() > FatFile.Slices.size() &&
+ "Cannot write Slices if not decribed in FatArches");
for (size_t i = 0; i < FatFile.Slices.size(); i++) {
ZeroToOffset(OS, FatFile.FatArchs[i].offset);
MachOWriter Writer(FatFile.Slices[i]);
diff --git a/llvm/test/Object/Inputs/macho-invalid-fat-arch-size b/llvm/test/Object/Inputs/macho-invalid-fat-arch-size
deleted file mode 100644
index dfd154c88e3..00000000000
--- a/llvm/test/Object/Inputs/macho-invalid-fat-arch-size
+++ /dev/null
Binary files differ
diff --git a/llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml b/llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml
new file mode 100644
index 00000000000..f7bf00d7c13
--- /dev/null
+++ b/llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml
@@ -0,0 +1,12 @@
+--- !fat-mach-o
+FatHeader:
+ magic: 0xCAFEBABE
+ nfat_arch: 1
+FatArchs:
+ - cputype: 0x00000007
+ cpusubtype: 0x00000003
+ offset: 0x000000000000020
+ size: 32
+ align: 2
+Slices:
+...
diff --git a/llvm/test/Object/macho-invalid.test b/llvm/test/Object/macho-invalid.test
index 1cbd7469d73..2206c678105 100644
--- a/llvm/test/Object/macho-invalid.test
+++ b/llvm/test/Object/macho-invalid.test
@@ -491,8 +491,8 @@ INVALID-EXPORT-OVERLAP: macho-invalid-export-overlap': truncated or malformed ob
RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-header 2>&1 | FileCheck -check-prefix INVALID-FAT-HEADER %s
INVALID-FAT-HEADER: macho-invalid-fat-header': truncated or malformed fat file (contains zero architecture types)
-RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-arch-size 2>&1 | FileCheck -check-prefix INVALID-FAT-ARCH-SIZE %s
-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)
+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
+INVALID-FAT-ARCH-SIZE: '-': truncated or malformed fat file (offset plus size of cputype (7) cpusubtype (3) extends past the end of the file)
RUN: not llvm-objdump --macho --universal-headers %p/Inputs/macho-invalid-fat-arch-bigalign 2>&1 | FileCheck -check-prefix INVALID-FAT-ARCH-BIGALIGN %s
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))
OpenPOWER on IntegriCloud