auto sHdr = *sHdrOrErr;
auto ri = _objFile->rel_begin(§ion);
auto re = _objFile->rel_end(§ion);
- _relocationReferences[sHdr] = make_range(ri, re);
+ _relocationReferences[sHdr] = §ion;
totalRelocs += std::distance(ri, re);
} else {
auto sectionName = _objFile->getSectionName(§ion);
return ec;
sectionNames.push_back(*sectionName);
}
- const Elf_Sym *symbol = _objFile->getSymbol(section->sh_info);
ErrorOr<const Elf_Shdr *> symtab = _objFile->getSection(section->sh_link);
if (std::error_code ec = symtab.getError())
return ec;
+ const Elf_Sym *symbol = _objFile->getSymbol(*symtab, section->sh_info);
ErrorOr<const Elf_Shdr *> strtab_sec =
_objFile->getSection((*symtab)->sh_link);
if (std::error_code ec = strtab_sec.getError())
void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
- range<const Elf_Rel *> rels) {
+ const Elf_Shdr *relSec) {
+ auto rels = _objFile->rels(relSec);
bool isMips64EL = _objFile->isMips64EL();
const auto symValue = getSymbolValue(symbol);
for (const auto &rel : rels) {
}
template <class ELFT> void ELFFile<ELFT>::updateReferences() {
+ const Elf_Shdr *symtab = _objFile->getDotSymtabSec();
for (auto &ri : _references) {
if (ri->kindNamespace() != Reference::KindNamespace::ELF)
continue;
- const Elf_Sym *symbol = _objFile->getSymbol(ri->targetSymbolIndex());
+ const Elf_Sym *symbol =
+ _objFile->getSymbol(symtab, ri->targetSymbolIndex());
ErrorOr<const Elf_Shdr *> shdr = _objFile->getSection(symbol);
// If the atom is not in mergeable string section, the target atom is
virtual void createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
- range<const Elf_Rel *> rels);
+ const Elf_Shdr *relSec);
/// \brief After all the Atoms and References are created, update each
/// Reference's target with the Atom pointer it refers to.
std::unordered_map<const Elf_Shdr *, range<const Elf_Rela *>>
_relocationAddendReferences;
MergedSectionMapT _mergedSectionMap;
- std::unordered_map<const Elf_Shdr *, range<const Elf_Rel *>>
- _relocationReferences;
+ std::unordered_map<const Elf_Shdr *, const Elf_Shdr *> _relocationReferences;
std::vector<ELFReference<ELFT> *> _references;
llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping;
llvm::DenseMap<const ELFReference<ELFT> *, const Elf_Sym *>
}
template <class ELFT>
-void MipsELFFile<ELFT>::createRelocationReferences(
- const Elf_Sym *symbol, ArrayRef<uint8_t> symContent,
- ArrayRef<uint8_t> secContent, range<const Elf_Rel *> rels) {
+void MipsELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
+ ArrayRef<uint8_t> symContent,
+ ArrayRef<uint8_t> secContent,
+ const Elf_Shdr *relSec) {
+ const Elf_Shdr *symtab = *this->_objFile->getSection(relSec->sh_link);
+ auto rels = this->_objFile->rels(relSec);
const auto value = this->getSymbolValue(symbol);
for (const Elf_Rel *rit = rels.begin(), *eit = rels.end(); rit != eit;
++rit) {
this->_references.push_back(r);
auto addend = readAddend(*rit, secContent);
- auto pairRelType = getPairRelocation(*rit);
+ auto pairRelType = getPairRelocation(symtab, *rit);
if (pairRelType != llvm::ELF::R_MIPS_NONE) {
addend <<= 16;
auto mit = findMatchingRelocation(pairRelType, rit, eit);
}
template <class ELFT>
-uint32_t MipsELFFile<ELFT>::getPairRelocation(const Elf_Rel &rel) const {
+uint32_t MipsELFFile<ELFT>::getPairRelocation(const Elf_Shdr *symtab,
+ const Elf_Rel &rel) const {
switch (getPrimaryType(rel)) {
case llvm::ELF::R_MIPS_HI16:
return llvm::ELF::R_MIPS_LO16;
case llvm::ELF::R_MIPS_PCHI16:
return llvm::ELF::R_MIPS_PCLO16;
case llvm::ELF::R_MIPS_GOT16:
- if (isLocalBinding(rel))
+ if (isLocalBinding(symtab, rel))
return llvm::ELF::R_MIPS_LO16;
break;
case llvm::ELF::R_MICROMIPS_HI16:
return llvm::ELF::R_MICROMIPS_LO16;
case llvm::ELF::R_MICROMIPS_GOT16:
- if (isLocalBinding(rel))
+ if (isLocalBinding(symtab, rel))
return llvm::ELF::R_MICROMIPS_LO16;
break;
default:
}
template <class ELFT>
-bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Rel &rel) const {
- return this->_objFile->getSymbol(rel.getSymbol(isMips64EL<ELFT>()))
+bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Shdr *symtab,
+ const Elf_Rel &rel) const {
+ return this->_objFile->getSymbol(symtab, rel.getSymbol(isMips64EL<ELFT>()))
->getBinding() == llvm::ELF::STB_LOCAL;
}
void createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
- range<const Elf_Rel *> rels) override;
+ const Elf_Shdr *RelSec) override;
const Elf_Shdr *findSectionByType(uint64_t type) const;
const Elf_Shdr *findSectionByFlags(uint64_t flags) const;
Reference::Addend readAddend(const Elf_Rel &ri,
const ArrayRef<uint8_t> content) const;
- uint32_t getPairRelocation(const Elf_Rel &rel) const;
+ uint32_t getPairRelocation(const Elf_Shdr *Symtab, const Elf_Rel &rel) const;
const Elf_Rel *findMatchingRelocation(uint32_t pairRelType,
const Elf_Rel *rit,
const Elf_Rel *eit) const;
- bool isLocalBinding(const Elf_Rel &rel) const;
+ bool isLocalBinding(const Elf_Shdr *Symtab, const Elf_Rel &rel) const;
};
} // elf