[PATCH] D41681: Centralize Config->IsRela handling
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 17:16:42 PST 2018
espindola updated this revision to Diff 128585.
espindola added a comment.
Avoid changes to DynamicReloc.
https://reviews.llvm.org/D41681
Files:
ELF/Relocations.cpp
ELF/SyntheticSections.cpp
ELF/SyntheticSections.h
Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -361,6 +361,9 @@
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; }
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1202,6 +1202,19 @@
: 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;
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -837,16 +837,8 @@
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
@@ -1027,15 +1019,8 @@
// 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);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41681.128585.patch
Type: text/x-patch
Size: 3471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180104/32af3014/attachment.bin>
More information about the llvm-commits
mailing list