Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -980,14 +980,6 @@ return Ret; } -static Optional getArchiveName(InputFile *File) { - if (isa(File)) - return File->getName(); - if (!File->ArchiveName.empty()) - return StringRef(File->ArchiveName); - return None; -} - // Handles the -exclude-libs option. If a static library file is specified // by the -exclude-libs option, all public symbols from the archive become // private unless otherwise specified by version scripts or something. @@ -995,15 +987,15 @@ // // This is not a popular option, but some programs such as bionic libc use it. template -static void excludeLibs(opt::InputArgList &Args, ArrayRef Files) { +static void excludeLibs(opt::InputArgList &Args) { DenseSet Libs = getExcludeLibs(Args); bool All = Libs.count("ALL"); - for (InputFile *File : Files) - if (Optional Archive = getArchiveName(File)) - if (All || Libs.count(path::filename(*Archive))) + for (InputFile *File : ObjectFiles) + if (!File->ArchiveName.empty()) + if (All || Libs.count(path::filename(File->ArchiveName))) for (Symbol *Sym : File->getSymbols()) - if (!Sym->isLocal()) + if (!Sym->isLocal() && Sym->File == File) Sym->VersionId = VER_NDX_LOCAL; } @@ -1088,7 +1080,7 @@ // Handle the -exclude-libs option. if (Args.hasArg(OPT_exclude_libs)) - excludeLibs(Args, Files); + excludeLibs(Args); // Create ElfHeader early. We need a dummy section in // addReservedSymbols to mark the created symbols as not absolute. Index: lld/ELF/InputFiles.h =================================================================== --- lld/ELF/InputFiles.h +++ lld/ELF/InputFiles.h @@ -91,7 +91,7 @@ // function on files of other types. ArrayRef getSymbols() { assert(FileKind == BinaryKind || FileKind == ObjKind || - FileKind == BitcodeKind || FileKind == ArchiveKind); + FileKind == BitcodeKind); return Symbols; } Index: lld/ELF/InputFiles.cpp =================================================================== --- lld/ELF/InputFiles.cpp +++ lld/ELF/InputFiles.cpp @@ -707,9 +707,8 @@ File(std::move(File)) {} template void ArchiveFile::parse() { - Symbols.reserve(File->getNumberOfSymbols()); for (const Archive::Symbol &Sym : File->symbols()) - Symbols.push_back(Symtab->addLazyArchive(Sym.getName(), *this, Sym)); + Symtab->addLazyArchive(Sym.getName(), *this, Sym); } // Returns a buffer pointing to a member file containing a given symbol. Index: lld/ELF/SymbolTable.h =================================================================== --- lld/ELF/SymbolTable.h +++ lld/ELF/SymbolTable.h @@ -60,8 +60,8 @@ uint32_t VerdefIndex); template - Symbol *addLazyArchive(StringRef Name, ArchiveFile &F, - const llvm::object::Archive::Symbol S); + void addLazyArchive(StringRef Name, ArchiveFile &F, + const llvm::object::Archive::Symbol S); template void addLazyObject(StringRef Name, LazyObjFile &Obj); Index: lld/ELF/SymbolTable.cpp =================================================================== --- lld/ELF/SymbolTable.cpp +++ lld/ELF/SymbolTable.cpp @@ -530,29 +530,28 @@ } template -Symbol *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F, - const object::Archive::Symbol Sym) { +void SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F, + const object::Archive::Symbol Sym) { Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted) { replaceSymbol(S, F, Sym, Symbol::UnknownType); - return S; + return; } if (!S->isUndefined()) - return S; + return; // An undefined weak will not fetch archive members. See comment on Lazy in // Symbols.h for the details. if (S->isWeak()) { replaceSymbol(S, F, Sym, S->Type); S->Binding = STB_WEAK; - return S; + return; } std::pair MBInfo = F.getMember(&Sym); if (!MBInfo.first.getBuffer().empty()) addFile(createObjectFile(MBInfo.first, F.getName(), MBInfo.second)); - return S; } template @@ -797,16 +796,16 @@ template void SymbolTable::addCombinedLTOObject(); template void SymbolTable::addCombinedLTOObject(); -template Symbol * +template void SymbolTable::addLazyArchive(StringRef, ArchiveFile &, const object::Archive::Symbol); -template Symbol * +template void SymbolTable::addLazyArchive(StringRef, ArchiveFile &, const object::Archive::Symbol); -template Symbol * +template void SymbolTable::addLazyArchive(StringRef, ArchiveFile &, const object::Archive::Symbol); -template Symbol * +template void SymbolTable::addLazyArchive(StringRef, ArchiveFile &, const object::Archive::Symbol); Index: lld/test/ELF/Inputs/exclude-libs.s =================================================================== --- lld/test/ELF/Inputs/exclude-libs.s +++ lld/test/ELF/Inputs/exclude-libs.s @@ -1,3 +1,5 @@ .globl fn fn: nop + +.globl foo Index: lld/test/ELF/exclude-libs.s =================================================================== --- lld/test/ELF/exclude-libs.s +++ lld/test/ELF/exclude-libs.s @@ -22,6 +22,9 @@ // RUN: ld.lld -shared %t.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s +// RUN: ld.lld -shared %t.o %t2.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL +// RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=DEFAULT %s + // RUN: ld.lld -shared --whole-archive %t.o %t.dir/exc.a -o %t.exe --exclude-libs foo,bar,exc.a // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s @@ -29,8 +32,10 @@ // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s // DEFAULT: Name: fn +// DEFAULT: Name: foo // EXCLUDE-NOT: Name: fn +// EXCLUDE: Name: foo -.globl fn +.globl fn, foo foo: call fn@PLT