Problem
--exclude-libs does not work for static libraries affected by the --whole-archive option.
Description
--exclude-libs creates a list of static library paths and does library lookups in this list.
--whole-archive splits the static libraries that follow it into separate objects. As a result, lld no longer sees static libraries among linked files and does no --exclude-libs lookups.
Solution
The proposed solution is to make --exclude-libs consider object files too. When lld finds an object file it checks whether this file originates from an archive and, if so, looks the archive up in the --exclude-libs list.
I'd define a function
static StringRef getArchiveName(InputFile *File) { if (isa<ArchiveFile>(File)) return File_>getName(); return File->ArchiveName; }so that I can write
for (InputFile *File :Files) if ((All && isa<ArchiveFile>(File)) || Libs.count(path::filename(getArchiveName(File))) for (SymbolBody *Sym : F->getSymbols() if (!Sym->isLocal()) Sym->symbol()->VersionId = VER_NDX_LOCAL;