[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
Wed Dec 26 13:41:05 PST 2018
MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Repository:
rLLD LLVM Linker
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,7 +94,9 @@
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)
+ auto R = SoNames.try_emplace(F->SoName, F);
+ cast<SharedFile<ELFT>>(R.first->second)->IsNeeded |= F->IsNeeded;
+ if (errorCount() || !R.second)
return;
SharedFiles.push_back(F);
F->parseRest();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56089.179520.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181226/f4ca1142/attachment.bin>
More information about the llvm-commits
mailing list