[ELF] Factor out the code creates a Reference for the specified symbol
and relocation entry into the two virtual functions. llvm-svn: 203408
This commit is contained in:
parent
305c864756
commit
3af8664858
|
@ -166,6 +166,16 @@ protected:
|
|||
StringRef symbolName, StringRef sectionName, const Elf_Sym *symbol,
|
||||
const Elf_Shdr *section, ArrayRef<uint8_t> content);
|
||||
|
||||
/// \brief Create a reference for the Elf_Sym symbol
|
||||
/// and Elf_Rela relocation entry.
|
||||
virtual ELFReference<ELFT> *createRelocationReference(const Elf_Sym &symbol,
|
||||
const Elf_Rela &rai);
|
||||
/// \brief Create a reference for the Elf_Sym symbol
|
||||
/// and Elf_Rel relocation entry.
|
||||
virtual ELFReference<ELFT> *
|
||||
createRelocationReference(const Elf_Sym &symbol, const Elf_Rel &ri,
|
||||
ArrayRef<uint8_t> content);
|
||||
|
||||
/// \brief After all the Atoms and References are created, update each
|
||||
/// Reference's target with the Atom pointer it refers to.
|
||||
virtual void updateReferences();
|
||||
|
@ -747,15 +757,9 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::createDefinedAtomAndAssignRelocations(
|
|||
auto rari = _relocationAddendReferences.find(sectionName);
|
||||
if (rari != _relocationAddendReferences.end()) {
|
||||
for (const Elf_Rela &rai : rari->second) {
|
||||
if (rai.r_offset < symbol->st_value ||
|
||||
symbol->st_value + content.size() <= rai.r_offset)
|
||||
continue;
|
||||
bool isMips64EL = _objFile->isMips64EL();
|
||||
uint32_t symbolIndex = rai.getSymbol(isMips64EL);
|
||||
auto *ERef = new (_readerStorage)
|
||||
ELFReference<ELFT>(&rai, rai.r_offset - symbol->st_value, kindArch(),
|
||||
rai.getType(isMips64EL), symbolIndex);
|
||||
_references.push_back(ERef);
|
||||
if (symbol->st_value <= rai.r_offset &&
|
||||
rai.r_offset < symbol->st_value + content.size())
|
||||
_references.push_back(createRelocationReference(*symbol, rai));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -763,20 +767,9 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::createDefinedAtomAndAssignRelocations(
|
|||
auto rri = _relocationReferences.find(sectionName);
|
||||
if (rri != _relocationReferences.end()) {
|
||||
for (const Elf_Rel &ri : rri->second) {
|
||||
if (ri.r_offset < symbol->st_value ||
|
||||
symbol->st_value + content.size() <= ri.r_offset)
|
||||
continue;
|
||||
bool isMips64EL = _objFile->isMips64EL();
|
||||
uint32_t symbolIndex = ri.getSymbol(isMips64EL);
|
||||
auto *ERef = new (_readerStorage)
|
||||
ELFReference<ELFT>(&ri, ri.r_offset - symbol->st_value, kindArch(),
|
||||
ri.getType(isMips64EL), symbolIndex);
|
||||
// Read the addend from the section contents
|
||||
// TODO : We should move the way lld reads relocations totally from
|
||||
// ELFFile
|
||||
int32_t addend = *(content.data() + ri.r_offset - symbol->st_value);
|
||||
ERef->setAddend(addend);
|
||||
_references.push_back(ERef);
|
||||
if (symbol->st_value <= ri.r_offset &&
|
||||
ri.r_offset < symbol->st_value + content.size())
|
||||
_references.push_back(createRelocationReference(*symbol, ri, content));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -785,6 +778,28 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::createDefinedAtomAndAssignRelocations(
|
|||
referenceStart, _references.size(), _references);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
ELFReference<ELFT> *
|
||||
ELFFile<ELFT>::createRelocationReference(const Elf_Sym &symbol,
|
||||
const Elf_Rela &rai) {
|
||||
bool isMips64EL = _objFile->isMips64EL();
|
||||
return new (_readerStorage)
|
||||
ELFReference<ELFT>(&rai, rai.r_offset - symbol.st_value, kindArch(),
|
||||
rai.getType(isMips64EL), rai.getSymbol(isMips64EL));
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
ELFReference<ELFT> *ELFFile<ELFT>::createRelocationReference(
|
||||
const Elf_Sym &symbol, const Elf_Rel &ri, ArrayRef<uint8_t> content) {
|
||||
bool isMips64EL = _objFile->isMips64EL();
|
||||
auto *ref = new (_readerStorage)
|
||||
ELFReference<ELFT>(&ri, ri.r_offset - symbol.st_value, kindArch(),
|
||||
ri.getType(isMips64EL), ri.getSymbol(isMips64EL));
|
||||
int32_t addend = *(content.data() + ri.r_offset - symbol.st_value);
|
||||
ref->setAddend(addend);
|
||||
return ref;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
int64_t ELFFile<ELFT>::defaultRelocAddend(const Reference &) const {
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue