[lld] r321889 - Centralize Config->IsRela handling.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 5 12:08:39 PST 2018
Author: rafael
Date: Fri Jan 5 12:08:38 2018
New Revision: 321889
URL: http://llvm.org/viewvc/llvm-project?rev=321889&view=rev
Log:
Centralize Config->IsRela handling.
This merges the two places were we check Config->IsRela to decide how
to write a relocation addend.
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321889&r1=321888&r2=321889&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Jan 5 12:08:38 2018
@@ -832,16 +832,8 @@ template <class ELFT> static void addGot
Type = Target->RelativeRel;
else
Type = Target->GotRel;
- InX::RelaDyn->addReloc({Type, InX::Got, Off, !Preemptible, &Sym, 0});
-
- // REL type relocations don't have addend fields unlike RELAs, and
- // their addends are stored to the section to which they are applied.
- // So, store addends if we need to.
- //
- // This is ugly -- the difference between REL and RELA should be
- // handled in a better way. It's a TODO.
- if (!Config->IsRela && !Preemptible)
- InX::Got->Relocations.push_back({R_ABS, Target->GotRel, Off, 0, &Sym});
+ InX::RelaDyn->addReloc(Type, InX::Got, Off, !Preemptible, &Sym, 0, R_ABS,
+ Target->GotRel);
}
// The reason we have to do this early scan is as follows
@@ -1022,15 +1014,8 @@ static void scanRelocs(InputSectionBase
// dynamic linker. We can however do better than just copying the incoming
// relocation. We can process some of it and and just ask the dynamic
// linker to add the load address.
- if (Config->IsRela) {
- InX::RelaDyn->addReloc(
- {Target->RelativeRel, &Sec, Offset, true, &Sym, Addend});
- } else {
- // In REL, addends are stored to the target section.
- InX::RelaDyn->addReloc(
- {Target->RelativeRel, &Sec, Offset, true, &Sym, 0});
- Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});
- }
+ InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, true, &Sym,
+ Addend, Expr, Type);
}
}
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=321889&r1=321888&r2=321889&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Jan 5 12:08:38 2018
@@ -1202,6 +1202,19 @@ RelocationBaseSection::RelocationBaseSec
: SyntheticSection(SHF_ALLOC, Type, Config->Wordsize, Name),
DynamicTag(DynamicTag), SizeDynamicTag(SizeDynamicTag) {}
+void RelocationBaseSection::addReloc(uint32_t DynType,
+ InputSectionBase *InputSec,
+ uint64_t OffsetInSec, bool UseSymVA,
+ Symbol *Sym, int64_t Addend, RelExpr Expr,
+ RelType Type) {
+ // REL type relocations don't have addend fields unlike RELAs, and
+ // their addends are stored to the section to which they are applied.
+ // So, store addends if we need to.
+ if (!Config->IsRela && UseSymVA)
+ InputSec->Relocations.push_back({Expr, Type, OffsetInSec, Addend, Sym});
+ addReloc({DynType, InputSec, OffsetInSec, UseSymVA, Sym, Addend});
+}
+
void RelocationBaseSection::addReloc(const DynamicReloc &Reloc) {
if (Reloc.Type == Target->RelativeRel)
++NumRelativeRelocs;
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=321889&r1=321888&r2=321889&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri Jan 5 12:08:38 2018
@@ -361,6 +361,9 @@ class RelocationBaseSection : public Syn
public:
RelocationBaseSection(StringRef Name, uint32_t Type, int32_t DynamicTag,
int32_t SizeDynamicTag);
+ void addReloc(uint32_t DynType, InputSectionBase *InputSec,
+ uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym,
+ int64_t Addend, RelExpr Expr, RelType Type);
void addReloc(const DynamicReloc &Reloc);
bool empty() const override { return Relocs.empty(); }
size_t getSize() const override { return Relocs.size() * this->Entsize; }
More information about the llvm-commits
mailing list