template <class ELFT> class ELFReference : public Reference {
typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
+ typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
+
public:
- ELFReference(const Elf_Rela *rela, uint64_t off, Reference::KindArch arch,
- Reference::KindValue relocType, uint32_t idx)
- : Reference(Reference::KindNamespace::ELF, arch, relocType),
+ ELFReference(const Elf_Sym *sym, const Elf_Rela *rela, uint64_t off,
+ Reference::KindArch arch, Reference::KindValue relocType,
+ uint32_t idx)
+ : Reference(Reference::KindNamespace::ELF, arch, relocType), _sym(sym),
_target(nullptr), _targetSymbolIndex(idx), _offsetInAtom(off),
_addend(rela->r_addend) {}
- ELFReference(uint64_t off, Reference::KindArch arch,
+ ELFReference(const Elf_Sym *sym, uint64_t off, Reference::KindArch arch,
Reference::KindValue relocType, uint32_t idx)
- : Reference(Reference::KindNamespace::ELF, arch, relocType),
+ : Reference(Reference::KindNamespace::ELF, arch, relocType), _sym(sym),
_target(nullptr), _targetSymbolIndex(idx), _offsetInAtom(off),
_addend(0) {}
ELFReference(uint32_t edgeKind)
: Reference(Reference::KindNamespace::all, Reference::KindArch::all,
edgeKind),
- _target(nullptr), _targetSymbolIndex(0), _offsetInAtom(0), _addend(0) {}
+ _sym(nullptr), _target(nullptr), _targetSymbolIndex(0),
+ _offsetInAtom(0), _addend(0) {}
uint64_t offsetInAtom() const override { return _offsetInAtom; }
void setTarget(const Atom *newAtom) override { _target = newAtom; }
+ const Elf_Sym *symbol() const { return _sym; }
+
private:
+ const Elf_Sym *_sym;
const Atom *_target;
uint64_t _targetSymbolIndex;
uint64_t _offsetInAtom;
std::error_code doParse() override;
/// \brief Iterate over Elf_Rela relocations list and create references.
- virtual void createRelocationReferences(const Elf_Sym &symbol,
+ virtual void createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> content,
range<Elf_Rela_Iter> rels);
/// \brief Iterate over Elf_Rel relocations list and create references.
- virtual void createRelocationReferences(const Elf_Sym &symbol,
+ virtual void createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
range<Elf_Rel_Iter> rels);
// Add Rela (those with r_addend) references:
auto rari = _relocationAddendReferences.find(sectionName);
if (rari != _relocationAddendReferences.end())
- createRelocationReferences(*symbol, symContent, rari->second);
+ createRelocationReferences(symbol, symContent, rari->second);
// Add Rel references.
auto rri = _relocationReferences.find(sectionName);
if (rri != _relocationReferences.end())
- createRelocationReferences(*symbol, symContent, secContent, rri->second);
+ createRelocationReferences(symbol, symContent, secContent, rri->second);
// Create the DefinedAtom and add it to the list of DefinedAtoms.
return *handleDefinedSymbol(symbolName, sectionName, symbol, section,
}
template <class ELFT>
-void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym &symbol,
+void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> content,
range<Elf_Rela_Iter> rels) {
bool isMips64EL = _objFile->isMips64EL();
- const auto symValue = getSymbolValue(&symbol);
+ const auto symValue = getSymbolValue(symbol);
for (const auto &rel : rels) {
if (rel.r_offset < symValue ||
symValue + content.size() <= rel.r_offset)
continue;
_references.push_back(new (_readerStorage) ELFReference<ELFT>(
- &rel, rel.r_offset - symValue, kindArch(),
+ symbol, &rel, rel.r_offset - symValue, kindArch(),
rel.getType(isMips64EL), rel.getSymbol(isMips64EL)));
}
}
template <class ELFT>
-void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym &symbol,
+void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
range<Elf_Rel_Iter> rels) {
bool isMips64EL = _objFile->isMips64EL();
- const auto symValue = getSymbolValue(&symbol);
+ const auto symValue = getSymbolValue(symbol);
for (const auto &rel : rels) {
if (rel.r_offset < symValue ||
symValue + symContent.size() <= rel.r_offset)
continue;
_references.push_back(new (_readerStorage) ELFReference<ELFT>(
- rel.r_offset - symValue, kindArch(),
- rel.getType(isMips64EL), rel.getSymbol(isMips64EL)));
+ symbol, rel.r_offset - symValue, kindArch(), rel.getType(isMips64EL),
+ rel.getSymbol(isMips64EL)));
int32_t addend = *(symContent.data() + rel.r_offset - symValue);
_references.back()->setAddend(addend);
}
return std::error_code();
}
- void createRelocationReferences(const Elf_Sym &symbol,
+ void createRelocationReferences(const Elf_Sym *symbol,
ArrayRef<uint8_t> symContent,
ArrayRef<uint8_t> secContent,
range<Elf_Rel_Iter> rels) override {
for (Elf_Rel_Iter rit = rels.begin(), eit = rels.end(); rit != eit; ++rit) {
- if (rit->r_offset < symbol.st_value ||
- symbol.st_value + symContent.size() <= rit->r_offset)
+ if (rit->r_offset < symbol->st_value ||
+ symbol->st_value + symContent.size() <= rit->r_offset)
continue;
this->_references.push_back(new (this->_readerStorage) ELFReference<ELFT>(
- rit->r_offset - symbol.st_value, this->kindArch(),
+ symbol, rit->r_offset - symbol->st_value, this->kindArch(),
rit->getType(isMips64EL()), rit->getSymbol(isMips64EL())));
auto addend = getAddend(*rit, secContent);