[llvm] r231974 - Add the option, -info-plist to llvm-objdump used with -macho to print the

Kevin Enderby enderby at apple.com
Wed Mar 11 15:06:32 PDT 2015


Author: enderby
Date: Wed Mar 11 17:06:32 2015
New Revision: 231974

URL: http://llvm.org/viewvc/llvm-project?rev=231974&view=rev
Log:
Add the option, -info-plist to llvm-objdump used with -macho to print the
Mach-O info plist section as strings.

Added:
    llvm/trunk/test/tools/llvm-objdump/X86/macho-info-plist.test
Modified:
    llvm/trunk/tools/llvm-objdump/MachODump.cpp
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
    llvm/trunk/tools/llvm-objdump/llvm-objdump.h

Added: llvm/trunk/test/tools/llvm-objdump/X86/macho-info-plist.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/macho-info-plist.test?rev=231974&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/macho-info-plist.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/macho-info-plist.test Wed Mar 11 17:06:32 2015
@@ -0,0 +1,7 @@
+# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -info-plist - | FileCheck %s
+
+.section __TEXT, __info_plist
+.asciz "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
+# CHECK: Contents of (__TEXT,__info_plist) section
+# CHECK: <?xml version="1.0" encoding="UTF-8"?>

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=231974&r1=231973&r2=231974&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Wed Mar 11 17:06:32 2015
@@ -96,6 +96,11 @@ cl::list<std::string>
                        cl::desc("Prints the specified segment,section for "
                                 "Mach-O objects (requires -macho)"));
 
+cl::opt<bool>
+    llvm::InfoPlist("info-plist",
+                    cl::desc("Print the info plist section as strings for "
+                             "Mach-O objects (requires -macho)"));
+
 static cl::list<std::string>
     ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
               cl::ZeroOrMore);
@@ -981,6 +986,10 @@ static void DumpSectionContents(StringRe
             DisassembleMachO(Filename, O, SegName, SectName);
             continue;
           }
+          if (SegName == "__TEXT" && SectName == "__info_plist") {
+            outs() << sect;
+            continue;
+          }
           switch (section_type) {
           case MachO::S_REGULAR:
             DumpRawSectionContents(O, sect, sect_size, sect_addr);
@@ -1026,6 +1035,24 @@ static void DumpSectionContents(StringRe
   }
 }
 
+static void DumpInfoPlistSectionContents(StringRef Filename,
+                                         MachOObjectFile *O) {
+  for (const SectionRef &Section : O->sections()) {
+    StringRef SectName;
+    Section.getName(SectName);
+    DataRefImpl Ref = Section.getRawDataRefImpl();
+    StringRef SegName = O->getSectionFinalSegmentName(Ref);
+    if (SegName == "__TEXT" && SectName == "__info_plist") {
+      outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
+      StringRef BytesStr;
+      Section.getContents(BytesStr);
+      const char *sect = reinterpret_cast<const char *>(BytesStr.data());
+      outs() << sect;
+      return;
+    }
+  }
+}
+
 // checkMachOAndArchFlags() checks to see if the ObjectFile is a Mach-O file
 // and if it is and there is a list of architecture flags is specified then
 // check to make sure this Mach-O file is one of those architectures or all
@@ -1097,6 +1124,8 @@ static void ProcessMachO(StringRef Filen
     PrintSectionContents(MachOOF);
   if (DumpSections.size() != 0)
     DumpSectionContents(Filename, MachOOF, true);
+  if (InfoPlist)
+    DumpInfoPlistSectionContents(Filename, MachOOF);
   if (SymbolTable)
     PrintSymbolTable(MachOOF);
   if (UnwindInfo)

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=231974&r1=231973&r2=231974&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Mar 11 17:06:32 2015
@@ -907,6 +907,7 @@ int main(int argc, char **argv) {
       && !(IndirectSymbols && MachOOpt)
       && !(DataInCode && MachOOpt)
       && !(LinkOptHints && MachOOpt)
+      && !(InfoPlist && MachOOpt)
       && !(DumpSections.size() != 0 && MachOOpt)) {
     cl::PrintHelpMessage();
     return 2;

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.h?rev=231974&r1=231973&r2=231974&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Wed Mar 11 17:06:32 2015
@@ -40,6 +40,7 @@ extern cl::opt<bool> ArchiveHeaders;
 extern cl::opt<bool> IndirectSymbols;
 extern cl::opt<bool> DataInCode;
 extern cl::opt<bool> LinkOptHints;
+extern cl::opt<bool> InfoPlist;
 extern cl::opt<bool> Relocations;
 extern cl::opt<bool> SectionHeaders;
 extern cl::opt<bool> SectionContents;





More information about the llvm-commits mailing list