Index: lld/trunk/ELF/InputSection.cpp =================================================================== --- lld/trunk/ELF/InputSection.cpp +++ lld/trunk/ELF/InputSection.cpp @@ -113,8 +113,7 @@ if (Target->isTlsLocalDynamicReloc(Type) && !Target->isTlsOptimized(Type, nullptr)) { Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, - Out::Got->getVA() + - Out::LocalModuleTlsIndexOffset + + Out::Got->getLocalTlsIndexVA() + getAddend(RI)); continue; } Index: lld/trunk/ELF/OutputSections.h =================================================================== --- lld/trunk/ELF/OutputSections.h +++ lld/trunk/ELF/OutputSections.h @@ -119,7 +119,7 @@ void writeTo(uint8_t *Buf) override; void addEntry(SymbolBody *Sym); void addDynTlsEntry(SymbolBody *Sym); - uint32_t addLocalModuleTlsIndex(); + bool addLocalModelTlsIndex(); bool empty() const { return Entries.empty(); } uintX_t getEntryAddr(const SymbolBody &B) const; @@ -133,8 +133,11 @@ // the number of reserved entries. This method is MIPS-specific. unsigned getMipsLocalEntriesNum() const; + uint32_t getLocalTlsIndexVA() { return getVA() + LocalTlsIndexOff; } + private: std::vector Entries; + uint32_t LocalTlsIndexOff = -1; }; template @@ -430,7 +433,6 @@ static SymbolTableSection *DynSymTab; static SymbolTableSection *SymTab; static Elf_Phdr *TlsPhdr; - static uint32_t LocalModuleTlsIndexOffset; }; template DynamicSection *Out::Dynamic; @@ -452,7 +454,6 @@ template SymbolTableSection *Out::DynSymTab; template SymbolTableSection *Out::SymTab; template typename Out::Elf_Phdr *Out::TlsPhdr; -template uint32_t Out::LocalModuleTlsIndexOffset = -1; } // namespace elf2 } // namespace lld Index: lld/trunk/ELF/OutputSections.cpp =================================================================== --- lld/trunk/ELF/OutputSections.cpp +++ lld/trunk/ELF/OutputSections.cpp @@ -87,10 +87,13 @@ Entries.push_back(nullptr); } -template uint32_t GotSection::addLocalModuleTlsIndex() { +template bool GotSection::addLocalModelTlsIndex() { + if (LocalTlsIndexOff != uint32_t(-1)) + return false; Entries.push_back(nullptr); Entries.push_back(nullptr); - return (Entries.size() - 2) * sizeof(uintX_t); + LocalTlsIndexOff = (Entries.size() - 2) * sizeof(uintX_t); + return true; } template @@ -201,8 +204,7 @@ Elf_Rel *N) { if (Target->isTlsLocalDynamicReloc(Type)) { P->setSymbolAndType(0, Target->getTlsModuleIndexReloc(), Config->Mips64EL); - P->r_offset = - Out::Got->getVA() + Out::LocalModuleTlsIndexOffset; + P->r_offset = Out::Got->getLocalTlsIndexVA(); return true; } Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -205,11 +205,8 @@ if (Target->isTlsLocalDynamicReloc(Type)) { if (Target->isTlsOptimized(Type, nullptr)) continue; - if (Out::LocalModuleTlsIndexOffset == uint32_t(-1)) { - Out::LocalModuleTlsIndexOffset = - Out::Got->addLocalModuleTlsIndex(); + if (Out::Got->addLocalModelTlsIndex()) Out::RelaDyn->addReloc({&C, &RI}); - } continue; }