[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 11:33:01 PST 2018
MaskRay updated this revision to Diff 179568.
MaskRay added a comment.
Spell out the two components of the try_emplace return value
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
@@ -93,8 +93,17 @@
// .so file
if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
// DSOs are uniquified not by filename but by soname.
+ // 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 is likely to add an extra DSO with --no-as-needed to force
+ // it to be added to the dependency list.
F->parseSoName();
- if (errorCount() || !SoNames.insert(F->SoName).second)
+ 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 (errorCount() || !WasInserted)
return;
SharedFiles.push_back(F);
F->parseRest();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56089.179568.patch
Type: text/x-patch
Size: 2041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181227/05561016/attachment.bin>
More information about the llvm-commits
mailing list