[PATCH] [MachO] Support reading of fat binaries.

kledzik at apple.com kledzik at apple.com
Mon Jan 13 13:54:41 PST 2014


  Regarding "mb1", I would start the function making local variables const uint8_ *start and size_t size, initialize them from the mb, then if it is a fat file, change their values.  And have the rest of the function use those variables instead of mb.

  Regarding the padding, lipo likes to add padding so each slice starts on a page boundary.  Otherwise any aligned sections inside a slice may not be aligned in the overall buffer.


================
Comment at: lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp:95
@@ +94,3 @@
+template <typename T> static T swapIfLittleEndian(T t) {
+  if (llvm::sys::IsLittleEndianHost)
+    return SwapByteOrder(t);
----------------
This name is ambiguous.  Is the "if" about the host or file being read.  I think a better name would be readBigEndian().

================
Comment at: lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp:118
@@ +117,3 @@
+        reinterpret_cast<const fat_header *>(mb1->getBufferStart());
+    uint32_t nfat_arch = fh->nfat_arch;
+    const fat_arch *fa = reinterpret_cast<const fat_arch *>(
----------------
The arch count is in big endian, so you need the swap call here.

================
Comment at: lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp:134
@@ +133,3 @@
+    offset = swapIfLittleEndian(fa->offset);
+    size = swapIfLittleEndian(fa->size);
+    mh = reinterpret_cast<const mach_header *>(mb1->getBufferStart() + offset);
----------------
Should be a range check here that offset+size is not greater than mb1->getBufferSize().  If so, return an error because the file is truncated. 


http://llvm-reviews.chandlerc.com/D2537



More information about the llvm-commits mailing list