[lld] r203408 - [ELF] Factor out the code creates a Reference for the specified symbol
Simon Atanasyan
simon at atanasyan.com
Sun Mar 9 06:19:30 PDT 2014
Author: atanasyan
Date: Sun Mar 9 08:19:29 2014
New Revision: 203408
URL: http://llvm.org/viewvc/llvm-project?rev=203408&view=rev
Log:
[ELF] Factor out the code creates a Reference for the specified symbol
and relocation entry into the two virtual functions.
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=203408&r1=203407&r2=203408&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Sun Mar 9 08:19:29 2014
@@ -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>::cre
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>::cre
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>::cre
}
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;
}
More information about the llvm-commits
mailing list