recommend using llvm-ar when finding undefined references and empty archives

Summary:
When we perform LTO builds with a version of ar that does not
understand LLVM bitcode objects, we end up with undefined references,
because our archive files do not list the bitcode symbols in their
indices. The error messages do not make it clear what the real problem
is. This change adds a note that points out the likely problem and
solution. It is similar in spirit to r282633, but aims to avoid false
positives by only triggering when we see both undefined references and
archives without symbols in their indices.

Fixes PR32281.

Reviewers: davide, ruiu, tejohnson

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D31011

llvm-svn: 298124
This commit is contained in:
Bob Haarman 2017-03-17 21:32:49 +00:00
parent f73c6c7e84
commit f790f788b6
3 changed files with 19 additions and 3 deletions

View File

@ -98,6 +98,7 @@ struct Configuration {
std::vector<SymbolVersion> VersionScriptLocals;
std::vector<uint8_t> BuildIdVector;
bool AllowMultipleDefinition;
bool ArchiveWithoutSymbolsSeen = false;
bool AsNeeded = false;
bool Bsymbolic;
bool BsymbolicFunctions;

View File

@ -556,8 +556,12 @@ template <class ELFT> void ArchiveFile::parse() {
MB.getBufferIdentifier() + ": failed to parse archive");
// Read the symbol table to construct Lazy objects.
for (const Archive::Symbol &Sym : File->symbols())
for (const Archive::Symbol &Sym : File->symbols()) {
Symtab<ELFT>::X->addLazyArchive(this, Sym);
}
if (File->symbols().begin() == File->symbols().end())
Config->ArchiveWithoutSymbolsSeen = true;
}
// Returns a buffer pointing to a member file containing a given symbol.

View File

@ -610,10 +610,21 @@ static void reportUndefined(SymbolBody &Sym, InputSectionBase &S,
toString(Sym) + "'";
if (Config->UnresolvedSymbols == UnresolvedPolicy::WarnAll ||
(Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal))
(Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal)) {
warn(Msg);
else
} else {
error(Msg);
if (Config->ArchiveWithoutSymbolsSeen) {
message("At least one archive listed no symbols in its index."
" This can happen when creating archives with a version"
" of ar that does not understand the object files in"
" the archive. For example, if you are using LLVM"
" bitcode objects (such as created by -flto), you may"
" need to use llvm-ar or GNU ar with a plugin.");
// Reset to false so that we print the message only once.
Config->ArchiveWithoutSymbolsSeen = false;
}
}
}
template <class RelTy>