summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2014-03-09 13:19:29 +0000
committerSimon Atanasyan <simon@atanasyan.com>2014-03-09 13:19:29 +0000
commit3af86648587d6bcc8b04a7a53b908c9507f3f388 (patch)
treea75c73773337a83969820c08dcf606a99feaa95f
parent305c864756d38046db6a76d498ee2b933e0e47ae (diff)
downloadbcm5719-llvm-3af86648587d6bcc8b04a7a53b908c9507f3f388.tar.gz
bcm5719-llvm-3af86648587d6bcc8b04a7a53b908c9507f3f388.zip
[ELF] Factor out the code creates a Reference for the specified symbol
and relocation entry into the two virtual functions. llvm-svn: 203408
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFFile.h61
1 files changed, 38 insertions, 23 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h
index 8f56a310f27..a15d0c629b3 100644
--- a/lld/lib/ReaderWriter/ELF/ELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/ELFFile.h
@@ -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));
}
}
@@ -786,6 +779,28 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::createDefinedAtomAndAssignRelocations(
}
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;
}
OpenPOWER on IntegriCloud