Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -1295,7 +1295,7 @@ } // Force Sym to be entered in the output. Used for -u or equivalent. -template static void handleUndefined(StringRef Name) { +static void handleUndefined(StringRef Name) { Symbol *Sym = Symtab->find(Name); if (!Sym) return; @@ -1305,10 +1305,10 @@ Sym->IsUsedInRegularObj = true; if (Sym->isLazy()) - Symtab->fetchLazy(Sym); + Symtab->fetchLazy(Sym); } -template static void handleLibcall(StringRef Name) { +static void handleLibcall(StringRef Name) { Symbol *Sym = Symtab->find(Name); if (!Sym || !Sym->isLazy()) return; @@ -1320,7 +1320,7 @@ MB = cast(Sym)->getMemberBuffer(); if (isBitcode(MB)) - Symtab->fetchLazy(Sym); + Symtab->fetchLazy(Sym); } // Replaces common symbols with defined symbols reside in .bss sections. @@ -1426,7 +1426,7 @@ } template static Symbol *addUndefined(StringRef Name) { - return Symtab->addUndefined( + return Symtab->addUndefined( Undefined{nullptr, Name, STB_GLOBAL, STV_DEFAULT, 0}); } @@ -1551,7 +1551,7 @@ // Add all files to the symbol table. This will add almost all // symbols that we need to the symbol table. for (InputFile *F : Files) - parseFile(F); + parseFile(F); // Now that we have every file, we can decide if we will need a // dynamic symbol table. @@ -1569,10 +1569,10 @@ // Handle the `--undefined ` options. for (StringRef S : Config->Undefined) - handleUndefined(S); + handleUndefined(S); // If an entry symbol is in a static archive, pull out that file now. - handleUndefined(Config->Entry); + handleUndefined(Config->Entry); // If any of our inputs are bitcode files, the LTO code generator may create // references to certain library functions that might not be explicit in the @@ -1593,7 +1593,7 @@ // object file to the link. if (!BitcodeFiles.empty()) for (const char *S : LibcallRoutineNames) - handleLibcall(S); + handleLibcall(S); // Return if there were name resolution errors. if (errorCount()) Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -55,7 +55,7 @@ llvm::Optional readFile(StringRef Path); // Add symbols in File to the symbol table. -template void parseFile(InputFile *File); +void parseFile(InputFile *File); // The root class of input files. class InputFile { @@ -323,7 +323,7 @@ public: explicit ArchiveFile(std::unique_ptr &&File); static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; } - template void parse(); + void parse(); // Pulls out an object file that contains a definition for Sym and // returns it. If the same file was instantiated before, this Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -109,8 +109,7 @@ return false; } -// Add symbols in File to the symbol table. -template void elf::parseFile(InputFile *File) { +template static void doParseFile(InputFile *File) { // Comdat groups define "link once" sections. If two comdat groups have the // same name, only one of them is linked, and the other is ignored. This set // is used to uniquify them. @@ -128,7 +127,7 @@ // .a file if (auto *F = dyn_cast(File)) { - F->parse(); + F->parse(); return; } @@ -160,6 +159,26 @@ cast>(File)->parse(ComdatGroups); } +// Add symbols in File to the symbol table. +void elf::parseFile(InputFile *File) { + switch (Config->EKind) { + case ELF32LEKind: + doParseFile(File); + return; + case ELF32BEKind: + doParseFile(File); + return; + case ELF64LEKind: + doParseFile(File); + return; + case ELF64BEKind: + doParseFile(File); + return; + default: + llvm_unreachable("unknown ELFT"); + } +} + // Concatenates arguments to construct a string representing an error location. static std::string createFileLineMsg(StringRef Path, unsigned Line) { std::string Filename = path::filename(Path); @@ -892,8 +911,7 @@ switch (Sym->st_shndx) { case SHN_UNDEF: - return Symtab->addUndefined( - Undefined{this, Name, Binding, StOther, Type}); + return Symtab->addUndefined(Undefined{this, Name, Binding, StOther, Type}); case SHN_COMMON: if (Value == 0 || Value >= UINT32_MAX) fatal(toString(this) + ": common symbol '" + Name + @@ -909,7 +927,7 @@ case STB_WEAK: case STB_GNU_UNIQUE: if (Sec == &InputSection::Discarded) - return Symtab->addUndefined( + return Symtab->addUndefined( Undefined{this, Name, Binding, StOther, Type}); return Symtab->addDefined( Defined{this, Name, Binding, StOther, Type, Value, Size, Sec}); @@ -920,9 +938,9 @@ : InputFile(ArchiveKind, File->getMemoryBufferRef()), File(std::move(File)) {} -template void ArchiveFile::parse() { +void ArchiveFile::parse() { for (const Archive::Symbol &Sym : File->symbols()) - Symtab->addLazyArchive(LazyArchive{*this, Sym}); + Symtab->addLazyArchive(LazyArchive{*this, Sym}); } // Returns a buffer pointing to a member file containing a given symbol. @@ -1123,7 +1141,7 @@ } if (Sym.isUndefined()) { - Symbol *S = Symtab->addUndefined( + Symbol *S = Symtab->addUndefined( Undefined{this, Name, Sym.getBinding(), Sym.st_other, Sym.getType()}); S->ExportDynamic = true; continue; @@ -1262,7 +1280,7 @@ Undefined New(&F, Name, Binding, Visibility, Type); if (CanOmitFromDynSym) New.ExportDynamic = false; - return Symtab->addUndefined(New); + return Symtab->addUndefined(New); } if (ObjSym.isCommon()) @@ -1404,7 +1422,7 @@ for (const lto::InputFile::Symbol &Sym : Obj->symbols()) { if (Sym.isUndefined()) continue; - Symtab->addLazyObject(LazyObject{*this, Saver.save(Sym.getName())}); + Symtab->addLazyObject(LazyObject{*this, Saver.save(Sym.getName())}); } return; } @@ -1429,7 +1447,7 @@ for (const typename ELFT::Sym &Sym : Syms.slice(FirstGlobal)) { if (Sym.st_shndx == SHN_UNDEF) continue; - Symtab->addLazyObject( + Symtab->addLazyObject( LazyObject{*this, CHECK(Sym.getName(StringTable), this)}); } return; @@ -1445,16 +1463,6 @@ return Path; } -template void elf::parseFile(InputFile *); -template void elf::parseFile(InputFile *); -template void elf::parseFile(InputFile *); -template void elf::parseFile(InputFile *); - -template void ArchiveFile::parse(); -template void ArchiveFile::parse(); -template void ArchiveFile::parse(); -template void ArchiveFile::parse(); - template void BitcodeFile::parse(DenseSet &); template void BitcodeFile::parse(DenseSet &); template void BitcodeFile::parse(DenseSet &); Index: lld/trunk/ELF/SymbolTable.h =================================================================== --- lld/trunk/ELF/SymbolTable.h +++ lld/trunk/ELF/SymbolTable.h @@ -45,22 +45,18 @@ ArrayRef getSymbols() const { return SymVector; } - template Symbol *addUndefined(const Undefined &New); - + Symbol *addUndefined(const Undefined &New); Symbol *addDefined(const Defined &New); - void addShared(const SharedSymbol &New); - - template void addLazyArchive(const LazyArchive &New); - template void addLazyObject(const LazyObject &New); - + void addLazyArchive(const LazyArchive &New); + void addLazyObject(const LazyObject &New); Symbol *addBitcode(const Defined &New); Symbol *addCommon(const CommonSymbol &New); Symbol *insert(const Symbol &New); void mergeProperties(Symbol *Old, const Symbol &New); - template void fetchLazy(Symbol *Sym); + void fetchLazy(Symbol *Sym); void scanVersionScript(); @@ -74,7 +70,7 @@ llvm::DenseMap SoNames; private: - template void addLazy(const LazyT &New); + template void addLazy(const LazyT &New); std::vector findByVersion(SymbolVersion Ver); std::vector findAllByVersion(SymbolVersion Ver); Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -145,7 +145,7 @@ Old->Visibility = getMinVisibility(Old->Visibility, New.Visibility); } -template Symbol *SymbolTable::addUndefined(const Undefined &New) { +Symbol *SymbolTable::addUndefined(const Undefined &New) { Symbol *Old = insert(New); mergeProperties(Old, New); @@ -225,7 +225,7 @@ // group assignment rule simulates the traditional linker's semantics. bool Backref = Config->WarnBackrefs && New.File && Old->File->GroupId < New.File->GroupId; - fetchLazy(Old); + fetchLazy(Old); // We don't report backward references to weak symbols as they can be // overridden later. @@ -429,7 +429,7 @@ return SymVector[It->second]; } -template void SymbolTable::addLazy(const LazyT &New) { +template void SymbolTable::addLazy(const LazyT &New) { Symbol *Old = insert(New); mergeProperties(Old, New); @@ -452,27 +452,23 @@ } if (InputFile *F = New.fetch()) - parseFile(F); + parseFile(F); } -template void SymbolTable::addLazyArchive(const LazyArchive &New) { - addLazy(New); -} +void SymbolTable::addLazyArchive(const LazyArchive &New) { addLazy(New); } -template void SymbolTable::addLazyObject(const LazyObject &New) { - addLazy(New); -} +void SymbolTable::addLazyObject(const LazyObject &New) { addLazy(New); } -template void SymbolTable::fetchLazy(Symbol *Sym) { +void SymbolTable::fetchLazy(Symbol *Sym) { if (auto *S = dyn_cast(Sym)) { if (InputFile *File = S->fetch()) - parseFile(File); + parseFile(File); return; } auto *S = cast(Sym); if (InputFile *File = cast(S->File)->fetch()) - parseFile(File); + parseFile(File); } // Initialize DemangledSyms with a map from demangled symbols to symbol @@ -636,27 +632,7 @@ Sym->parseSymbolVersion(); } -template Symbol *SymbolTable::addUndefined(const Undefined &); -template Symbol *SymbolTable::addUndefined(const Undefined &); -template Symbol *SymbolTable::addUndefined(const Undefined &); -template Symbol *SymbolTable::addUndefined(const Undefined &); - template void SymbolTable::addCombinedLTOObject(); template void SymbolTable::addCombinedLTOObject(); template void SymbolTable::addCombinedLTOObject(); template void SymbolTable::addCombinedLTOObject(); - -template void SymbolTable::addLazyArchive(const LazyArchive &); -template void SymbolTable::addLazyArchive(const LazyArchive &); -template void SymbolTable::addLazyArchive(const LazyArchive &); -template void SymbolTable::addLazyArchive(const LazyArchive &); - -template void SymbolTable::addLazyObject(const LazyObject &); -template void SymbolTable::addLazyObject(const LazyObject &); -template void SymbolTable::addLazyObject(const LazyObject &); -template void SymbolTable::addLazyObject(const LazyObject &); - -template void SymbolTable::fetchLazy(Symbol *); -template void SymbolTable::fetchLazy(Symbol *); -template void SymbolTable::fetchLazy(Symbol *); -template void SymbolTable::fetchLazy(Symbol *);