llvm.org GIT mirror llvm / 66e2ddc
Add the option, -data-in-code, to llvm-objdump used with -macho to print the Mach-O data in code table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226921 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 5 years ago
5 changed file(s) with 61 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 RUN: llvm-objdump -m -data-in-code %p/Inputs/data-in-code.macho-arm | FileCheck %s
1
2 CHECK: Data in code table (4 entries)
3 CHECK: offset length kind
4 CHECK: 0x00000000 4 DATA
5 CHECK: 0x00000004 4 JUMP_TABLE32
6 CHECK: 0x00000008 2 JUMP_TABLE16
7 CHECK: 0x0000000a 1 JUMP_TABLE8
7979 cl::desc("Print indirect symbol table for Mach-O "
8080 "objects (requires -macho)"));
8181
82 cl::opt
83 llvm::DataInCode("data-in-code",
84 cl::desc("Print the data in code table for Mach-O objects "
85 "(requires -macho)"));
86
8287 static cl::list
8388 ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
8489 cl::ZeroOrMore);
388393 }
389394 }
390395
396 static void PrintDataInCodeTable(MachOObjectFile *O, bool verbose) {
397 MachO::linkedit_data_command DIC = O->getDataInCodeLoadCommand();
398 uint32_t nentries = DIC.datasize / sizeof(struct MachO::data_in_code_entry);
399 outs() << "Data in code table (" << nentries << " entries)\n";
400 outs() << "offset length kind\n";
401 for (dice_iterator DI = O->begin_dices(), DE = O->end_dices(); DI != DE;
402 ++DI) {
403 uint32_t Offset;
404 DI->getOffset(Offset);
405 outs() << format("0x%08" PRIx32, Offset) << " ";
406 uint16_t Length;
407 DI->getLength(Length);
408 outs() << format("%6u", Length) << " ";
409 uint16_t Kind;
410 DI->getKind(Kind);
411 if (verbose) {
412 switch (Kind) {
413 case MachO::DICE_KIND_DATA:
414 outs() << "DATA";
415 break;
416 case MachO::DICE_KIND_JUMP_TABLE8:
417 outs() << "JUMP_TABLE8";
418 break;
419 case MachO::DICE_KIND_JUMP_TABLE16:
420 outs() << "JUMP_TABLE16";
421 break;
422 case MachO::DICE_KIND_JUMP_TABLE32:
423 outs() << "JUMP_TABLE32";
424 break;
425 case MachO::DICE_KIND_ABS_JUMP_TABLE32:
426 outs() << "ABS_JUMP_TABLE32";
427 break;
428 default:
429 outs() << format("0x%04" PRIx32, Kind);
430 break;
431 }
432 } else
433 outs() << format("0x%04" PRIx32, Kind);
434 outs() << "\n";
435 }
436 }
437
391438 // checkMachOAndArchFlags() checks to see if the ObjectFile is a Mach-O file
392439 // and if it is and there is a list of architecture flags is specified then
393440 // check to make sure this Mach-O file is one of those architectures or all
435482 // info. And don't print it otherwise like in the case of printing the
436483 // UniversalHeaders or ArchiveHeaders.
437484 if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
438 LazyBind || WeakBind || IndirectSymbols) {
485 LazyBind || WeakBind || IndirectSymbols || DataInCode) {
439486 outs() << Filename;
440487 if (!ArchiveMemberName.empty())
441488 outs() << '(' << ArchiveMemberName << ')';
448495 DisassembleMachO(Filename, MachOOF);
449496 if (IndirectSymbols)
450497 PrintIndirectSymbols(MachOOF, true);
498 if (DataInCode)
499 PrintDataInCodeTable(MachOOF, true);
451500 if (Relocations)
452501 PrintRelocations(MachOOF);
453502 if (SectionHeaders)
893893 && !WeakBind
894894 && !(UniversalHeaders && MachOOpt)
895895 && !(ArchiveHeaders && MachOOpt)
896 && !(IndirectSymbols && MachOOpt)) {
896 && !(IndirectSymbols && MachOOpt)
897 && !(DataInCode && MachOOpt)) {
897898 cl::PrintHelpMessage();
898899 return 2;
899900 }
3636 extern cl::opt UniversalHeaders;
3737 extern cl::opt ArchiveHeaders;
3838 extern cl::opt IndirectSymbols;
39 extern cl::opt DataInCode;
3940 extern cl::opt Relocations;
4041 extern cl::opt SectionHeaders;
4142 extern cl::opt SectionContents;