[lld] r250731 - Change getLocalRelTarget to include the addend.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 13:24:44 PDT 2015
Author: rafael
Date: Mon Oct 19 15:24:44 2015
New Revision: 250731
URL: http://llvm.org/viewvc/llvm-project?rev=250731&view=rev
Log:
Change getLocalRelTarget to include the addend.
Given the name, it is natural for this function to compute the full target.
This will simplify SHF_MERGE handling by allowing getLocalRelTarget to
centralize the addend logic.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=250731&r1=250730&r2=250731&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Oct 19 15:24:44 2015
@@ -26,22 +26,6 @@ InputSection<ELFT>::InputSection(ObjectF
: File(F), Header(Header) {}
template <class ELFT>
-void InputSection<ELFT>::relocateOne(uint8_t *Buf, uint8_t *BufEnd,
- const Elf_Rel &Rel, uint32_t Type,
- uintX_t BaseAddr, uintX_t SymVA) {
- Target->relocateOne(Buf, BufEnd, reinterpret_cast<const void *>(&Rel), Type,
- BaseAddr, SymVA);
-}
-
-template <class ELFT>
-void InputSection<ELFT>::relocateOne(uint8_t *Buf, uint8_t *BufEnd,
- const Elf_Rela &Rel, uint32_t Type,
- uintX_t BaseAddr, uintX_t SymVA) {
- Target->relocateOne(Buf, BufEnd, reinterpret_cast<const void *>(&Rel), Type,
- BaseAddr, SymVA + Rel.r_addend);
-}
-
-template <class ELFT>
template <bool isRela>
void InputSection<ELFT>::relocate(
uint8_t *Buf, uint8_t *BufEnd,
@@ -57,7 +41,7 @@ void InputSection<ELFT>::relocate(
const Elf_Shdr *SymTab = File.getSymbolTable();
if (SymIndex < SymTab->sh_info) {
uintX_t SymVA = getLocalRelTarget(File, RI);
- relocateOne(Buf, BufEnd, RI, Type, BaseAddr, SymVA);
+ Target->relocateOne(Buf, BufEnd, &RI, Type, BaseAddr, SymVA);
continue;
}
@@ -75,7 +59,8 @@ void InputSection<ELFT>::relocate(
} else if (isa<SharedSymbol<ELFT>>(Body)) {
continue;
}
- relocateOne(Buf, BufEnd, RI, Type, BaseAddr, SymVA);
+ Target->relocateOne(Buf, BufEnd, &RI, Type, BaseAddr,
+ SymVA + getAddend<ELFT>(RI));
}
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=250731&r1=250730&r2=250731&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Mon Oct 19 15:24:44 2015
@@ -60,12 +60,6 @@ public:
static InputSection<ELFT> Discarded;
private:
- static void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const Elf_Rel &Rel,
- uint32_t Type, uintX_t BaseAddr, uintX_t SymVA);
-
- static void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const Elf_Rela &Rel,
- uint32_t Type, uintX_t BaseAddr, uintX_t SymVA);
-
template <bool isRela>
void relocate(uint8_t *Buf, uint8_t *BufEnd,
llvm::iterator_range<
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250731&r1=250730&r2=250731&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Oct 19 15:24:44 2015
@@ -135,15 +135,20 @@ template <class ELFT> void RelocationSec
else
P->r_offset = RI.r_offset + C.OutSec->getVA() + C.OutSecOff;
- uintX_t Addend = 0;
+ uintX_t OrigAddend = 0;
if (IsRela && !NeedsGot)
- Addend = static_cast<const Elf_Rela &>(RI).r_addend;
+ OrigAddend = static_cast<const Elf_Rela &>(RI).r_addend;
- if (!CanBePreempted) {
+ uintX_t Addend;
+ if (CanBePreempted) {
+ Addend = OrigAddend;
+ } else {
if (Body)
- Addend += getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body));
+ Addend = getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body)) + OrigAddend;
+ else if (IsRela)
+ Addend = getLocalRelTarget(File, static_cast<const Elf_Rela &>(RI));
else
- Addend += getLocalRelTarget(File, RI);
+ Addend = getLocalRelTarget(File, RI);
}
if (IsRela)
@@ -422,16 +427,20 @@ typename ELFFile<ELFT>::uintX_t lld::elf
// Returns a VA which a relocatin RI refers to. Used only for local symbols.
// For non-local symbols, use getSymVA instead.
-template <class ELFT>
+template <class ELFT, bool IsRela>
typename ELFFile<ELFT>::uintX_t
lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File,
- const typename ELFFile<ELFT>::Elf_Rel &RI) {
+ const Elf_Rel_Impl<ELFT, IsRela> &RI) {
+ typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
+ typedef typename ELFFile<ELFT>::uintX_t uintX_t;
+
+ uintX_t Addend = getAddend<ELFT>(RI);
+
// PPC64 has a special relocation representing the TOC base pointer
// that does not have a corresponding symbol.
if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC)
- return getPPC64TocBase();
+ return getPPC64TocBase() + Addend;
- typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
const Elf_Sym *Sym =
File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
@@ -444,9 +453,9 @@ lld::elf2::getLocalRelTarget(const Objec
// 0.
InputSection<ELFT> *Section = File.getSection(*Sym);
if (Section == &InputSection<ELFT>::Discarded)
- return 0;
+ return Addend;
- return Section->OutSec->getVA() + Section->OutSecOff + Sym->st_value;
+ return Section->OutSec->getVA() + Section->OutSecOff + Sym->st_value + Addend;
}
// Returns true if a symbol can be replaced at load-time by a symbol
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250731&r1=250730&r2=250731&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Mon Oct 19 15:24:44 2015
@@ -33,12 +33,24 @@ template <class ELFT> class DefinedRegul
template <class ELFT> class ELFSymbolBody;
template <class ELFT>
-typename llvm::object::ELFFile<ELFT>::uintX_t getSymVA(const SymbolBody &S);
+static inline typename llvm::object::ELFFile<ELFT>::uintX_t
+getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Rel) {
+ return 0;
+}
+
+template <class ELFT>
+static inline typename llvm::object::ELFFile<ELFT>::uintX_t
+getAddend(const typename llvm::object::ELFFile<ELFT>::Elf_Rela &Rel) {
+ return Rel.r_addend;
+}
template <class ELFT>
+typename llvm::object::ELFFile<ELFT>::uintX_t getSymVA(const SymbolBody &S);
+
+template <class ELFT, bool IsRela>
typename llvm::object::ELFFile<ELFT>::uintX_t
getLocalRelTarget(const ObjectFile<ELFT> &File,
- const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Sym);
+ const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel);
bool canBePreempted(const SymbolBody *Body, bool NeedsGot);
template <class ELFT> bool includeInSymtab(const SymbolBody &B);
More information about the llvm-commits
mailing list