Index: ELF/Arch/MipsArchTree.cpp =================================================================== --- ELF/Arch/MipsArchTree.cpp +++ ELF/Arch/MipsArchTree.cpp @@ -283,8 +283,10 @@ template uint32_t elf::getMipsEFlags() { std::vector V; - for (ObjFile *F : ObjFile::Instances) + for (InputFile *Obj : ObjFiles) { + ObjFile *F = cast>(Obj); V.push_back({F->getName(), F->getObj().getHeader()->e_flags}); + } if (V.empty()) return 0; checkFlags(V); Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1031,7 +1031,7 @@ // Now that we have a complete list of input files. // Beyond this point, no new files are added. // Aggregate all input sections into one place. - for (ObjFile *F : ObjFile::Instances) + for (InputFile *F : ObjFiles) for (InputSectionBase *S : F->getSections()) if (S && S != &InputSection::Discarded) InputSections.push_back(S); Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -155,8 +155,6 @@ return F->kind() == Base::ObjectKind; } - static std::vector *> Instances; - ArrayRef getSymbols(); ArrayRef getLocalSymbols(); @@ -218,8 +216,6 @@ llvm::once_flag InitDwarfLine; }; -template std::vector *> ObjFile::Instances; - // LazyObjFile is analogous to ArchiveFile in the sense that // the file contains lazy symbols. The difference is that // LazyObjFile wraps a single file instead of multiple files. @@ -352,6 +348,9 @@ uint64_t OffsetInArchive = 0); InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName); +// The list of all ObjFile instances. +extern std::vector ObjFiles; + } // namespace elf } // namespace lld Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -35,6 +35,8 @@ using namespace lld; using namespace lld::elf; +std::vector elf::ObjFiles; + TarWriter *elf::Tar; InputFile::InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {} Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -51,12 +51,14 @@ // Returns a list of all symbols that we want to print out. template std::vector getSymbols() { std::vector V; - for (ObjFile *File : ObjFile::Instances) + for (InputFile *Obj : ObjFiles) { + ObjFile *File = cast>(Obj); for (SymbolBody *B : File->getSymbols()) if (B->File == File && !B->isSection()) if (auto *Sym = dyn_cast(B)) if (Sym->Section && Sym->Section->Live) V.push_back(Sym); + } return V; } Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -101,9 +101,8 @@ } // Regular object file - auto *F = cast>(File); - ObjFile::Instances.push_back(F); - F->parse(ComdatGroups); + ObjFiles.push_back(File); + cast>(File)->parse(ComdatGroups); } // This function is where all the optimizations of link-time @@ -126,7 +125,7 @@ ObjFile *Obj = cast>(File); DenseSet DummyGroups; Obj->parse(DummyGroups); - ObjFile::Instances.push_back(Obj); + ObjFiles.push_back(Obj); } } Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -471,7 +471,8 @@ template void Writer::copyLocalSymbols() { if (!InX::SymTab) return; - for (ObjFile *F : ObjFile::Instances) { + for (InputFile *Obj : ObjFiles) { + ObjFile *F = cast>(Obj); for (SymbolBody *B : F->getLocalSymbols()) { if (!B->IsLocal) fatal(toString(F) + @@ -893,7 +894,8 @@ // Build a map from sections to their priorities. DenseMap SectionOrder; - for (ObjFile *File : ObjFile::Instances) { + for (InputFile *Obj : ObjFiles) { + ObjFile *File = cast>(Obj); for (SymbolBody *Body : File->getSymbols()) { auto *D = dyn_cast(Body); if (!D || !D->Section)