[PATCH] D12084: [llvm-readobj] Add support for MachO DataInCodeDataCommand
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 08:15:13 PDT 2015
+ Kevin, who's not on phab.
On Mon, Aug 17, 2015 at 11:14 AM, Davide Italiano <dccitaliano at gmail.com> wrote:
> davide created this revision.
> davide added reviewers: grosbach, rafael, echristo.
> davide added a subscriber: llvm-commits.
> Herald added a subscriber: aemerson.
>
> macho-dump has this. And some tests rely on it.
> I ported it to llvm-readobj as part of the bigger project "let's deprecate macho-dump".
> Example output:
>
> % /exps/llvm2/build/./bin/llvm-mc -triple armv7-apple-darwin10 -filetype=obj -o - < /exps/llvm2/test/MC/MachO/ARM/data-in-code.s | /exps/llvm2/build/bin/llvm-readobj -macho-dice
>
> File: <stdin>
> Format: Mach-O arm
> Arch: arm
> AddressSize: 32bit
> DataInCode {
> Data offset: 300
> Data size: 32
> Data Regions [
> DICE {
> Index: 0
> Offset: 0
> Length: 4
> Kind: 1
> }
> DICE {
> Index: 1
> Offset: 4
> Length: 4
> Kind: 4
> }
> DICE {
> Index: 2
> Offset: 8
> Length: 2
> Kind: 3
> }
> DICE {
> Index: 3
> Offset: 10
> Length: 1
> Kind: 2
> }
> ]
> }
>
> Feedback really appreciated.
>
>
>
> http://reviews.llvm.org/D12084
>
> Files:
> MachODumper.cpp
> ObjDumper.h
> llvm-readobj.cpp
>
> 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<bool>
> + MachODataInCode("macho-dice",
> + cl::desc("Display MachO Data in Code command"));
> +
> // -stackmap
> cl::opt<bool>
> PrintStackMap("stackmap",
> @@ -312,6 +317,9 @@
> if (opts::COFFBaseRelocs)
> Dumper->printCOFFBaseReloc();
> }
> + if (Obj->isMachO())
> + if (opts::MachODataInCode)
> + Dumper->printMachODataInCode();
> if (opts::PrintStackMap)
> Dumper->printStackMap();
> }
> 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: MachODumper.cpp
> ===================================================================
> --- MachODumper.cpp
> +++ MachODumper.cpp
> @@ -40,6 +40,9 @@
> void printUnwindInfo() override;
> void printStackMap() const override;
>
> + // MachO-specific.
> + void printMachODataInCode() override;
> +
> private:
> template<class MachHeader>
> void printFileHeaders(const MachHeader &Header);
> @@ -600,3 +603,25 @@
> prettyPrintStackMap(llvm::outs(),
> StackMapV1Parser<support::big>(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);
> + }
> + }
> + }
> +}
>
>
More information about the llvm-commits
mailing list