static bool collectRelocatedSymbols(const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, uint64_t SymAddress, uint64_t SymSize, StringRef *I, StringRef *E) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; for (const SectionRef &SR : getRelocSections(Obj, Sec)) { for (const object::RelocationRef &Reloc : SR.relocations()) { if (I == E) break; const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; StringRef RelocSymName; if (error(RelocSymI->getName(RelocSymName))) return true; uint64_t Offset; if (error(Reloc.getOffset(Offset))) return true; if (Offset >= SymOffset && Offset < SymEnd) { *I = RelocSymName; ++I; } } } return false; }
static bool collectRelocationOffsets( const ObjectFile *Obj, object::section_iterator SecI, StringRef SymName, std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) { for (const object::RelocationRef &Reloc : SecI->relocations()) { const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; StringRef RelocSymName; if (error(RelocSymI->getName(RelocSymName))) return true; uint64_t Offset; if (error(Reloc.getOffset(Offset))) return true; Collection[std::make_pair(SymName, Offset)] = RelocSymName; } return false; }
static bool collectRelocatedSymbols(const ObjectFile *Obj, object::section_iterator SecI, StringRef *I, StringRef *E) { for (const object::RelocationRef &Reloc : SecI->relocations()) { if (I == E) break; const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; StringRef RelocSymName; if (error(RelocSymI->getName(RelocSymName))) return true; *I = RelocSymName; ++I; } return false; }
static void collectRelocationOffsets( const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, uint64_t SymAddress, uint64_t SymSize, StringRef SymName, std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; for (const SectionRef &SR : SectionRelocMap[Sec]) { for (const object::RelocationRef &Reloc : SR.relocations()) { const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); error(RelocSymName.getError()); uint64_t Offset = Reloc.getOffset(); if (Offset >= SymOffset && Offset < SymEnd) Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName; } } }
static void collectRelocatedSymbols(const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, uint64_t SymAddress, uint64_t SymSize, StringRef *I, StringRef *E) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; for (const SectionRef &SR : SectionRelocMap[Sec]) { for (const object::RelocationRef &Reloc : SR.relocations()) { if (I == E) break; const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; ErrorOr<StringRef> RelocSymName = RelocSymI->getName(); error(RelocSymName.getError()); uint64_t Offset = Reloc.getOffset(); if (Offset >= SymOffset && Offset < SymEnd) { *I = *RelocSymName; ++I; } } } }
static bool collectRelocationOffsets( const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, uint64_t SymAddress, uint64_t SymSize, StringRef SymName, std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; for (const SectionRef &SR : getRelocSections(Obj, Sec)) { for (const object::RelocationRef &Reloc : SR.relocations()) { const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; StringRef RelocSymName; if (error(RelocSymI->getName(RelocSymName))) return true; uint64_t Offset; if (error(Reloc.getOffset(Offset))) return true; if (Offset >= SymOffset && Offset < SymEnd) Collection[std::make_pair(SymName, Offset - SymOffset)] = RelocSymName; } } return false; }
static void dumpVTables(const ObjectFile *Obj) { std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries; std::map<StringRef, ArrayRef<aligned_little32_t>> VBTables; for (const object::SymbolRef &Sym : Obj->symbols()) { StringRef SymName; if (error(Sym.getName(SymName))) return; // VFTables in the MS-ABI start with '??_7' and are contained within their // own COMDAT section. We then determine the contents of the VFTable by // looking at each relocation in the section. if (SymName.startswith("??_7")) { object::section_iterator SecI(Obj->section_begin()); if (error(Sym.getSection(SecI))) return; if (SecI == Obj->section_end()) continue; // Each relocation either names a virtual method or a thunk. We note the // offset into the section and the symbol used for the relocation. for (const object::RelocationRef &Reloc : SecI->relocations()) { const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) continue; StringRef RelocSymName; if (error(RelocSymI->getName(RelocSymName))) return; uint64_t Offset; if (error(Reloc.getOffset(Offset))) return; VFTableEntries[std::make_pair(SymName, Offset)] = RelocSymName; } } // VBTables in the MS-ABI start with '??_8' and are filled with 32-bit // offsets of virtual bases. else if (SymName.startswith("??_8")) { object::section_iterator SecI(Obj->section_begin()); if (error(Sym.getSection(SecI))) return; if (SecI == Obj->section_end()) continue; StringRef SecContents; if (error(SecI->getContents(SecContents))) return; ArrayRef<aligned_little32_t> VBTableData( reinterpret_cast<const aligned_little32_t *>(SecContents.data()), SecContents.size() / sizeof(aligned_little32_t)); VBTables[SymName] = VBTableData; } } for ( const std::pair<std::pair<StringRef, uint64_t>, StringRef> &VFTableEntry : VFTableEntries) { StringRef VFTableName = VFTableEntry.first.first; uint64_t Offset = VFTableEntry.first.second; StringRef SymName = VFTableEntry.second; outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n'; } for (const std::pair<StringRef, ArrayRef<aligned_little32_t>> &VBTable : VBTables) { StringRef VBTableName = VBTable.first; uint32_t Idx = 0; for (aligned_little32_t Offset : VBTable.second) { outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n'; Idx += sizeof(Offset); } } }