Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -242,9 +242,7 @@ InputFile *fetch(); private: - std::vector getSymbolNames(); - template std::vector getElfSymbols(); - std::vector getBitcodeSymbols(); + template void addElfSymbols(); bool Seen = false; uint64_t OffsetInArchive; Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -1119,61 +1119,51 @@ } template void LazyObjFile::parse() { - for (StringRef Sym : getSymbolNames()) - Symtab->addLazyObject(Sym, *this); + // A lazy object file wraps either a bitcode file or an ELF file. + if (isBitcode(this->MB)) { + std::unique_ptr Obj = + CHECK(lto::InputFile::create(this->MB), this); + for (const lto::InputFile::Symbol &Sym : Obj->symbols()) + if (!Sym.isUndefined()) + Symtab->addLazyObject(Saver.save(Sym.getName()), *this); + return; + } + + switch (getELFKind(this->MB)) { + case ELF32LEKind: + addElfSymbols(); + return; + case ELF32BEKind: + addElfSymbols(); + return; + case ELF64LEKind: + addElfSymbols(); + return; + case ELF64BEKind: + addElfSymbols(); + return; + default: + llvm_unreachable("getELFKind"); + } } -template std::vector LazyObjFile::getElfSymbols() { - typedef typename ELFT::Shdr Elf_Shdr; - typedef typename ELFT::Sym Elf_Sym; - typedef typename ELFT::SymRange Elf_Sym_Range; +template void LazyObjFile::addElfSymbols() { + ELFFile Obj = check(ELFFile::create(MB.getBuffer())); + ArrayRef Sections = CHECK(Obj.sections(), this); - ELFFile Obj = check(ELFFile::create(this->MB.getBuffer())); - ArrayRef Sections = CHECK(Obj.sections(), this); - for (const Elf_Shdr &Sec : Sections) { + for (const typename ELFT::Shdr &Sec : Sections) { if (Sec.sh_type != SHT_SYMTAB) continue; - Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), this); + typename ELFT::SymRange Syms = CHECK(Obj.symbols(&Sec), this); uint32_t FirstNonLocal = Sec.sh_info; StringRef StringTable = CHECK(Obj.getStringTableForSymtab(Sec, Sections), this); - std::vector V; - for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal)) + for (const typename ELFT::Sym &Sym : Syms.slice(FirstNonLocal)) if (Sym.st_shndx != SHN_UNDEF) - V.push_back(CHECK(Sym.getName(StringTable), this)); - return V; - } - return {}; -} - -std::vector LazyObjFile::getBitcodeSymbols() { - std::unique_ptr Obj = - CHECK(lto::InputFile::create(this->MB), this); - std::vector V; - for (const lto::InputFile::Symbol &Sym : Obj->symbols()) - if (!Sym.isUndefined()) - V.push_back(Saver.save(Sym.getName())); - return V; -} - -// Returns a vector of globally-visible defined symbol names. -std::vector LazyObjFile::getSymbolNames() { - if (isBitcode(this->MB)) - return getBitcodeSymbols(); - - switch (getELFKind(this->MB)) { - case ELF32LEKind: - return getElfSymbols(); - case ELF32BEKind: - return getElfSymbols(); - case ELF64LEKind: - return getElfSymbols(); - case ELF64BEKind: - return getElfSymbols(); - default: - llvm_unreachable("getELFKind"); + Symtab->addLazyObject(CHECK(Sym.getName(StringTable), this), + *this); } } @@ -1203,7 +1193,6 @@ StringRef StringTable = CHECK(Obj.getStringTableForSymtab(Sec, Sections), ObjName); - std::vector> Ret; for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal)) if (Sym.st_shndx != SHN_UNDEF) Symtab->addRegular(CHECK(Sym.getName(StringTable), ObjName),