Improve error check for an empty archive.
Previously, it warned on any archive file that has no symbol.
It turned out that that is too noisy.
With this patch, it warns on such archive file that contains no file.
Differential Revision: https://reviews.llvm.org/D25111
llvm-svn: 282885
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 7605ab0..c1b59c1 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -425,18 +425,16 @@
template <class ELFT> void ArchiveFile::parse() {
File = check(Archive::create(MB), "failed to parse archive");
- // Read the symbol table to construct Lazy objects.
- bool IsEmpty = true;
- for (const Archive::Symbol &Sym : File->symbols()) {
- Symtab<ELFT>::X->addLazyArchive(this, Sym);
- IsEmpty = false;
- }
+ // Checks for a common usage error of an ar command.
+ if (File->getNumberOfSymbols() == 0 && !File->isEmpty())
+ warn(getName() + " has no symbol."
+ " Chances are you are doing an LTO build and forgot to use an ar"
+ " command that can create a symbol table for LLVM bitcode files."
+ " If so, use llvm-ar or GNU ar + plugin.");
- if (IsEmpty)
- warn(getName() + " has no symbol. Chances are you are doing "
- "an LTO build and forgot to use an ar command that can create "
- "a symbol table for LLVM bitcode files. If so, use llvm-ar or "
- "GNU ar + plugin.");
+ // Read the symbol table to construct Lazy objects.
+ for (const Archive::Symbol &Sym : File->symbols())
+ Symtab<ELFT>::X->addLazyArchive(this, Sym);
}
// Returns a buffer pointing to a member file containing a given symbol.