diff options
author | Rui Ueyama <ruiu@google.com> | 2018-11-28 17:42:59 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2018-11-28 17:42:59 +0000 |
commit | 63d397ea6ec4eb239374af152f97ed1f053d22af (patch) | |
tree | e447358cdc1137d0692918457e907ae9b81d7671 | |
parent | 4eacdb41e98168d44af610805f4f0068a90d1e47 (diff) | |
download | bcm5719-llvm-63d397ea6ec4eb239374af152f97ed1f053d22af.tar.gz bcm5719-llvm-63d397ea6ec4eb239374af152f97ed1f053d22af.zip |
Simplify Symbol::getPltVA.
This patch also makes getPltEntryOffset a non-member function because
it doesn't depend on any private members of the TargetInfo class.
I tried a few different ideas, and it seems this change fits in best to me.
Differential Revision: https://reviews.llvm.org/D54981
llvm-svn: 347781
-rw-r--r-- | lld/ELF/Arch/X86_64.cpp | 4 | ||||
-rw-r--r-- | lld/ELF/Relocations.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Symbols.cpp | 13 | ||||
-rw-r--r-- | lld/ELF/Symbols.h | 1 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.h | 4 | ||||
-rw-r--r-- | lld/ELF/Target.h | 8 |
6 files changed, 11 insertions, 21 deletions
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp index 9b86f228d70..06314155dcc 100644 --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -592,7 +592,7 @@ void Retpoline<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, }; memcpy(Buf, Insn, sizeof(Insn)); - uint64_t Off = TargetInfo::getPltEntryOffset(Index); + uint64_t Off = getPltEntryOffset(Index); write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7); write32le(Buf + 8, -Off - 12 + 32); @@ -635,7 +635,7 @@ void RetpolineZNow<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, memcpy(Buf, Insn, sizeof(Insn)); write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7); - write32le(Buf + 8, -TargetInfo::getPltEntryOffset(Index) - 12); + write32le(Buf + 8, -getPltEntryOffset(Index) - 12); } template <class ELFT> static TargetInfo *getTargetInfo() { diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index d7850c4ce51..c75ae4f823f 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -943,7 +943,7 @@ static void processRelocAux(InputSectionBase &Sec, RelExpr Expr, RelType Type, if (!Sym.isInPlt()) addPltEntry<ELFT>(In.Plt, In.GotPlt, In.RelaPlt, Target->PltRel, Sym); if (!Sym.isDefined()) - replaceWithDefined(Sym, In.Plt, Sym.getPltOffset(), 0); + replaceWithDefined(Sym, In.Plt, getPltEntryOffset(Sym.PltIndex), 0); Sym.NeedsPltAddr = true; Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym}); return; diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 80a3b4669f3..da7fdb5dc43 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -144,17 +144,8 @@ uint64_t Symbol::getPPC64LongBranchOffset() const { } uint64_t Symbol::getPltVA() const { - if (this->IsInIplt) { - if (Config->ZRetpolineplt) - return In.Iplt->getVA() + Target->getPltEntryOffset(PltIndex); - return In.Iplt->getVA() + PltIndex * Target->PltEntrySize; - } - return In.Plt->getVA() + Target->getPltEntryOffset(PltIndex); -} - -uint64_t Symbol::getPltOffset() const { - assert(!this->IsInIplt); - return Target->getPltEntryOffset(PltIndex); + PltSection *Plt = IsInIplt ? In.Iplt : In.Plt; + return Plt->getVA() + Plt->HeaderSize + PltIndex * Target->PltEntrySize; } uint64_t Symbol::getPPC64LongBranchTableVA() const { diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 26a80ace74f..803cb80dd85 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -172,7 +172,6 @@ public: uint64_t getGotPltOffset() const; uint64_t getGotPltVA() const; uint64_t getPltVA() const; - uint64_t getPltOffset() const; uint64_t getPPC64LongBranchTableVA() const; uint64_t getPPC64LongBranchOffset() const; uint64_t getSize() const; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 3458bdfee74..63d7897e12a 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -659,13 +659,13 @@ public: size_t getSize() const override; bool empty() const override { return Entries.empty(); } void addSymbols(); - template <class ELFT> void addEntry(Symbol &Sym); + size_t HeaderSize; + private: unsigned getPltRelocOff() const; std::vector<std::pair<const Symbol *, unsigned>> Entries; - size_t HeaderSize; bool IsIplt; }; diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index f93208e9b22..e7a31e76327 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -45,10 +45,6 @@ public: virtual void addPltHeaderSymbols(InputSection &IS) const {} virtual void addPltSymbols(InputSection &IS, uint64_t Off) const {} - unsigned getPltEntryOffset(unsigned Index) const { - return Index * PltEntrySize + PltHeaderSize; - } - // Returns true if a relocation only uses the low bits of a value such that // all those bits are in the same page. For example, if the relocation // only uses the low 12 bits in a system with 4k pages. If this is true, the @@ -201,6 +197,10 @@ static inline void reportRangeError(uint8_t *Loc, RelType Type, const Twine &V, ", " + Twine(Max).str() + "]" + Hint); } +inline unsigned getPltEntryOffset(unsigned Idx) { + return Target->PltHeaderSize + Target->PltEntrySize * Idx; +} + // Make sure that V can be represented as an N bit signed integer. inline void checkInt(uint8_t *Loc, int64_t V, int N, RelType Type) { if (V != llvm::SignExtend64(V, N)) |