[llvm] r226921 - Add the option, -data-in-code, to llvm-objdump used with -macho to print the Mach-O data in code table.
Kevin Enderby
enderby at apple.com
Fri Jan 23 10:52:18 PST 2015
Author: enderby
Date: Fri Jan 23 12:52:17 2015
New Revision: 226921
URL: http://llvm.org/viewvc/llvm-project?rev=226921&view=rev
Log:
Add the option, -data-in-code, to llvm-objdump used with -macho to print the Mach-O data in code table.
Added:
llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/data-in-code.macho-arm (with props)
llvm/trunk/test/tools/llvm-objdump/ARM/macho-data-in-code.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/ARM/Inputs/data-in-code.macho-arm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/data-in-code.macho-arm?rev=226921&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-objdump/ARM/Inputs/data-in-code.macho-arm
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-objdump/ARM/macho-data-in-code.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/macho-data-in-code.test?rev=226921&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/ARM/macho-data-in-code.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/ARM/macho-data-in-code.test Fri Jan 23 12:52:17 2015
@@ -0,0 +1,8 @@
+RUN: llvm-objdump -m -data-in-code %p/Inputs/data-in-code.macho-arm | FileCheck %s
+
+CHECK: Data in code table (4 entries)
+CHECK: offset length kind
+CHECK: 0x00000000 4 DATA
+CHECK: 0x00000004 4 JUMP_TABLE32
+CHECK: 0x00000008 2 JUMP_TABLE16
+CHECK: 0x0000000a 1 JUMP_TABLE8
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=226921&r1=226920&r2=226921&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Jan 23 12:52:17 2015
@@ -80,6 +80,11 @@ cl::opt<bool>
cl::desc("Print indirect symbol table for Mach-O "
"objects (requires -macho)"));
+cl::opt<bool>
+ llvm::DataInCode("data-in-code",
+ cl::desc("Print the data in code table 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);
@@ -389,6 +394,48 @@ static void PrintIndirectSymbols(MachOOb
}
}
+static void PrintDataInCodeTable(MachOObjectFile *O, bool verbose) {
+ MachO::linkedit_data_command DIC = O->getDataInCodeLoadCommand();
+ uint32_t nentries = DIC.datasize / sizeof(struct MachO::data_in_code_entry);
+ outs() << "Data in code table (" << nentries << " entries)\n";
+ outs() << "offset length kind\n";
+ for (dice_iterator DI = O->begin_dices(), DE = O->end_dices(); DI != DE;
+ ++DI) {
+ uint32_t Offset;
+ DI->getOffset(Offset);
+ outs() << format("0x%08" PRIx32, Offset) << " ";
+ uint16_t Length;
+ DI->getLength(Length);
+ outs() << format("%6u", Length) << " ";
+ uint16_t Kind;
+ DI->getKind(Kind);
+ if (verbose) {
+ switch (Kind) {
+ case MachO::DICE_KIND_DATA:
+ outs() << "DATA";
+ break;
+ case MachO::DICE_KIND_JUMP_TABLE8:
+ outs() << "JUMP_TABLE8";
+ break;
+ case MachO::DICE_KIND_JUMP_TABLE16:
+ outs() << "JUMP_TABLE16";
+ break;
+ case MachO::DICE_KIND_JUMP_TABLE32:
+ outs() << "JUMP_TABLE32";
+ break;
+ case MachO::DICE_KIND_ABS_JUMP_TABLE32:
+ outs() << "ABS_JUMP_TABLE32";
+ break;
+ default:
+ outs() << format("0x%04" PRIx32, Kind);
+ break;
+ }
+ } else
+ outs() << format("0x%04" PRIx32, Kind);
+ outs() << "\n";
+ }
+}
+
// 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
@@ -436,7 +483,7 @@ static void ProcessMachO(StringRef Filen
// info. And don't print it otherwise like in the case of printing the
// UniversalHeaders or ArchiveHeaders.
if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
- LazyBind || WeakBind || IndirectSymbols) {
+ LazyBind || WeakBind || IndirectSymbols || DataInCode) {
outs() << Filename;
if (!ArchiveMemberName.empty())
outs() << '(' << ArchiveMemberName << ')';
@@ -449,6 +496,8 @@ static void ProcessMachO(StringRef Filen
DisassembleMachO(Filename, MachOOF);
if (IndirectSymbols)
PrintIndirectSymbols(MachOOF, true);
+ if (DataInCode)
+ PrintDataInCodeTable(MachOOF, true);
if (Relocations)
PrintRelocations(MachOOF);
if (SectionHeaders)
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=226921&r1=226920&r2=226921&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Jan 23 12:52:17 2015
@@ -894,7 +894,8 @@ int main(int argc, char **argv) {
&& !WeakBind
&& !(UniversalHeaders && MachOOpt)
&& !(ArchiveHeaders && MachOOpt)
- && !(IndirectSymbols && MachOOpt)) {
+ && !(IndirectSymbols && MachOOpt)
+ && !(DataInCode && 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=226921&r1=226920&r2=226921&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Fri Jan 23 12:52:17 2015
@@ -37,6 +37,7 @@ extern cl::opt<bool> WeakBind;
extern cl::opt<bool> UniversalHeaders;
extern cl::opt<bool> ArchiveHeaders;
extern cl::opt<bool> IndirectSymbols;
+extern cl::opt<bool> DataInCode;
extern cl::opt<bool> Relocations;
extern cl::opt<bool> SectionHeaders;
extern cl::opt<bool> SectionContents;
More information about the llvm-commits
mailing list