From: Kevin Enderby Date: Wed, 11 Mar 2015 22:06:32 +0000 (+0000) Subject: Add the option, -info-plist to llvm-objdump used with -macho to print the X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8284f0fb291c3882c86aef99cdf32672c6db5422;p=oota-llvm.git Add the option, -info-plist to llvm-objdump used with -macho to print the Mach-O info plist section as strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231974 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-objdump/X86/macho-info-plist.test b/test/tools/llvm-objdump/X86/macho-info-plist.test new file mode 100644 index 00000000000..bee1952ce9b --- /dev/null +++ b/test/tools/llvm-objdump/X86/macho-info-plist.test @@ -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 "\n" + +# CHECK: Contents of (__TEXT,__info_plist) section +# CHECK: diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 8acb097eeda..cf86d1c6812 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -96,6 +96,11 @@ cl::list cl::desc("Prints the specified segment,section for " "Mach-O objects (requires -macho)")); +cl::opt + llvm::InfoPlist("info-plist", + cl::desc("Print the info plist section as strings for " + "Mach-O objects (requires -macho)")); + static cl::list ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"), cl::ZeroOrMore); @@ -981,6 +986,10 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, 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(StringRef Filename, MachOObjectFile *O, } } +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(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 Filename, MachOObjectFile *MachOOF, PrintSectionContents(MachOOF); if (DumpSections.size() != 0) DumpSectionContents(Filename, MachOOF, true); + if (InfoPlist) + DumpInfoPlistSectionContents(Filename, MachOOF); if (SymbolTable) PrintSymbolTable(MachOOF); if (UnwindInfo) diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 6e62aaac235..4bae053b403 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -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; diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index 19f842f381d..845b7ea26bb 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -40,6 +40,7 @@ extern cl::opt ArchiveHeaders; extern cl::opt IndirectSymbols; extern cl::opt DataInCode; extern cl::opt LinkOptHints; +extern cl::opt InfoPlist; extern cl::opt Relocations; extern cl::opt SectionHeaders; extern cl::opt SectionContents;