[lld] r288128 - [ELF][MIPS] Replace the magic number of GOT header entries by constant. NFC

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 29 02:23:50 PST 2016


Author: atanasyan
Date: Tue Nov 29 04:23:50 2016
New Revision: 288128

URL: http://llvm.org/viewvc/llvm-project?rev=288128&view=rev
Log:
[ELF][MIPS] Replace the magic number of GOT header entries by constant. NFC

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=288128&r1=288127&r2=288128&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Nov 29 04:23:50 2016
@@ -536,10 +536,10 @@ MipsGotSection<ELFT>::getPageEntryOffset
   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 <class ELFT>
@@ -547,25 +547,22 @@ typename MipsGotSection<ELFT>::uintX_t
 MipsGotSection<ELFT>::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 <class ELFT>
@@ -587,14 +584,15 @@ const SymbolBody *MipsGotSection<ELFT>::
 
 template <class ELFT>
 unsigned MipsGotSection<ELFT>::getLocalEntriesNum() const {
-  return PageEntriesNum + LocalEntries.size() + LocalEntries32.size();
+  return HeaderEntriesNum + PageEntriesNum + LocalEntries.size() +
+         LocalEntries32.size();
 }
 
 template <class ELFT> void MipsGotSection<ELFT>::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 <class ELFT> void MipsGotSectio
   // if we had to do this.
   auto *P = reinterpret_cast<typename ELFT::Off *>(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<uintX_t, size_t> &L : PageIndexMap) {
     uint8_t *Entry = Buf + L.second * sizeof(uintX_t);

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=288128&r1=288127&r2=288128&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Tue Nov 29 04:23:50 2016
@@ -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<const OutputSectionBase *, 10> OutSections;




More information about the llvm-commits mailing list