Add printing the LC_SUB_FRAMEWORK load command with llvm-objdump’s -private-headers.
authorKevin Enderby <enderby@apple.com>
Thu, 18 Dec 2014 19:24:35 +0000 (19:24 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 18 Dec 2014 19:24:35 +0000 (19:24 +0000)
llvm-svn: 224534

llvm/include/llvm/Object/MachO.h
llvm/include/llvm/Support/MachO.h
llvm/lib/Object/MachOObjectFile.cpp
llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 [new file with mode: 0755]
llvm/test/tools/llvm-objdump/X86/macho-private-headers.test
llvm/tools/llvm-objdump/MachODump.cpp

index 19558a3..2cab6c4 100644 (file)
@@ -368,6 +368,8 @@ public:
   getEncryptionInfoCommand(const LoadCommandInfo &L) const;
   MachO::encryption_info_command_64
   getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
+  MachO::sub_framework_command
+  getSubFrameworkCommand(const LoadCommandInfo &L) const;
 
   MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
   MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
index 342bdd5..1cb4299 100644 (file)
@@ -1107,6 +1107,12 @@ namespace llvm {
       sys::swapByteOrder(d.dylib.compatibility_version);
     }
 
+    inline void swapStruct(sub_framework_command &s) {
+      sys::swapByteOrder(s.cmd);
+      sys::swapByteOrder(s.cmdsize);
+      sys::swapByteOrder(s.umbrella);
+    };
+
     inline void swapStruct(dylinker_command &d) {
       sys::swapByteOrder(d.cmd);
       sys::swapByteOrder(d.cmdsize);
index 5bc1110..a5031f1 100644 (file)
@@ -2309,6 +2309,10 @@ MachOObjectFile::getEncryptionInfoCommand64(const LoadCommandInfo &L) const {
   return getStruct<MachO::encryption_info_command_64>(this, L.Ptr);
 }
 
+MachO::sub_framework_command
+MachOObjectFile::getSubFrameworkCommand(const LoadCommandInfo &L) const {
+  return getStruct<MachO::sub_framework_command>(this, L.Ptr);
+}
 
 MachO::any_relocation_info
 MachOObjectFile::getRelocation(DataRefImpl Rel) const {
diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 b/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64
new file mode 100755 (executable)
index 0000000..3036c27
Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 differ
index 2bbd340..bbb9086 100644 (file)
@@ -5,6 +5,8 @@
 // RUN:     | FileCheck %s -check-prefix=LOAD
 // RUN: llvm-objdump -p %p/Inputs/linkerOption.macho-x86_64 \
 // RUN:     | FileCheck %s -check-prefix=LD_OPT
+// RUN: llvm-objdump -p %p/Inputs/dylibSubFramework.macho-x86_64 \
+// RUN:     | FileCheck %s -check-prefix=SUB_FRAME
 
 CHECK: Mach header
 CHECK:       magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
@@ -379,3 +381,8 @@ LD_OPT:  cmdsize 40
 LD_OPT:    count 2
 LD_OPT:   string #1 -framework
 LD_OPT:   string #2 Foundation
+
+SUB_FRAME: Load command 10
+SUB_FRAME:           cmd LC_SUB_FRAMEWORK
+SUB_FRAME:       cmdsize 16
+SUB_FRAME:      umbrella Bar (offset 12)
index 7446e32..f5feeed 100644 (file)
@@ -3674,6 +3674,22 @@ static void PrintLinkerOptionCommand(MachO::linker_option_command lo,
            << "\n";
 }
 
+static void PrintSubFrameworkCommand(MachO::sub_framework_command sub,
+                                     const char *Ptr) {
+  outs() << "          cmd LC_SUB_FRAMEWORK\n";
+  outs() << "      cmdsize " << sub.cmdsize;
+  if (sub.cmdsize < sizeof(struct MachO::sub_framework_command))
+    outs() << " Incorrect size\n";
+  else
+    outs() << "\n";
+  if (sub.umbrella < sub.cmdsize) {
+    const char *P = Ptr + sub.umbrella;
+    outs() << "     umbrella " << P << " (offset " << sub.umbrella << ")\n";
+  } else {
+    outs() << "     umbrella ?(bad offset " << sub.umbrella << ")\n";
+  }
+}
+
 static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
   if (dl.cmd == MachO::LC_ID_DYLIB)
     outs() << "          cmd LC_ID_DYLIB\n";
@@ -3830,6 +3846,9 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
     } else if (Command.C.cmd == MachO::LC_LINKER_OPTION) {
       MachO::linker_option_command Lo = Obj->getLinkerOptionLoadCommand(Command);
       PrintLinkerOptionCommand(Lo, Command.Ptr);
+    } else if (Command.C.cmd == MachO::LC_SUB_FRAMEWORK) {
+      MachO::sub_framework_command Sf = Obj->getSubFrameworkCommand(Command);
+      PrintSubFrameworkCommand(Sf, Command.Ptr);
     } else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
                Command.C.cmd == MachO::LC_ID_DYLIB ||
                Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||