[llvm-readobj] Add support for dumping MachO min version load command.
authorDavide Italiano <davide@freebsd.org>
Thu, 27 Aug 2015 15:11:32 +0000 (15:11 +0000)
committerDavide Italiano <davide@freebsd.org>
Thu, 27 Aug 2015 15:11:32 +0000 (15:11 +0000)
Example output:
File: <stdin>
Format: Mach-O arm
Arch: arm
AddressSize: 32bit
MinVersion {
  Cmd: LC_VERSION_MIN_IPHONEOS
  Size: 16
  Version: 99.8.7
  SDK: n/a
}

Differential Revision:  http://reviews.llvm.org/D12373

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246151 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-readobj/MachODumper.cpp
tools/llvm-readobj/ObjDumper.h
tools/llvm-readobj/llvm-readobj.cpp

index 4628d7a..57db9ed 100644 (file)
@@ -42,6 +42,7 @@ public:
 
   // MachO-specific.
   void printMachODataInCode() override;
+  void printMachOVersionMin() override;
 
 private:
   template<class MachHeader>
@@ -625,3 +626,40 @@ void MachODumper::printMachODataInCode() {
     }
   }
 }
+
+void MachODumper::printMachOVersionMin() {
+  for (const auto &Load : Obj->load_commands()) {
+    if (Load.C.cmd == MachO::LC_VERSION_MIN_MACOSX ||
+        Load.C.cmd == MachO::LC_VERSION_MIN_IPHONEOS) {
+      MachO::version_min_command VMC = Obj->getVersionMinLoadCommand(Load);
+      DictScope Group(W, "MinVersion");
+      StringRef Cmd;
+      if (Load.C.cmd == MachO::LC_VERSION_MIN_MACOSX)
+        Cmd = "LC_VERSION_MIN_MACOSX";
+      else
+        Cmd = "LC_VERSION_MIN_IPHONEOS";
+      W.printString("Cmd", Cmd);
+      W.printNumber("Size", VMC.cmdsize);
+      SmallString<32> Version;
+      Version = utostr(MachOObjectFile::getVersionMinMajor(VMC, false)) + "." +
+        utostr(MachOObjectFile::getVersionMinMinor(VMC, false));
+      uint32_t Update = MachOObjectFile::getVersionMinUpdate(VMC, false);
+      if (Update != 0)
+        Version += "." + utostr(MachOObjectFile::getVersionMinUpdate(VMC,
+                                                                     false));
+      W.printString("Version", Version);
+      SmallString<32> SDK;
+      if (VMC.sdk == 0)
+        SDK = "n/a";
+      else {
+        SDK = utostr(MachOObjectFile::getVersionMinMajor(VMC, true)) + "." +
+          utostr(MachOObjectFile::getVersionMinMinor(VMC, true));
+        uint32_t Update = MachOObjectFile::getVersionMinUpdate(VMC, true);
+        if (Update != 0)
+          SDK += "." + utostr(MachOObjectFile::getVersionMinUpdate(VMC,
+                                                                   true));
+      }
+      W.printString("SDK", SDK);
+    }
+  }
+}
index 153e5bb..8710088 100644 (file)
@@ -56,6 +56,7 @@ public:
 
   // Only implemented for MachO.
   virtual void printMachODataInCode() { }
+  virtual void printMachOVersionMin() { }
 
   virtual void printStackMap() const = 0;
 
index c6f303d..d41dcc3 100644 (file)
@@ -186,6 +186,10 @@ namespace opts {
   MachODataInCode("macho-data-in-code",
                   cl::desc("Display MachO Data in Code command"));
 
+  // -macho-version-min
+  cl::opt<bool>
+  MachOVersionMin("macho-version-min",
+                  cl::desc("Display MachO version min command"));
   // -stackmap
   cl::opt<bool>
   PrintStackMap("stackmap",
@@ -320,6 +324,8 @@ static void dumpObject(const ObjectFile *Obj) {
   if (Obj->isMachO())
     if (opts::MachODataInCode)
       Dumper->printMachODataInCode();
+    if (opts::MachOVersionMin)
+      Dumper->printMachOVersionMin();
   if (opts::PrintStackMap)
     Dumper->printStackMap();
 }