[lld] r356812 - Simplify PltSection.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 22 14:17:25 PDT 2019


Author: ruiu
Date: Fri Mar 22 14:17:25 2019
New Revision: 356812

URL: http://llvm.org/viewvc/llvm-project?rev=356812&view=rev
Log:
Simplify PltSection.

Previously, `Entries` contains pairs of symbols and their indices.
The indices are always 0, x, 2x, 3x, ..., where x is the size of
relocation entry. We didn't have to store that values because we can
compute them when we consume them.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=356812&r1=356811&r2=356812&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Mar 22 14:17:25 2019
@@ -1567,10 +1567,6 @@ template <class ELFT> void RelocationSec
   }
 }
 
-template <class ELFT> unsigned RelocationSection<ELFT>::getRelocOffset() {
-  return this->Entsize * Relocs.size();
-}
-
 template <class ELFT>
 AndroidPackedRelocationSection<ELFT>::AndroidPackedRelocationSection(
     StringRef Name)
@@ -2329,15 +2325,18 @@ PltSection::PltSection(bool IsIplt)
 void PltSection::writeTo(uint8_t *Buf) {
   // At beginning of PLT or retpoline IPLT, we have code to call the dynamic
   // linker to resolve dynsyms at runtime. Write such code.
-  if (HeaderSize > 0)
+  if (HeaderSize)
     Target->writePltHeader(Buf);
   size_t Off = HeaderSize;
+
+  RelocationBaseSection *RelSec = IsIplt ? In.RelaIplt : In.RelaPlt;
+
   // The IPlt is immediately after the Plt, account for this in RelOff
-  unsigned PltOff = getPltRelocOff();
+  size_t PltOff = IsIplt ? In.Plt->getSize() : 0;
 
-  for (auto &I : Entries) {
-    const Symbol *B = I.first;
-    unsigned RelOff = I.second + PltOff;
+  for (size_t I = 0, E = Entries.size(); I != E; ++I) {
+    const Symbol *B = Entries[I];
+    unsigned RelOff = RelSec->Entsize * I + PltOff;
     uint64_t Got = B->getGotPltVA();
     uint64_t Plt = this->getVA() + Off;
     Target->writePlt(Buf + Off, Got, Plt, B->PltIndex, RelOff);
@@ -2347,12 +2346,7 @@ void PltSection::writeTo(uint8_t *Buf) {
 
 template <class ELFT> void PltSection::addEntry(Symbol &Sym) {
   Sym.PltIndex = Entries.size();
-  RelocationBaseSection *PltRelocSection = In.RelaPlt;
-  if (IsIplt)
-    PltRelocSection = In.RelaIplt;
-  unsigned RelOff =
-      static_cast<RelocationSection<ELFT> *>(PltRelocSection)->getRelocOffset();
-  Entries.push_back(std::make_pair(&Sym, RelOff));
+  Entries.push_back(&Sym);
 }
 
 size_t PltSection::getSize() const {
@@ -2365,6 +2359,7 @@ void PltSection::addSymbols() {
   // The PLT may have symbols defined for the Header, the IPLT has no header
   if (!IsIplt)
     Target->addPltHeaderSymbols(*this);
+
   size_t Off = HeaderSize;
   for (size_t I = 0; I < Entries.size(); ++I) {
     Target->addPltSymbols(*this, Off);
@@ -2372,10 +2367,6 @@ void PltSection::addSymbols() {
   }
 }
 
-unsigned PltSection::getPltRelocOff() const {
-  return IsIplt ? In.Plt->getSize() : 0;
-}
-
 // The string hash function for .gdb_index.
 static uint32_t computeGdbHash(StringRef S) {
   uint32_t H = 0;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=356812&r1=356811&r2=356812&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Fri Mar 22 14:17:25 2019
@@ -497,7 +497,6 @@ class RelocationSection final : public R
 
 public:
   RelocationSection(StringRef Name, bool Sort);
-  unsigned getRelocOffset();
   void writeTo(uint8_t *Buf) override;
 
 private:
@@ -663,8 +662,7 @@ public:
   size_t HeaderSize;
 
 private:
-  unsigned getPltRelocOff() const;
-  std::vector<std::pair<const Symbol *, unsigned>> Entries;
+  std::vector<const Symbol *> Entries;
   bool IsIplt;
 };
 




More information about the llvm-commits mailing list