Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -1506,9 +1506,8 @@ LTO->add(*File); for (InputFile *File : LTO->compile()) { - DenseMap DummyGroups; auto *Obj = cast>(File); - Obj->parse(DummyGroups); + Obj->parse(/*IgnoreComdats=*/true); for (Symbol *Sym : Obj->getGlobalSymbols()) Sym->parseSymbolVersion(); ObjectFiles.push_back(File); Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -201,8 +201,7 @@ this->ArchiveName = ArchiveName; } - void parse(llvm::DenseMap - &ComdatGroups); + void parse(bool IgnoreComdats = false); StringRef getShtGroupSignature(ArrayRef Sections, const Elf_Shdr &Sec); @@ -250,8 +249,7 @@ ArrayRef CGProfile; private: - void initializeSections(llvm::DenseMap &ComdatGroups); + void initializeSections(bool IgnoreComdats); void initializeSymbols(); void initializeJustSymbols(); void initializeDwarf(); @@ -340,9 +338,7 @@ BitcodeFile(MemoryBufferRef M, StringRef ArchiveName, uint64_t OffsetInArchive); static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } - template - void parse(llvm::DenseMap - &ComdatGroups); + template void parse(); std::unique_ptr Obj; }; Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -178,13 +178,13 @@ // LLVM bitcode file if (auto *F = dyn_cast(File)) { BitcodeFiles.push_back(F); - F->parse(Symtab->ComdatGroups); + F->parse(); return; } // Regular object file ObjectFiles.push_back(File); - cast>(File)->parse(Symtab->ComdatGroups); + cast>(File)->parse(); } // Add symbols in File to the symbol table. @@ -449,14 +449,12 @@ return makeArrayRef(this->Symbols).slice(this->FirstGlobal); } -template -void ObjFile::parse( - DenseMap &ComdatGroups) { +template void ObjFile::parse(bool IgnoreComdats) { // Read a section table. JustSymbols is usually false. if (this->JustSymbols) initializeJustSymbols(); else - initializeSections(ComdatGroups); + initializeSections(IgnoreComdats); // Read a symbol table. initializeSymbols(); @@ -564,8 +562,7 @@ } template -void ObjFile::initializeSections( - DenseMap &ComdatGroups) { +void ObjFile::initializeSections(bool IgnoreComdats) { const ELFFile &Obj = this->getObj(); ArrayRef ObjSections = CHECK(Obj.sections(), this); @@ -625,7 +622,9 @@ fatal(toString(this) + ": unsupported SHT_GROUP format"); bool IsNew = - ComdatGroups.try_emplace(CachedHashStringRef(Signature), this).second; + IgnoreComdats || + Symtab->ComdatGroups.try_emplace(CachedHashStringRef(Signature), this) + .second; if (IsNew) { if (Config->Relocatable) this->Sections[I] = createInputSection(Sec); @@ -1478,13 +1477,11 @@ return Symtab->addSymbol(New); } -template -void BitcodeFile::parse( - DenseMap &ComdatGroups) { +template void BitcodeFile::parse() { std::vector KeptComdats; for (StringRef S : Obj->getComdatTable()) KeptComdats.push_back( - ComdatGroups.try_emplace(CachedHashStringRef(S), this).second); + Symtab->ComdatGroups.try_emplace(CachedHashStringRef(S), this).second); for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, *this)); @@ -1617,14 +1614,10 @@ return Path; } -template void -BitcodeFile::parse(DenseMap &); -template void -BitcodeFile::parse(DenseMap &); -template void -BitcodeFile::parse(DenseMap &); -template void -BitcodeFile::parse(DenseMap &); +template void BitcodeFile::parse(); +template void BitcodeFile::parse(); +template void BitcodeFile::parse(); +template void BitcodeFile::parse(); template void LazyObjFile::parse(); template void LazyObjFile::parse(); Index: lld/trunk/wasm/InputFiles.cpp =================================================================== --- lld/trunk/wasm/InputFiles.cpp +++ lld/trunk/wasm/InputFiles.cpp @@ -306,11 +306,10 @@ TypeIsUsed.resize(getWasmObj()->types().size(), false); ArrayRef Comdats = WasmObj->linkingData().Comdats; - for (unsigned I = 0; I < Comdats.size(); ++I) - if (IgnoreComdats) - KeptComdats.push_back(true); - else - KeptComdats.push_back(Symtab->addComdat(Comdats[I])); + for (unsigned I = 0; I < Comdats.size(); ++I) { + bool IsNew = IgnoreComdats || Symtab->addComdat(Comdats[I]); + KeptComdats.push_back(IsNew); + } // Populate `Segments`. for (const WasmSegment &S : WasmObj->dataSegments()) @@ -535,10 +534,7 @@ } std::vector KeptComdats; for (StringRef S : Obj->getComdatTable()) - if (IgnoreComdats) - KeptComdats.push_back(true); - else - KeptComdats.push_back(Symtab->addComdat(S)); + KeptComdats.push_back(Symtab->addComdat(S)); for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, *this));