[PATCH] D69856: [Object][MachO] Rewrite macho-invalid-fat-arch-size into YAML

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 09:51:54 PST 2019


steven_wu created this revision.
steven_wu added reviewers: beanz, mtrent.
Herald added subscribers: ributzka, dexonsmith, jkorous, hiraditya.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69856

Files:
  llvm/lib/ObjectYAML/MachOEmitter.cpp
  llvm/test/Object/Inputs/macho-invalid-fat-arch-size
  llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml
  llvm/test/Object/macho-invalid.test


Index: llvm/test/Object/macho-invalid.test
===================================================================
--- llvm/test/Object/macho-invalid.test
+++ llvm/test/Object/macho-invalid.test
@@ -491,8 +491,8 @@
 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))
Index: llvm/test/Object/Inputs/macho-invalid-fat-arch-size.yaml
===================================================================
--- /dev/null
+++ 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:
+...
Index: llvm/lib/ObjectYAML/MachOEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -494,7 +494,8 @@
   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]);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69856.227904.patch
Type: text/x-patch
Size: 2528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191105/ec7b1a06/attachment.bin>


More information about the llvm-commits mailing list