[ELF][MIPS] Separate calculation of MIPS GOT index and offset of the corresponding...
authorSimon Atanasyan <simon@atanasyan.com>
Thu, 20 Oct 2016 17:53:55 +0000 (17:53 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Thu, 20 Oct 2016 17:53:55 +0000 (17:53 +0000)
MIPS GOT consists of some parts: local, global, TLS entries. This change
separates calculation of MIPS GOT index and offset of the corresponding
part of the GOT. That makes code a bit clear and allow to extend number
of parts in the future.

llvm-svn: 284750

lld/ELF/OutputSections.cpp

index 360d652..91b89aa 100644 (file)
@@ -244,19 +244,24 @@ GotSection<ELFT>::getMipsLocalPageOffset(uintX_t EntryValue) {
 template <class ELFT>
 typename GotSection<ELFT>::uintX_t
 GotSection<ELFT>::getMipsGotOffset(const SymbolBody &B, uintX_t Addend) const {
-  uintX_t Off = MipsPageEntries;
+  // Calculate offset of the GOT entries block: TLS, global, local.
+  uintX_t GotBlockOff;
   if (B.isTls())
-    Off += MipsLocal.size() + MipsGlobal.size() + B.GotIndex;
+    GotBlockOff = getMipsTlsOffset();
   else if (B.IsInGlobalMipsGot)
-    Off += MipsLocal.size() + B.GotIndex;
-  else if (B.isInGot())
-    Off += B.GotIndex;
+    GotBlockOff = getMipsLocalEntriesNum() * sizeof(uintX_t);
+  else
+    GotBlockOff = MipsPageEntries * sizeof(uintX_t);
+  // Calculate index of the GOT entry in the block.
+  uintX_t GotIndex;
+  if (B.isInGot())
+    GotIndex = B.GotIndex;
   else {
     auto It = MipsGotMap.find({&B, Addend});
     assert(It != MipsGotMap.end());
-    Off += It->second;
+    GotIndex = It->second;
   }
-  return Off * sizeof(uintX_t) - MipsGPOffset;
+  return GotBlockOff + GotIndex * sizeof(uintX_t) - MipsGPOffset;
 }
 
 template <class ELFT>