[PATCH] D39353: [lld] Fix --exclude-libs broken when --whole-archive is used
Oleg Ranevskyy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 16:24:43 PDT 2017
iid_iunknown created this revision.
iid_iunknown added a project: lld.
Herald added a subscriber: emaste.
**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.
Repository:
rL LLVM
https://reviews.llvm.org/D39353
Files:
ELF/Driver.cpp
test/ELF/exclude-libs.s
Index: test/ELF/exclude-libs.s
===================================================================
--- test/ELF/exclude-libs.s
+++ test/ELF/exclude-libs.s
@@ -22,6 +22,12 @@
// 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 --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
+
+// RUN: ld.lld -shared --whole-archive %t.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL
+// RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s
+
// DEFAULT: Name: fn
// EXCLUDE-NOT: Name: fn
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -976,15 +976,28 @@
// A special library name "ALL" means all archive files.
//
// This is not a popular option, but some programs such as bionic libc use it.
+template <class ELFT>
static void excludeLibs(opt::InputArgList &Args, ArrayRef<InputFile *> Files) {
DenseSet<StringRef> Libs = getExcludeLibs(Args);
bool All = Libs.count("ALL");
- for (InputFile *File : Files)
- if (auto *F = dyn_cast<ArchiveFile>(File))
+ for (InputFile *File : Files) {
+ // For archives check if they are in the -exclude-libs list.
+ if (auto *F = dyn_cast<ArchiveFile>(File)) {
if (All || Libs.count(path::filename(F->getName())))
for (SymbolBody *Sym : F->getSymbols())
Sym->symbol()->VersionId = VER_NDX_LOCAL;
+ // Use of --whole-archive splits static libraries into separate objects.
+ // To handle this case check if the object originates from a static
+ // library that is to be excluded.
+ } else if (auto *F = dyn_cast<elf::ObjFile<ELFT>>(File)) {
+ if (!F->ArchiveName.empty() &&
+ (All || Libs.count(path::filename(F->ArchiveName))))
+ for (SymbolBody *SymBody : F->getSymbols())
+ if (!SymBody->isLocal())
+ SymBody->symbol()->VersionId = VER_NDX_LOCAL;
+ }
+ }
}
// Do actual linking. Note that when this function is called,
@@ -1067,7 +1080,7 @@
// Handle the -exclude-libs option.
if (Args.hasArg(OPT_exclude_libs))
- excludeLibs(Args, Files);
+ excludeLibs<ELFT>(Args, Files);
// Apply version scripts.
Symtab->scanVersionScript();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39353.120512.patch
Type: text/x-patch
Size: 2469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171026/f6a42f66/attachment.bin>
More information about the llvm-commits
mailing list