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
This commit is contained in:
Rui Ueyama 2019-03-22 21:17:25 +00:00
parent 8316ea4299
commit d2e0ed7755
2 changed files with 12 additions and 23 deletions

View File

@ -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;
// The IPlt is immediately after the Plt, account for this in RelOff
unsigned PltOff = getPltRelocOff();
for (auto &I : Entries) {
const Symbol *B = I.first;
unsigned RelOff = I.second + PltOff;
RelocationBaseSection *RelSec = IsIplt ? In.RelaIplt : In.RelaPlt;
// The IPlt is immediately after the Plt, account for this in RelOff
size_t PltOff = IsIplt ? In.Plt->getSize() : 0;
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;

View File

@ -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;
};