[lld] r325380 - ELF: Stop collecting a list of symbols in ArchiveFile.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 12:23:54 PST 2018
Author: pcc
Date: Fri Feb 16 12:23:54 2018
New Revision: 325380
URL: http://llvm.org/viewvc/llvm-project?rev=325380&view=rev
Log:
ELF: Stop collecting a list of symbols in ArchiveFile.
There seems to be no reason to collect this list of symbols.
Also fix a bug where --exclude-libs would apply to all symbols that
appear in an archive's symbol table, even if the relevant archive
member was not added to the link.
Differential Revision: https://reviews.llvm.org/D43369
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/test/ELF/Inputs/exclude-libs.s
lld/trunk/test/ELF/exclude-libs.s
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Feb 16 12:23:54 2018
@@ -985,14 +985,6 @@ static DenseSet<StringRef> getExcludeLib
return Ret;
}
-static Optional<StringRef> getArchiveName(InputFile *File) {
- if (isa<ArchiveFile>(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.
@@ -1000,15 +992,15 @@ static Optional<StringRef> getArchiveNam
//
// 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) {
+static void excludeLibs(opt::InputArgList &Args) {
DenseSet<StringRef> Libs = getExcludeLibs(Args);
bool All = Libs.count("ALL");
- for (InputFile *File : Files)
- if (Optional<StringRef> 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;
}
@@ -1093,7 +1085,7 @@ template <class ELFT> void LinkerDriver:
// Handle the -exclude-libs option.
if (Args.hasArg(OPT_exclude_libs))
- excludeLibs<ELFT>(Args, Files);
+ excludeLibs<ELFT>(Args);
// Create ElfHeader early. We need a dummy section in
// addReservedSymbols to mark the created symbols as not absolute.
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Feb 16 12:23:54 2018
@@ -707,9 +707,8 @@ ArchiveFile::ArchiveFile(std::unique_ptr
File(std::move(File)) {}
template <class ELFT> void ArchiveFile::parse() {
- Symbols.reserve(File->getNumberOfSymbols());
for (const Archive::Symbol &Sym : File->symbols())
- Symbols.push_back(Symtab->addLazyArchive<ELFT>(Sym.getName(), *this, Sym));
+ Symtab->addLazyArchive<ELFT>(Sym.getName(), *this, Sym);
}
// Returns a buffer pointing to a member file containing a given symbol.
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Fri Feb 16 12:23:54 2018
@@ -91,7 +91,7 @@ public:
// function on files of other types.
ArrayRef<Symbol *> getSymbols() {
assert(FileKind == BinaryKind || FileKind == ObjKind ||
- FileKind == BitcodeKind || FileKind == ArchiveKind);
+ FileKind == BitcodeKind);
return Symbols;
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Feb 16 12:23:54 2018
@@ -530,29 +530,28 @@ Symbol *SymbolTable::find(StringRef Name
}
template <class ELFT>
-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<LazyArchive>(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<LazyArchive>(S, F, Sym, S->Type);
S->Binding = STB_WEAK;
- return S;
+ return;
}
std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
if (!MBInfo.first.getBuffer().empty())
addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
- return S;
}
template <class ELFT>
@@ -797,16 +796,16 @@ template void SymbolTable::addCombinedLT
template void SymbolTable::addCombinedLTOObject<ELF64LE>();
template void SymbolTable::addCombinedLTOObject<ELF64BE>();
-template Symbol *
+template void
SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile &,
const object::Archive::Symbol);
-template Symbol *
+template void
SymbolTable::addLazyArchive<ELF32BE>(StringRef, ArchiveFile &,
const object::Archive::Symbol);
-template Symbol *
+template void
SymbolTable::addLazyArchive<ELF64LE>(StringRef, ArchiveFile &,
const object::Archive::Symbol);
-template Symbol *
+template void
SymbolTable::addLazyArchive<ELF64BE>(StringRef, ArchiveFile &,
const object::Archive::Symbol);
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Fri Feb 16 12:23:54 2018
@@ -60,8 +60,8 @@ public:
uint32_t VerdefIndex);
template <class ELFT>
- 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 <class ELFT> void addLazyObject(StringRef Name, LazyObjFile &Obj);
Modified: lld/trunk/test/ELF/Inputs/exclude-libs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/exclude-libs.s?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/test/ELF/Inputs/exclude-libs.s (original)
+++ lld/trunk/test/ELF/Inputs/exclude-libs.s Fri Feb 16 12:23:54 2018
@@ -1,3 +1,5 @@
.globl fn
fn:
nop
+
+.globl foo
Modified: lld/trunk/test/ELF/exclude-libs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/exclude-libs.s?rev=325380&r1=325379&r2=325380&view=diff
==============================================================================
--- lld/trunk/test/ELF/exclude-libs.s (original)
+++ lld/trunk/test/ELF/exclude-libs.s Fri Feb 16 12:23:54 2018
@@ -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 at PLT
More information about the llvm-commits
mailing list