[PATCH] D56089: [ELF] A shared object is needed if any of its occurrences is needed
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 27 14:27:25 PST 2018
MaskRay updated this revision to Diff 179582.
MaskRay edited the summary of this revision.
MaskRay added a comment.
Check `if (errorCount) early
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56089/new/
https://reviews.llvm.org/D56089
Files:
ELF/SymbolTable.cpp
ELF/SymbolTable.h
test/ELF/as-needed-not-in-regular.s
Index: test/ELF/as-needed-not-in-regular.s
===================================================================
--- test/ELF/as-needed-not-in-regular.s
+++ test/ELF/as-needed-not-in-regular.s
@@ -19,6 +19,12 @@
# the reference to a2 is weak, don't add a DT_NEEDED entry for a.so.
# CHECK-NOT: a.so
+# RUN: ld.lld %t.o %tb.so --as-needed %ta.so --no-as-needed %ta.so -o %t
+# RUN: llvm-readelf -d %t | FileCheck %s -check-prefix=NEEDED
+
+# a.so is needed because one of its occurrences is needed.
+# NEEDED: a.so
+
.global _start
.weak a2
_start:
Index: ELF/SymbolTable.h
===================================================================
--- ELF/SymbolTable.h
+++ ELF/SymbolTable.h
@@ -108,7 +108,7 @@
llvm::DenseSet<llvm::CachedHashStringRef> ComdatGroups;
// Set of .so files to not link the same shared object file more than once.
- llvm::DenseSet<StringRef> SoNames;
+ llvm::DenseMap<StringRef, InputFile *> SoNames;
// A map from demangled symbol names to their symbol objects.
// This mapping is 1:N because two symbols with different versions
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -94,8 +94,20 @@
if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
// DSOs are uniquified not by filename but by soname.
F->parseSoName();
- if (errorCount() || !SoNames.insert(F->SoName).second)
+ if (errorCount())
return;
+
+ // If a DSO appears more than once on the command line with and without
+ // --as-needed, --no-as-needed takes precedence over --as-needed because a
+ // user can add an extra DSO with --no-as-needed to force it to be added to
+ // the dependency list.
+ DenseMap<StringRef, InputFile *>::iterator It;
+ bool WasInserted;
+ std::tie(It, WasInserted) = SoNames.try_emplace(F->SoName, F);
+ cast<SharedFile<ELFT>>(It->second)->IsNeeded |= F->IsNeeded;
+ if (!WasInserted)
+ return;
+
SharedFiles.push_back(F);
F->parseRest();
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56089.179582.patch
Type: text/x-patch
Size: 2054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181227/7ef760b2/attachment.bin>
More information about the llvm-commits
mailing list