diff options
Diffstat (limited to 'lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index dfd8d3d3dd..e62b5a4819 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -339,7 +339,7 @@ static void printRelocationTargetName(const MachOObjectFile *O, StringRef S; bool isExtern = O->getPlainRelocationExternal(RE); - uint64_t Val = O->getAnyRelocationAddress(RE); + uint64_t Val = O->getPlainRelocationSymbolNum(RE); if (isExtern) { symbol_iterator SI = O->begin_symbols(); @@ -347,7 +347,8 @@ static void printRelocationTargetName(const MachOObjectFile *O, SI->getName(S); } else { section_iterator SI = O->begin_sections(); - advanceTo(SI, Val); + // Adjust for the fact that sections are 1-indexed. + advanceTo(SI, Val - 1); SI->getName(S); } @@ -413,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; @@ -426,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) { @@ -868,15 +872,13 @@ error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel, return object_error::success; } -error_code -MachOObjectFile::getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const { +symbol_iterator +MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const { macho::RelocationEntry RE = getRelocation(Rel); uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE); bool isExtern = getPlainRelocationExternal(RE); - if (!isExtern) { - Res = *end_symbols(); - return object_error::success; - } + if (!isExtern) + return end_symbols(); macho::SymtabLoadCommand S = getSymtabLoadCommand(); unsigned SymbolTableEntrySize = is64Bit() ? @@ -885,8 +887,7 @@ MachOObjectFile::getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const { uint64_t Offset = S.SymbolTableOffset + SymbolIdx * SymbolTableEntrySize; DataRefImpl Sym; Sym.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset)); - Res = SymbolRef(Sym, this); - return object_error::success; + return symbol_iterator(SymbolRef(Sym, this)); } error_code MachOObjectFile::getRelocationType(DataRefImpl Rel, @@ -989,12 +990,6 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, return object_error::success; } -error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel, - int64_t &Res) const { - Res = 0; - return object_error::success; -} - error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel, SmallVectorImpl<char> &Result) const { @@ -1336,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); @@ -1500,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)); } @@ -1532,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); |