From a0efc4268c99a2bfe498cf5645d66401a8d2f834 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Tue, 29 Nov 2016 10:23:50 +0000 Subject: [PATCH] [ELF][MIPS] Replace the magic number of GOT header entries by constant. NFC llvm-svn: 288128 --- lld/ELF/SyntheticSections.cpp | 31 +++++++++++++++---------------- lld/ELF/SyntheticSections.h | 4 +++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index bb43a5b..91d721a 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -536,10 +536,10 @@ MipsGotSection::getPageEntryOffset(uintX_t EntryValue) { EntryValue = (EntryValue + 0x8000) & ~0xffff; // Take into account MIPS GOT header. // See comment in the MipsGotSection::writeTo. - size_t NewIndex = PageIndexMap.size() + 2; + size_t NewIndex = PageIndexMap.size(); auto P = PageIndexMap.insert(std::make_pair(EntryValue, NewIndex)); - assert(!P.second || PageIndexMap.size() <= (PageEntriesNum - 2)); - return (uintX_t)P.first->second * sizeof(uintX_t); + assert(!P.second || PageIndexMap.size() <= PageEntriesNum); + return (HeaderEntriesNum + P.first->second) * sizeof(uintX_t); } template @@ -547,25 +547,22 @@ typename MipsGotSection::uintX_t MipsGotSection::getBodyEntryOffset(const SymbolBody &B, uintX_t Addend) const { // Calculate offset of the GOT entries block: TLS, global, local. - uintX_t GotBlockOff; + uintX_t Index = HeaderEntriesNum + PageEntriesNum; if (B.isTls()) - GotBlockOff = getTlsOffset(); + Index += LocalEntries.size() + LocalEntries32.size() + GlobalEntries.size(); else if (B.IsInGlobalMipsGot) - GotBlockOff = getLocalEntriesNum() * sizeof(uintX_t); + Index += LocalEntries.size() + LocalEntries32.size(); else if (B.Is32BitMipsGot) - GotBlockOff = (PageEntriesNum + LocalEntries.size()) * sizeof(uintX_t); - else - GotBlockOff = PageEntriesNum * sizeof(uintX_t); - // Calculate index of the GOT entry in the block. - uintX_t GotIndex; + Index += LocalEntries.size(); + // Calculate offset of the GOT entry in the block. if (B.isInGot()) - GotIndex = B.GotIndex; + Index += B.GotIndex; else { auto It = EntryIndexMap.find({&B, Addend}); assert(It != EntryIndexMap.end()); - GotIndex = It->second; + Index += It->second; } - return GotBlockOff + GotIndex * sizeof(uintX_t); + return Index * sizeof(uintX_t); } template @@ -587,14 +584,15 @@ const SymbolBody *MipsGotSection::getFirstGlobalEntry() const { template unsigned MipsGotSection::getLocalEntriesNum() const { - return PageEntriesNum + LocalEntries.size() + LocalEntries32.size(); + return HeaderEntriesNum + PageEntriesNum + LocalEntries.size() + + LocalEntries32.size(); } template void MipsGotSection::finalize() { size_t EntriesNum = TlsEntries.size(); // Take into account MIPS GOT header. // See comment in the MipsGotSection::writeTo. - PageEntriesNum = 2; + PageEntriesNum = 0; for (const OutputSectionBase *OutSec : OutSections) { // Calculate an upper bound of MIPS GOT entries required to store page // addresses of local symbols. We assume the worst case - each 64kb @@ -640,6 +638,7 @@ template void MipsGotSection::writeTo(uint8_t *Buf) { // if we had to do this. auto *P = reinterpret_cast(Buf); P[1] = uintX_t(1) << (ELFT::Is64Bits ? 63 : 31); + Buf += HeaderEntriesNum * sizeof(uintX_t); // Write 'page address' entries to the local part of the GOT. for (std::pair &L : PageIndexMap) { uint8_t *Entry = Buf + L.second * sizeof(uintX_t); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 52c08b8..e38f90c 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -164,7 +164,9 @@ private: // TLS entries: // Entries created by TLS relocations. - // Total number of allocated "Header" and "Page" entries. + // Number of "Header" entries. + static const unsigned HeaderEntriesNum = 2; + // Number of allocated "Page" entries. uint32_t PageEntriesNum = 0; // Output sections referenced by MIPS GOT relocations. llvm::SmallPtrSet OutSections; -- 2.7.4