summaryrefslogtreecommitdiff
path: root/include/llvm
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2013-06-06 17:20:50 +0000
committerKevin Enderby <enderby@apple.com>2013-06-06 17:20:50 +0000
commit54154f3bf1ae3d2dfd68cc9474cad061b3338a40 (patch)
tree5ebe75661f64525d36edb04be5363c1d10e112c9 /include/llvm
parentf2988a00843bf5ddef7c9ee8b26534a1aa8c56cf (diff)
downloadllvm-54154f3bf1ae3d2dfd68cc9474cad061b3338a40.tar.gz
llvm-54154f3bf1ae3d2dfd68cc9474cad061b3338a40.tar.bz2
llvm-54154f3bf1ae3d2dfd68cc9474cad061b3338a40.tar.xz
Teach llvm-objdump with the -macho parser how to use the data in code table
from the LC_DATA_IN_CODE load command. And when disassembling print the data in code formatted for the kind of data it and not disassemble those bytes. I added the format specific functionality to the derived class MachOObjectFile since these tables only appears in Mach-O object files. This is my first attempt to modify the libObject stuff so if folks have better suggestions how to fit this in or suggestions on the implementation please let me know. rdar://11791371 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/Object/MachO.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index f3ba8ef757..1b9faaa9fd 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -25,6 +25,31 @@
namespace llvm {
namespace object {
+/// DiceRef - This is a value type class that represents a single
+/// data in code entry in the table in a Mach-O object file.
+class DiceRef {
+ DataRefImpl DicePimpl;
+ const ObjectFile *OwningObject;
+
+public:
+ DiceRef() : OwningObject(NULL) { }
+
+ DiceRef(DataRefImpl DiceP, const ObjectFile *Owner);
+
+ bool operator==(const DiceRef &Other) const;
+ bool operator<(const DiceRef &Other) const;
+
+ error_code getNext(DiceRef &Result) const;
+
+ error_code getOffset(uint32_t &Result) const;
+ error_code getLength(uint16_t &Result) const;
+ error_code getKind(uint16_t &Result) const;
+
+ DataRefImpl getRawDataRefImpl() const;
+ const ObjectFile *getObjectFile() const;
+};
+typedef content_iterator<DiceRef> dice_iterator;
+
class MachOObjectFile : public ObjectFile {
public:
struct LoadCommandInfo {
@@ -108,6 +133,9 @@ public:
relocation_iterator getSectionRelBegin(unsigned Index) const;
relocation_iterator getSectionRelEnd(unsigned Index) const;
+ dice_iterator begin_dices() const;
+ dice_iterator end_dices() const;
+
// In a MachO file, sections have a segment name. This is used in the .o
// files. They have a single segment, but this field specifies which segment
// a section should be put in in the final object.
@@ -152,6 +180,7 @@ public:
getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const;
macho::RelocationEntry getRelocation(DataRefImpl Rel) const;
+ macho::DataInCodeTableEntry getDice(DataRefImpl Rel) const;
macho::Header getHeader() const;
macho::Header64Ext getHeader64Ext() const;
macho::IndirectSymbolTableEntry
@@ -161,6 +190,7 @@ public:
unsigned Index) const;
macho::SymtabLoadCommand getSymtabLoadCommand() const;
macho::DysymtabLoadCommand getDysymtabLoadCommand() const;
+ macho::LinkeditDataLoadCommand getDataInCodeLoadCommand() const;
StringRef getStringTableData() const;
bool is64Bit() const;
@@ -175,8 +205,66 @@ private:
SectionList Sections;
const char *SymtabLoadCmd;
const char *DysymtabLoadCmd;
+ const char *DataInCodeLoadCmd;
};
+/// DiceRef
+inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner)
+ : DicePimpl(DiceP) , OwningObject(Owner) {}
+
+inline bool DiceRef::operator==(const DiceRef &Other) const {
+ return DicePimpl == Other.DicePimpl;
+}
+
+inline bool DiceRef::operator<(const DiceRef &Other) const {
+ return DicePimpl < Other.DicePimpl;
+}
+
+inline error_code DiceRef::getNext(DiceRef &Result) const {
+ DataRefImpl Rel = DicePimpl;
+ const macho::DataInCodeTableEntry *P =
+ reinterpret_cast<const macho::DataInCodeTableEntry *>(Rel.p);
+ Rel.p = reinterpret_cast<uintptr_t>(P + 1);
+ Result = DiceRef(Rel, OwningObject);
+ return object_error::success;
+}
+
+// Since a Mach-O data in code reference, a DiceRef, can only be created when
+// the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for
+// the methods that get the values of the fields of the reference.
+
+inline error_code DiceRef::getOffset(uint32_t &Result) const {
+ const MachOObjectFile *MachOOF =
+ static_cast<const MachOObjectFile *>(OwningObject);
+ macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl);
+ Result = Dice.Offset;
+ return object_error::success;
+}
+
+inline error_code DiceRef::getLength(uint16_t &Result) const {
+ const MachOObjectFile *MachOOF =
+ static_cast<const MachOObjectFile *>(OwningObject);
+ macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl);
+ Result = Dice.Length;
+ return object_error::success;
+}
+
+inline error_code DiceRef::getKind(uint16_t &Result) const {
+ const MachOObjectFile *MachOOF =
+ static_cast<const MachOObjectFile *>(OwningObject);
+ macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl);
+ Result = Dice.Kind;
+ return object_error::success;
+}
+
+inline DataRefImpl DiceRef::getRawDataRefImpl() const {
+ return DicePimpl;
+}
+
+inline const ObjectFile *DiceRef::getObjectFile() const {
+ return OwningObject;
+}
+
}
}