From d2e0ed7755671039f75f90803793d44e93b3ef56 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 22 Mar 2019 21:17:25 +0000 Subject: [PATCH] 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. llvm-svn: 356812 --- lld/ELF/SyntheticSections.cpp | 29 ++++++++++------------------- lld/ELF/SyntheticSections.h | 4 +--- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 1825424..5235939 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1567,10 +1567,6 @@ template void RelocationSection::writeTo(uint8_t *Buf) { } } -template unsigned RelocationSection::getRelocOffset() { - return this->Entsize * Relocs.size(); -} - template AndroidPackedRelocationSection::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 void PltSection::addEntry(Symbol &Sym) { Sym.PltIndex = Entries.size(); - RelocationBaseSection *PltRelocSection = In.RelaPlt; - if (IsIplt) - PltRelocSection = In.RelaIplt; - unsigned RelOff = - static_cast *>(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; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 11dae79..c8dda46 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -497,7 +497,6 @@ class RelocationSection final : public RelocationBaseSection { 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> Entries; + std::vector Entries; bool IsIplt; }; -- 2.7.4