[PATCH] D43369: ELF: Stop collecting a list of symbols in ArchiveFile.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 10:42:08 PST 2018
LGTM
Peter Collingbourne via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:
> pcc updated this revision to Diff 134557.
> pcc added a comment.
>
> - Remove unused file
>
>
> https://reviews.llvm.org/D43369
>
> Files:
> lld/ELF/Driver.cpp
> lld/ELF/InputFiles.cpp
> lld/ELF/InputFiles.h
> lld/ELF/SymbolTable.cpp
> lld/ELF/SymbolTable.h
> lld/test/ELF/Inputs/exclude-libs.s
> lld/test/ELF/exclude-libs.s
>
> Index: lld/test/ELF/exclude-libs.s
> ===================================================================
> --- lld/test/ELF/exclude-libs.s
> +++ lld/test/ELF/exclude-libs.s
> @@ -22,15 +22,20 @@
> // 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
>
> // 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
> +// DEFAULT: Name: foo
> // EXCLUDE-NOT: Name: fn
> +// EXCLUDE: Name: foo
>
> -.globl fn
> +.globl fn, foo
> foo:
> call fn at PLT
> Index: lld/test/ELF/Inputs/exclude-libs.s
> ===================================================================
> --- lld/test/ELF/Inputs/exclude-libs.s
> +++ lld/test/ELF/Inputs/exclude-libs.s
> @@ -1,3 +1,5 @@
> .globl fn
> fn:
> nop
> +
> +.globl foo
> Index: lld/ELF/SymbolTable.h
> ===================================================================
> --- lld/ELF/SymbolTable.h
> +++ lld/ELF/SymbolTable.h
> @@ -60,8 +60,8 @@
> 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);
>
> Index: lld/ELF/SymbolTable.cpp
> ===================================================================
> --- lld/ELF/SymbolTable.cpp
> +++ lld/ELF/SymbolTable.cpp
> @@ -530,29 +530,28 @@
> }
>
> 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<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);
>
> Index: lld/ELF/InputFiles.h
> ===================================================================
> --- lld/ELF/InputFiles.h
> +++ lld/ELF/InputFiles.h
> @@ -91,7 +91,7 @@
> // function on files of other types.
> ArrayRef<Symbol *> getSymbols() {
> assert(FileKind == BinaryKind || FileKind == ObjKind ||
> - FileKind == BitcodeKind || FileKind == ArchiveKind);
> + FileKind == BitcodeKind);
> return Symbols;
> }
>
> Index: lld/ELF/InputFiles.cpp
> ===================================================================
> --- lld/ELF/InputFiles.cpp
> +++ lld/ELF/InputFiles.cpp
> @@ -707,9 +707,8 @@
> 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.
> Index: lld/ELF/Driver.cpp
> ===================================================================
> --- lld/ELF/Driver.cpp
> +++ lld/ELF/Driver.cpp
> @@ -980,30 +980,22 @@
> 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.
> // 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) {
> +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;
> }
>
> @@ -1088,7 +1080,7 @@
>
> // 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.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list