From f4415a3d77058f2714b2110276a8f40f77cca12d Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 20 Oct 2016 17:53:55 +0000 Subject: [PATCH] [ELF][MIPS] Separate calculation of MIPS GOT index and offset of the corresponding part of the GOT. NFC 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 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 360d652..91b89aa 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -244,19 +244,24 @@ GotSection::getMipsLocalPageOffset(uintX_t EntryValue) { template typename GotSection::uintX_t GotSection::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 -- 2.7.4