[lld] r347781 - Simplify Symbol::getPltVA.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 28 09:43:01 PST 2018


Author: ruiu
Date: Wed Nov 28 09:42:59 2018
New Revision: 347781

URL: http://llvm.org/viewvc/llvm-project?rev=347781&view=rev
Log:
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

Modified:
    lld/trunk/ELF/Arch/X86_64.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Target.h

Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Wed Nov 28 09:42:59 2018
@@ -592,7 +592,7 @@ void Retpoline<ELFT>::writePlt(uint8_t *
   };
   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
   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() {

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Nov 28 09:42:59 2018
@@ -943,7 +943,7 @@ static void processRelocAux(InputSection
     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;

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Nov 28 09:42:59 2018
@@ -144,17 +144,8 @@ uint64_t Symbol::getPPC64LongBranchOffse
 }
 
 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 {

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Nov 28 09:42:59 2018
@@ -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;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Wed Nov 28 09:42:59 2018
@@ -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;
 };
 

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=347781&r1=347780&r2=347781&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Nov 28 09:42:59 2018
@@ -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(uint
               ", " + 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))




More information about the llvm-commits mailing list