Index: MachODumper.cpp =================================================================== --- MachODumper.cpp +++ MachODumper.cpp @@ -40,6 +40,9 @@ void printUnwindInfo() override; void printStackMap() const override; + // MachO-specific. + void printMachODataInCode() override; + private: template void printFileHeaders(const MachHeader &Header); @@ -600,3 +603,25 @@ prettyPrintStackMap(llvm::outs(), StackMapV1Parser(StackMapContentsArray)); } + +void MachODumper::printMachODataInCode() { + for (const auto &Load : Obj->load_commands()) { + if (Load.C.cmd == MachO::LC_DATA_IN_CODE) { + MachO::linkedit_data_command LLC = Obj->getLinkeditDataLoadCommand(Load); + DictScope Group(W, "DataInCode"); + W.printNumber("Data offset", LLC.dataoff); + W.printNumber("Data size", LLC.datasize); + ListScope D(W, "Data Regions"); + unsigned NumRegions = LLC.datasize / sizeof(MachO::data_in_code_entry); + for (unsigned i = 0; i < NumRegions; ++i) { + MachO::data_in_code_entry DICE = Obj->getDataInCodeTableEntry( + LLC.dataoff, i); + DictScope Group(W, "DICE"); + W.printNumber("Index", i); + W.printNumber("Offset", DICE.offset); + W.printNumber("Length", DICE.length); + W.printNumber("Kind", DICE.kind); + } + } + } +} Index: ObjDumper.h =================================================================== --- ObjDumper.h +++ ObjDumper.h @@ -54,6 +54,9 @@ virtual void printCOFFDirectives() { } virtual void printCOFFBaseReloc() { } + // Only implemented for MachO. + virtual void printMachODataInCode() { } + virtual void printStackMap() const = 0; protected: Index: llvm-readobj.cpp =================================================================== --- llvm-readobj.cpp +++ llvm-readobj.cpp @@ -181,6 +181,11 @@ COFFBaseRelocs("coff-basereloc", cl::desc("Display the PE/COFF .reloc section")); + // -macho-dice + cl::opt + MachODataInCode("macho-dice", + cl::desc("Display MachO Data in Code command")); + // -stackmap cl::opt PrintStackMap("stackmap", @@ -312,6 +317,9 @@ if (opts::COFFBaseRelocs) Dumper->printCOFFBaseReloc(); } + if (Obj->isMachO()) + if (opts::MachODataInCode) + Dumper->printMachODataInCode(); if (opts::PrintStackMap) Dumper->printStackMap(); }