forked from OSchip/llvm-project
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 llvm-svn: 325380
This commit is contained in:
parent
f931c179ca
commit
09e04af42f
|
@ -985,14 +985,6 @@ static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &Args) {
|
|||
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> getArchiveName(InputFile *File) {
|
|||
//
|
||||
// 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::link(opt::InputArgList &Args) {
|
|||
|
||||
// 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.
|
||||
|
|
|
@ -707,9 +707,8 @@ ArchiveFile::ArchiveFile(std::unique_ptr<Archive> &&File)
|
|||
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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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::addCombinedLTOObject<ELF32BE>();
|
|||
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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
.globl fn
|
||||
fn:
|
||||
nop
|
||||
|
||||
.globl foo
|
||||
|
|
|
@ -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@PLT
|
||||
|
|
Loading…
Reference in New Issue