summaryrefslogtreecommitdiff
path: root/lib/Object
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 /lib/Object
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 'lib/Object')
-rw-r--r--lib/Object/MachOObjectFile.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp
index bd5ea57c1f..e62b5a4819 100644
--- a/lib/Object/MachOObjectFile.cpp
+++ b/lib/Object/MachOObjectFile.cpp
@@ -414,7 +414,7 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
bool IsLittleEndian, bool Is64bits,
error_code &ec)
: ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
- SymtabLoadCmd(NULL), DysymtabLoadCmd(NULL) {
+ SymtabLoadCmd(NULL), DysymtabLoadCmd(NULL), DataInCodeLoadCmd(NULL) {
uint32_t LoadCommandCount = this->getHeader().NumLoadCommands;
macho::LoadCommandType SegmentLoadType = is64Bit() ?
macho::LCT_Segment64 : macho::LCT_Segment;
@@ -427,6 +427,9 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
} else if (Load.C.Type == macho::LCT_Dysymtab) {
assert(!DysymtabLoadCmd && "Multiple dynamic symbol tables");
DysymtabLoadCmd = Load.Ptr;
+ } else if (Load.C.Type == macho::LCT_DataInCode) {
+ assert(!DataInCodeLoadCmd && "Multiple data in code tables");
+ DataInCodeLoadCmd = Load.Ptr;
} else if (Load.C.Type == SegmentLoadType) {
uint32_t NumSections = getSegmentLoadCommandNumSections(this, Load);
for (unsigned J = 0; J < NumSections; ++J) {
@@ -1328,6 +1331,27 @@ relocation_iterator MachOObjectFile::getSectionRelEnd(unsigned Index) const {
return getSectionRelEnd(DRI);
}
+dice_iterator MachOObjectFile::begin_dices() const {
+ DataRefImpl DRI;
+ if (!DataInCodeLoadCmd)
+ return dice_iterator(DiceRef(DRI, this));
+
+ macho::LinkeditDataLoadCommand DicLC = getDataInCodeLoadCommand();
+ DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, DicLC.DataOffset));
+ return dice_iterator(DiceRef(DRI, this));
+}
+
+dice_iterator MachOObjectFile::end_dices() const {
+ DataRefImpl DRI;
+ if (!DataInCodeLoadCmd)
+ return dice_iterator(DiceRef(DRI, this));
+
+ macho::LinkeditDataLoadCommand DicLC = getDataInCodeLoadCommand();
+ unsigned Offset = DicLC.DataOffset + DicLC.DataSize;
+ DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset));
+ return dice_iterator(DiceRef(DRI, this));
+}
+
StringRef
MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec) const {
ArrayRef<char> Raw = getSectionRawFinalSegmentName(Sec);
@@ -1492,6 +1516,12 @@ MachOObjectFile::getRelocation(DataRefImpl Rel) const {
return getStruct<macho::RelocationEntry>(this, P);
}
+macho::DataInCodeTableEntry
+MachOObjectFile::getDice(DataRefImpl Rel) const {
+ const char *P = reinterpret_cast<const char *>(Rel.p);
+ return getStruct<macho::DataInCodeTableEntry>(this, P);
+}
+
macho::Header MachOObjectFile::getHeader() const {
return getStruct<macho::Header>(this, getPtr(this, 0));
}
@@ -1524,6 +1554,20 @@ macho::DysymtabLoadCommand MachOObjectFile::getDysymtabLoadCommand() const {
return getStruct<macho::DysymtabLoadCommand>(this, DysymtabLoadCmd);
}
+macho::LinkeditDataLoadCommand
+MachOObjectFile::getDataInCodeLoadCommand() const {
+ if (DataInCodeLoadCmd)
+ return getStruct<macho::LinkeditDataLoadCommand>(this, DataInCodeLoadCmd);
+
+ // If there is no DataInCodeLoadCmd return a load command with zero'ed fields.
+ macho::LinkeditDataLoadCommand Cmd;
+ Cmd.Type = macho::LCT_DataInCode;
+ Cmd.Size = macho::LinkeditLoadCommandSize;
+ Cmd.DataOffset = 0;
+ Cmd.DataSize = 0;
+ return Cmd;
+}
+
StringRef MachOObjectFile::getStringTableData() const {
macho::SymtabLoadCommand S = getSymtabLoadCommand();
return getData().substr(S.StringTableOffset, S.StringTableSize);