diff options
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 29 | ||||
-rw-r--r-- | 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 18254245061..52359397371 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1567,10 +1567,6 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { } } -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; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 11dae7933d0..c8dda4621d3 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<std::pair<const Symbol *, unsigned>> Entries; + std::vector<const Symbol *> Entries; bool IsIplt; }; |