Move everything depending on Object/MachOFormat.h over to Support/MachO.h.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189728 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index e0ec9cc..403be5a 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -104,7 +104,7 @@
   uint64_t Value;
 
   switch (Kind) {
-  case macho::Data:
+  case MachO::DICE_KIND_DATA:
     switch (Size) {
     case 4:
       Value = bytes[3] << 24 |
@@ -125,16 +125,16 @@
     }
     outs() << "\t@ KIND_DATA\n";
     break;
-  case macho::JumpTable8:
+  case MachO::DICE_KIND_JUMP_TABLE8:
     Value = bytes[0];
     outs() << "\t.byte " << Value << "\t@ KIND_JUMP_TABLE8";
     break;
-  case macho::JumpTable16:
+  case MachO::DICE_KIND_JUMP_TABLE16:
     Value = bytes[1] << 8 |
             bytes[0];
     outs() << "\t.short " << Value << "\t@ KIND_JUMP_TABLE16";
     break;
-  case macho::JumpTable32:
+  case MachO::DICE_KIND_JUMP_TABLE32:
     Value = bytes[3] << 24 |
             bytes[2] << 16 |
             bytes[1] << 8 |
@@ -148,7 +148,7 @@
 }
 
 static void
-getSectionsAndSymbols(const macho::Header Header,
+getSectionsAndSymbols(const MachO::mach_header Header,
                       MachOObjectFile *MachOObj,
                       std::vector<SectionRef> &Sections,
                       std::vector<SymbolRef> &Symbols,
@@ -171,25 +171,25 @@
     MachOObj->getFirstLoadCommandInfo();
   bool BaseSegmentAddressSet = false;
   for (unsigned i = 0; ; ++i) {
-    if (Command.C.Type == macho::LCT_FunctionStarts) {
+    if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
       // We found a function starts segment, parse the addresses for later
       // consumption.
-      macho::LinkeditDataLoadCommand LLC =
+      MachO::linkedit_data_command LLC =
         MachOObj->getLinkeditDataLoadCommand(Command);
 
-      MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
+      MachOObj->ReadULEB128s(LLC.dataoff, FoundFns);
     }
-    else if (Command.C.Type == macho::LCT_Segment) {
-      macho::SegmentLoadCommand SLC =
+    else if (Command.C.cmd == MachO::LC_SEGMENT) {
+      MachO::segment_command SLC =
         MachOObj->getSegmentLoadCommand(Command);
-      StringRef SegName = SLC.Name;
+      StringRef SegName = SLC.segname;
       if(!BaseSegmentAddressSet && SegName != "__PAGEZERO") {
         BaseSegmentAddressSet = true;
-        BaseSegmentAddress = SLC.VMAddress;
+        BaseSegmentAddress = SLC.vmaddr;
       }
     }
 
-    if (i == Header.NumLoadCommands - 1)
+    if (i == Header.ncmds - 1)
       break;
     else
       Command = MachOObj->getNextLoadCommandInfo(Command);
@@ -244,7 +244,7 @@
 
   outs() << '\n' << Filename << ":\n\n";
 
-  macho::Header Header = MachOOF->getHeader();
+  MachO::mach_header Header = MachOOF->getHeader();
 
   // FIXME: FoundFns isn't used anymore. Using symbols/LC_FUNCTION_STARTS to
   // determine function locations will eventually go in MCObjectDisassembler.
@@ -267,7 +267,7 @@
 
   // Build a data in code table that is sorted on by the address of each entry.
   uint64_t BaseAddress = 0;
-  if (Header.FileType == macho::HFT_Object)
+  if (Header.filetype == MachO::MH_OBJECT)
     Sections[0].getAddress(BaseAddress);
   else
     BaseAddress = BaseSegmentAddress;
diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp
index 8df6fd6..e27a58a 100644
--- a/tools/llvm-readobj/MachODumper.cpp
+++ b/tools/llvm-readobj/MachODumper.cpp
@@ -166,28 +166,28 @@
                        DataRefImpl Sec,
                        MachOSection &Section) {
   if (!Obj->is64Bit()) {
-    macho::Section Sect = Obj->getSection(Sec);
-    Section.Address     = Sect.Address;
-    Section.Size        = Sect.Size;
-    Section.Offset      = Sect.Offset;
-    Section.Alignment   = Sect.Align;
-    Section.RelocationTableOffset = Sect.RelocationTableOffset;
-    Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries;
-    Section.Flags       = Sect.Flags;
-    Section.Reserved1   = Sect.Reserved1;
-    Section.Reserved2   = Sect.Reserved2;
+    MachO::section Sect = Obj->getSection(Sec);
+    Section.Address     = Sect.addr;
+    Section.Size        = Sect.size;
+    Section.Offset      = Sect.offset;
+    Section.Alignment   = Sect.align;
+    Section.RelocationTableOffset = Sect.reloff;
+    Section.NumRelocationTableEntries = Sect.nreloc;
+    Section.Flags       = Sect.flags;
+    Section.Reserved1   = Sect.reserved1;
+    Section.Reserved2   = Sect.reserved2;
     return;
   }
-  macho::Section64 Sect = Obj->getSection64(Sec);
-  Section.Address     = Sect.Address;
-  Section.Size        = Sect.Size;
-  Section.Offset      = Sect.Offset;
-  Section.Alignment   = Sect.Align;
-  Section.RelocationTableOffset = Sect.RelocationTableOffset;
-  Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries;
-  Section.Flags       = Sect.Flags;
-  Section.Reserved1   = Sect.Reserved1;
-  Section.Reserved2   = Sect.Reserved2;
+  MachO::section_64 Sect = Obj->getSection64(Sec);
+  Section.Address     = Sect.addr;
+  Section.Size        = Sect.size;
+  Section.Offset      = Sect.offset;
+  Section.Alignment   = Sect.align;
+  Section.RelocationTableOffset = Sect.reloff;
+  Section.NumRelocationTableEntries = Sect.nreloc;
+  Section.Flags       = Sect.flags;
+  Section.Reserved1   = Sect.reserved1;
+  Section.Reserved2   = Sect.reserved2;
 }
 
 
@@ -195,20 +195,20 @@
                       DataRefImpl DRI,
                       MachOSymbol &Symbol) {
   if (!Obj->is64Bit()) {
-    macho::SymbolTableEntry Entry = Obj->getSymbolTableEntry(DRI);
-    Symbol.StringIndex  = Entry.StringIndex;
-    Symbol.Type         = Entry.Type;
-    Symbol.SectionIndex = Entry.SectionIndex;
-    Symbol.Flags        = Entry.Flags;
-    Symbol.Value        = Entry.Value;
+    MachO::nlist Entry = Obj->getSymbolTableEntry(DRI);
+    Symbol.StringIndex  = Entry.n_strx;
+    Symbol.Type         = Entry.n_type;
+    Symbol.SectionIndex = Entry.n_sect;
+    Symbol.Flags        = Entry.n_desc;
+    Symbol.Value        = Entry.n_value;
     return;
   }
-  macho::Symbol64TableEntry Entry = Obj->getSymbol64TableEntry(DRI);
-  Symbol.StringIndex  = Entry.StringIndex;
-  Symbol.Type         = Entry.Type;
-  Symbol.SectionIndex = Entry.SectionIndex;
-  Symbol.Flags        = Entry.Flags;
-  Symbol.Value        = Entry.Value;
+  MachO::nlist_64 Entry = Obj->getSymbol64TableEntry(DRI);
+  Symbol.StringIndex  = Entry.n_strx;
+  Symbol.Type         = Entry.n_type;
+  Symbol.SectionIndex = Entry.n_sect;
+  Symbol.Flags        = Entry.n_desc;
+  Symbol.Value        = Entry.n_value;
 }
 
 void MachODumper::printFileHeaders() {
@@ -349,7 +349,7 @@
     return;
 
   DataRefImpl DR = RelI->getRawDataRefImpl();
-  macho::RelocationEntry RE = Obj->getRelocation(DR);
+  MachO::any_relocation_info RE = Obj->getRelocation(DR);
   bool IsScattered = Obj->isRelocationScattered(RE);
 
   if (opts::ExpandRelocs) {
diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp
index 897a785..7ae5440 100644
--- a/tools/macho-dump/macho-dump.cpp
+++ b/tools/macho-dump/macho-dump.cpp
@@ -99,10 +99,10 @@
   error_code EC;
   for (relocation_iterator I = Obj.getSectionRelBegin(Index),
          E = Obj.getSectionRelEnd(Index); I != E; I.increment(EC), ++RelNum) {
-    macho::RelocationEntry RE = Obj.getRelocation(I->getRawDataRefImpl());
+    MachO::any_relocation_info RE = Obj.getRelocation(I->getRawDataRefImpl());
     outs() << "    # Relocation " << RelNum << "\n";
-    outs() << "    (('word-0', " << format("0x%x", RE.Word0) << "),\n";
-    outs() << "     ('word-1', " << format("0x%x", RE.Word1) << ")),\n";
+    outs() << "    (('word-0', " << format("0x%x", RE.r_word0) << "),\n";
+    outs() << "     ('word-1', " << format("0x%x", RE.r_word1) << ")),\n";
   }
   outs() << "  ])\n";
 
@@ -124,23 +124,21 @@
 
 static int DumpSegmentCommand(const MachOObjectFile &Obj,
                               const MachOObjectFile::LoadCommandInfo &LCI) {
-  macho::SegmentLoadCommand SLC = Obj.getSegmentLoadCommand(LCI);
+  MachO::segment_command SLC = Obj.getSegmentLoadCommand(LCI);
 
-  DumpSegmentCommandData(StringRef(SLC.Name, 16), SLC.VMAddress,
-                         SLC.VMSize, SLC.FileOffset, SLC.FileSize,
-                         SLC.MaxVMProtection, SLC.InitialVMProtection,
-                         SLC.NumSections, SLC.Flags);
+  DumpSegmentCommandData(StringRef(SLC.segname, 16), SLC.vmaddr,
+                         SLC.vmsize, SLC.fileoff, SLC.filesize,
+                         SLC.maxprot, SLC.initprot, SLC.nsects, SLC.flags);
 
   // Dump the sections.
   outs() << "  ('sections', [\n";
-  for (unsigned i = 0; i != SLC.NumSections; ++i) {
-    macho::Section Sect = Obj.getSection(LCI, i);
-    DumpSectionData(Obj, i, StringRef(Sect.Name, 16),
-                    StringRef(Sect.SegmentName, 16), Sect.Address,
-                    Sect.Size, Sect.Offset, Sect.Align,
-                    Sect.RelocationTableOffset,
-                    Sect.NumRelocationTableEntries, Sect.Flags,
-                    Sect.Reserved1, Sect.Reserved2);
+  for (unsigned i = 0; i != SLC.nsects; ++i) {
+    MachO::section Sect = Obj.getSection(LCI, i);
+    DumpSectionData(Obj, i, StringRef(Sect.sectname, 16),
+                    StringRef(Sect.segname, 16), Sect.addr,
+                    Sect.size, Sect.offset, Sect.align,
+                    Sect.reloff, Sect.nreloc, Sect.flags,
+                    Sect.reserved1, Sect.reserved2);
   }
   outs() << "  ])\n";
 
@@ -149,24 +147,22 @@
 
 static int DumpSegment64Command(const MachOObjectFile &Obj,
                                 const MachOObjectFile::LoadCommandInfo &LCI) {
-  macho::Segment64LoadCommand SLC = Obj.getSegment64LoadCommand(LCI);
-  DumpSegmentCommandData(StringRef(SLC.Name, 16), SLC.VMAddress,
-                          SLC.VMSize, SLC.FileOffset, SLC.FileSize,
-                          SLC.MaxVMProtection, SLC.InitialVMProtection,
-                          SLC.NumSections, SLC.Flags);
+  MachO::segment_command_64 SLC = Obj.getSegment64LoadCommand(LCI);
+  DumpSegmentCommandData(StringRef(SLC.segname, 16), SLC.vmaddr,
+                         SLC.vmsize, SLC.fileoff, SLC.filesize,
+                         SLC.maxprot, SLC.initprot, SLC.nsects, SLC.flags);
 
   // Dump the sections.
   outs() << "  ('sections', [\n";
-  for (unsigned i = 0; i != SLC.NumSections; ++i) {
-    macho::Section64 Sect = Obj.getSection64(LCI, i);
+  for (unsigned i = 0; i != SLC.nsects; ++i) {
+    MachO::section_64 Sect = Obj.getSection64(LCI, i);
 
-    DumpSectionData(Obj, i, StringRef(Sect.Name, 16),
-                    StringRef(Sect.SegmentName, 16), Sect.Address,
-                    Sect.Size, Sect.Offset, Sect.Align,
-                    Sect.RelocationTableOffset,
-                    Sect.NumRelocationTableEntries, Sect.Flags,
-                    Sect.Reserved1, Sect.Reserved2,
-                    Sect.Reserved3);
+    DumpSectionData(Obj, i, StringRef(Sect.sectname, 16),
+                    StringRef(Sect.segname, 16), Sect.addr,
+                    Sect.size, Sect.offset, Sect.align,
+                    Sect.reloff, Sect.nreloc, Sect.flags,
+                    Sect.reserved1, Sect.reserved2,
+                    Sect.reserved3);
   }
   outs() << "  ])\n";
 
@@ -190,12 +186,12 @@
 }
 
 static int DumpSymtabCommand(const MachOObjectFile &Obj) {
-  macho::SymtabLoadCommand SLC = Obj.getSymtabLoadCommand();
+  MachO::symtab_command SLC = Obj.getSymtabLoadCommand();
 
-  outs() << "  ('symoff', " << SLC.SymbolTableOffset << ")\n";
-  outs() << "  ('nsyms', " << SLC.NumSymbolTableEntries << ")\n";
-  outs() << "  ('stroff', " << SLC.StringTableOffset << ")\n";
-  outs() << "  ('strsize', " << SLC.StringTableSize << ")\n";
+  outs() << "  ('symoff', " << SLC.symoff << ")\n";
+  outs() << "  ('nsyms', " << SLC.nsyms << ")\n";
+  outs() << "  ('stroff', " << SLC.stroff << ")\n";
+  outs() << "  ('strsize', " << SLC.strsize << ")\n";
 
   // Dump the string data.
   outs() << "  ('_string_data', '";
@@ -211,14 +207,14 @@
        I.increment(EC), ++SymNum) {
     DataRefImpl DRI = I->getRawDataRefImpl();
     if (Obj.is64Bit()) {
-      macho::Symbol64TableEntry STE = Obj.getSymbol64TableEntry(DRI);
-      DumpSymbolTableEntryData(Obj, SymNum, STE.StringIndex, STE.Type,
-                               STE.SectionIndex, STE.Flags, STE.Value,
+      MachO::nlist_64 STE = Obj.getSymbol64TableEntry(DRI);
+      DumpSymbolTableEntryData(Obj, SymNum, STE.n_strx, STE.n_type,
+                               STE.n_sect, STE.n_desc, STE.n_value,
                                StringTable);
     } else {
-      macho::SymbolTableEntry STE = Obj.getSymbolTableEntry(DRI);
-      DumpSymbolTableEntryData(Obj, SymNum, STE.StringIndex, STE.Type,
-                               STE.SectionIndex, STE.Flags, STE.Value,
+      MachO::nlist STE = Obj.getSymbolTableEntry(DRI);
+      DumpSymbolTableEntryData(Obj, SymNum, STE.n_strx, STE.n_type,
+                               STE.n_sect, STE.n_desc, STE.n_value,
                                StringTable);
     }
   }
@@ -228,37 +224,33 @@
 }
 
 static int DumpDysymtabCommand(const MachOObjectFile &Obj) {
-  macho::DysymtabLoadCommand DLC = Obj.getDysymtabLoadCommand();
+  MachO::dysymtab_command DLC = Obj.getDysymtabLoadCommand();
 
-  outs() << "  ('ilocalsym', " << DLC.LocalSymbolsIndex << ")\n";
-  outs() << "  ('nlocalsym', " << DLC.NumLocalSymbols << ")\n";
-  outs() << "  ('iextdefsym', " << DLC.ExternalSymbolsIndex << ")\n";
-  outs() << "  ('nextdefsym', " << DLC.NumExternalSymbols << ")\n";
-  outs() << "  ('iundefsym', " << DLC.UndefinedSymbolsIndex << ")\n";
-  outs() << "  ('nundefsym', " << DLC.NumUndefinedSymbols << ")\n";
-  outs() << "  ('tocoff', " << DLC.TOCOffset << ")\n";
-  outs() << "  ('ntoc', " << DLC.NumTOCEntries << ")\n";
-  outs() << "  ('modtaboff', " << DLC.ModuleTableOffset << ")\n";
-  outs() << "  ('nmodtab', " << DLC.NumModuleTableEntries << ")\n";
-  outs() << "  ('extrefsymoff', " << DLC.ReferenceSymbolTableOffset << ")\n";
-  outs() << "  ('nextrefsyms', "
-         << DLC.NumReferencedSymbolTableEntries << ")\n";
-  outs() << "  ('indirectsymoff', " << DLC.IndirectSymbolTableOffset << ")\n";
-  outs() << "  ('nindirectsyms', "
-         << DLC.NumIndirectSymbolTableEntries << ")\n";
-  outs() << "  ('extreloff', " << DLC.ExternalRelocationTableOffset << ")\n";
-  outs() << "  ('nextrel', " << DLC.NumExternalRelocationTableEntries << ")\n";
-  outs() << "  ('locreloff', " << DLC.LocalRelocationTableOffset << ")\n";
-  outs() << "  ('nlocrel', " << DLC.NumLocalRelocationTableEntries << ")\n";
+  outs() << "  ('ilocalsym', " << DLC.ilocalsym << ")\n";
+  outs() << "  ('nlocalsym', " << DLC.nlocalsym << ")\n";
+  outs() << "  ('iextdefsym', " << DLC.iextdefsym << ")\n";
+  outs() << "  ('nextdefsym', " << DLC.nextdefsym << ")\n";
+  outs() << "  ('iundefsym', " << DLC.iundefsym << ")\n";
+  outs() << "  ('nundefsym', " << DLC.nundefsym << ")\n";
+  outs() << "  ('tocoff', " << DLC.tocoff << ")\n";
+  outs() << "  ('ntoc', " << DLC.ntoc << ")\n";
+  outs() << "  ('modtaboff', " << DLC.modtaboff << ")\n";
+  outs() << "  ('nmodtab', " << DLC.nmodtab << ")\n";
+  outs() << "  ('extrefsymoff', " << DLC.extrefsymoff << ")\n";
+  outs() << "  ('nextrefsyms', " << DLC.nextrefsyms << ")\n";
+  outs() << "  ('indirectsymoff', " << DLC.indirectsymoff << ")\n";
+  outs() << "  ('nindirectsyms', " << DLC.nindirectsyms << ")\n";
+  outs() << "  ('extreloff', " << DLC.extreloff << ")\n";
+  outs() << "  ('nextrel', " << DLC.nextrel << ")\n";
+  outs() << "  ('locreloff', " << DLC.locreloff << ")\n";
+  outs() << "  ('nlocrel', " << DLC.nlocrel << ")\n";
 
   // Dump the indirect symbol table.
   outs() << "  ('_indirect_symbols', [\n";
-  for (unsigned i = 0; i != DLC.NumIndirectSymbolTableEntries; ++i) {
-    macho::IndirectSymbolTableEntry ISTE =
-      Obj.getIndirectSymbolTableEntry(DLC, i);
+  for (unsigned i = 0; i != DLC.nindirectsyms; ++i) {
+    uint32_t ISTE = Obj.getIndirectSymbolTableEntry(DLC, i);
     outs() << "    # Indirect Symbol " << i << "\n";
-    outs() << "    (('symbol_index', "
-           << format("0x%x", ISTE.Index) << "),),\n";
+    outs() << "    (('symbol_index', " << format("0x%x", ISTE) << "),),\n";
   }
   outs() << "  ])\n";
 
@@ -268,13 +260,13 @@
 static int
 DumpLinkeditDataCommand(const MachOObjectFile &Obj,
                         const MachOObjectFile::LoadCommandInfo &LCI) {
-  macho::LinkeditDataLoadCommand LLC = Obj.getLinkeditDataLoadCommand(LCI);
-  outs() << "  ('dataoff', " << LLC.DataOffset << ")\n"
-         << "  ('datasize', " << LLC.DataSize << ")\n"
+  MachO::linkedit_data_command LLC = Obj.getLinkeditDataLoadCommand(LCI);
+  outs() << "  ('dataoff', " << LLC.dataoff << ")\n"
+         << "  ('datasize', " << LLC.datasize << ")\n"
          << "  ('_addresses', [\n";
 
   SmallVector<uint64_t, 8> Addresses;
-  Obj.ReadULEB128s(LLC.DataOffset, Addresses);
+  Obj.ReadULEB128s(LLC.dataoff, Addresses);
   for (unsigned i = 0, e = Addresses.size(); i != e; ++i)
     outs() << "    # Address " << i << '\n'
            << "    ('address', " << format("0x%x", Addresses[i]) << "),\n";
@@ -287,19 +279,18 @@
 static int
 DumpDataInCodeDataCommand(const MachOObjectFile &Obj,
                           const MachOObjectFile::LoadCommandInfo &LCI) {
-  macho::LinkeditDataLoadCommand LLC = Obj.getLinkeditDataLoadCommand(LCI);
-  outs() << "  ('dataoff', " << LLC.DataOffset << ")\n"
-         << "  ('datasize', " << LLC.DataSize << ")\n"
+  MachO::linkedit_data_command LLC = Obj.getLinkeditDataLoadCommand(LCI);
+  outs() << "  ('dataoff', " << LLC.dataoff << ")\n"
+         << "  ('datasize', " << LLC.datasize << ")\n"
          << "  ('_data_regions', [\n";
 
-  unsigned NumRegions = LLC.DataSize / sizeof(macho::DataInCodeTableEntry);
+  unsigned NumRegions = LLC.datasize / sizeof(MachO::data_in_code_entry);
   for (unsigned i = 0; i < NumRegions; ++i) {
-    macho::DataInCodeTableEntry DICE =
-      Obj.getDataInCodeTableEntry(LLC.DataOffset, i);
+    MachO::data_in_code_entry DICE= Obj.getDataInCodeTableEntry(LLC.dataoff, i);
     outs() << "    # DICE " << i << "\n"
-           << "    ('offset', " << DICE.Offset << ")\n"
-           << "    ('length', " << DICE.Length << ")\n"
-           << "    ('kind', " << DICE.Kind << ")\n";
+           << "    ('offset', " << DICE.offset << ")\n"
+           << "    ('length', " << DICE.length << ")\n"
+           << "    ('kind', " << DICE.kind << ")\n";
   }
 
   outs() <<"  ])\n";
@@ -310,46 +301,46 @@
 static int
 DumpLinkerOptionsCommand(const MachOObjectFile &Obj,
                          const MachOObjectFile::LoadCommandInfo &LCI) {
-  macho::LinkerOptionsLoadCommand LOLC = Obj.getLinkerOptionsLoadCommand(LCI);
-   outs() << "  ('count', " << LOLC.Count << ")\n"
-          << "  ('_strings', [\n";
+  MachO::linker_options_command LOLC = Obj.getLinkerOptionsLoadCommand(LCI);
+  outs() << "  ('count', " << LOLC.count << ")\n"
+         << "  ('_strings', [\n";
 
-   uint64_t DataSize = LOLC.Size - sizeof(macho::LinkerOptionsLoadCommand);
-   const char *P = LCI.Ptr + sizeof(macho::LinkerOptionsLoadCommand);
-   StringRef Data(P, DataSize);
-   for (unsigned i = 0; i != LOLC.Count; ++i) {
-     std::pair<StringRef,StringRef> Split = Data.split('\0');
-     outs() << "\t\"";
-     outs().write_escaped(Split.first);
-     outs() << "\",\n";
-     Data = Split.second;
-   }
-   outs() <<"  ])\n";
+  uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_options_command);
+  const char *P = LCI.Ptr + sizeof(MachO::linker_options_command);
+  StringRef Data(P, DataSize);
+  for (unsigned i = 0; i != LOLC.count; ++i) {
+    std::pair<StringRef,StringRef> Split = Data.split('\0');
+    outs() << "\t\"";
+    outs().write_escaped(Split.first);
+    outs() << "\",\n";
+    Data = Split.second;
+  }
+  outs() <<"  ])\n";
 
   return 0;
 }
 
 static int DumpLoadCommand(const MachOObjectFile &Obj,
                            MachOObjectFile::LoadCommandInfo &LCI) {
-  switch (LCI.C.Type) {
-  case macho::LCT_Segment:
+  switch (LCI.C.cmd) {
+  case MachO::LC_SEGMENT:
     return DumpSegmentCommand(Obj, LCI);
-  case macho::LCT_Segment64:
+  case MachO::LC_SEGMENT_64:
     return DumpSegment64Command(Obj, LCI);
-  case macho::LCT_Symtab:
+  case MachO::LC_SYMTAB:
     return DumpSymtabCommand(Obj);
-  case macho::LCT_Dysymtab:
+  case MachO::LC_DYSYMTAB:
     return DumpDysymtabCommand(Obj);
-  case macho::LCT_CodeSignature:
-  case macho::LCT_SegmentSplitInfo:
-  case macho::LCT_FunctionStarts:
+  case MachO::LC_CODE_SIGNATURE:
+  case MachO::LC_SEGMENT_SPLIT_INFO:
+  case MachO::LC_FUNCTION_STARTS:
     return DumpLinkeditDataCommand(Obj, LCI);
-  case macho::LCT_DataInCode:
+  case MachO::LC_DATA_IN_CODE:
     return DumpDataInCodeDataCommand(Obj, LCI);
-  case macho::LCT_LinkerOptions:
+  case MachO::LC_LINKER_OPTIONS:
     return DumpLinkerOptionsCommand(Obj, LCI);
   default:
-    Warning("unknown load command: " + Twine(LCI.C.Type));
+    Warning("unknown load command: " + Twine(LCI.C.cmd));
     return 0;
   }
 }
@@ -358,26 +349,27 @@
 static int DumpLoadCommand(const MachOObjectFile &Obj, unsigned Index,
                            MachOObjectFile::LoadCommandInfo &LCI) {
   outs() << "  # Load Command " << Index << "\n"
-         << " (('command', " << LCI.C.Type << ")\n"
-         << "  ('size', " << LCI.C.Size << ")\n";
+         << " (('command', " << LCI.C.cmd << ")\n"
+         << "  ('size', " << LCI.C.cmdsize << ")\n";
   int Res = DumpLoadCommand(Obj, LCI);
   outs() << " ),\n";
   return Res;
 }
 
 static void printHeader(const MachOObjectFile *Obj,
-                        const macho::Header &Header) {
-  outs() << "('cputype', " << Header.CPUType << ")\n";
-  outs() << "('cpusubtype', " << Header.CPUSubtype << ")\n";
-  outs() << "('filetype', " << Header.FileType << ")\n";
-  outs() << "('num_load_commands', " << Header.NumLoadCommands << ")\n";
-  outs() << "('load_commands_size', " << Header.SizeOfLoadCommands << ")\n";
-  outs() << "('flag', " << Header.Flags << ")\n";
+                        const MachO::mach_header &Header) {
+  outs() << "('cputype', " << Header.cputype << ")\n";
+  outs() << "('cpusubtype', " << Header.cpusubtype << ")\n";
+  outs() << "('filetype', " << Header.filetype << ")\n";
+  outs() << "('num_load_commands', " << Header.ncmds << ")\n";
+  outs() << "('load_commands_size', " << Header.sizeofcmds << ")\n";
+  outs() << "('flag', " << Header.flags << ")\n";
 
   // Print extended header if 64-bit.
   if (Obj->is64Bit()) {
-    macho::Header64Ext Header64Ext = Obj->getHeader64Ext();
-    outs() << "('reserved', " << Header64Ext.Reserved << ")\n";
+    const MachO::mach_header_64 *Header64 =
+      reinterpret_cast<const MachO::mach_header_64 *>(&Header);
+    outs() << "('reserved', " << Header64->reserved << ")\n";
   }
 }
 
@@ -396,8 +388,13 @@
     return Error("Not a MachO object");
 
   // Print the header
-  macho::Header Header = InputObject->getHeader();
-  printHeader(InputObject, Header);
+  MachO::mach_header_64 Header64;
+  MachO::mach_header *Header = reinterpret_cast<MachO::mach_header*>(&Header64);
+  if (InputObject->is64Bit())
+    Header64 = InputObject->getHeader64();
+  else
+    *Header = InputObject->getHeader();
+  printHeader(InputObject, *Header);
 
   // Print the load commands.
   int Res = 0;
@@ -408,7 +405,7 @@
     if (DumpLoadCommand(*InputObject, i, Command))
       break;
 
-    if (i == Header.NumLoadCommands - 1)
+    if (i == Header->ncmds - 1)
       break;
     Command = InputObject->getNextLoadCommandInfo(Command);
   }