<div dir="ltr">I'm wondering if this is really an expected behavior. Does linkers have to look at DT_SONAME field in DSOs to dedup them? Is this what other linkers do?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 1, 2015 at 12:52 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Oct 1 14:52:48 2015<br>
New Revision: 249061<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249061&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249061&view=rev</a><br>
Log:<br>
Don't include shared libraries multiple times.<br>
<br>
Modified:<br>
lld/trunk/ELF/InputFiles.cpp<br>
lld/trunk/ELF/InputFiles.h<br>
lld/trunk/ELF/SymbolTable.cpp<br>
lld/trunk/ELF/SymbolTable.h<br>
lld/trunk/test/elf2/soname.s<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=249061&r1=249060&r2=249061&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=249061&r1=249060&r2=249061&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Thu Oct 1 14:52:48 2015<br>
@@ -77,13 +77,14 @@ ELFData<ELFT>::getSymbolsHelper(bool Loc<br>
return make_range(Syms.begin() + 1, Syms.begin() + FirstNonLocal);<br>
}<br>
<br>
-template <class ELFT><br>
-typename ELFData<ELFT>::Elf_Sym_Range ELFData<ELFT>::getNonLocalSymbols() {<br>
- if (!Symtab)<br>
- return Elf_Sym_Range(nullptr, nullptr);<br>
+template <class ELFT> void ELFData<ELFT>::initStringTable() {<br>
ErrorOr<StringRef> StringTableOrErr = ELFObj.getStringTableForSymtab(*Symtab);<br>
error(StringTableOrErr.getError());<br>
StringTable = *StringTableOrErr;<br>
+}<br>
+<br>
+template <class ELFT><br>
+typename ELFData<ELFT>::Elf_Sym_Range ELFData<ELFT>::getNonLocalSymbols() {<br>
return getSymbolsHelper(false);<br>
}<br>
<br>
@@ -141,6 +142,7 @@ template <class ELFT> void elf2::ObjectF<br>
}<br>
<br>
template <class ELFT> void elf2::ObjectFile<ELFT>::initializeSymbols() {<br>
+ this->initStringTable();<br>
Elf_Sym_Range Syms = this->getNonLocalSymbols();<br>
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());<br>
SymbolBodies.reserve(NumSymbols);<br>
@@ -233,7 +235,7 @@ template <class ELFT><br>
SharedFile<ELFT>::SharedFile(MemoryBufferRef M)<br>
: SharedFileBase(getStaticELFKind<ELFT>(), M), ELFData<ELFT>(M) {}<br>
<br>
-template <class ELFT> void SharedFile<ELFT>::parse() {<br>
+template <class ELFT> void SharedFile<ELFT>::parseSoName() {<br>
typedef typename ELFFile<ELFT>::Elf_Dyn Elf_Dyn;<br>
typedef typename ELFFile<ELFT>::uintX_t uintX_t;<br>
const Elf_Shdr *DynamicSec = nullptr;<br>
@@ -247,8 +249,7 @@ template <class ELFT> void SharedFile<EL<br>
DynamicSec = &Sec;<br>
}<br>
<br>
- // Also sets StringTable<br>
- Elf_Sym_Range Syms = this->getNonLocalSymbols();<br>
+ this->initStringTable();<br>
SoName = getName();<br>
<br>
if (DynamicSec) {<br>
@@ -266,7 +267,10 @@ template <class ELFT> void SharedFile<EL<br>
}<br>
}<br>
}<br>
+}<br>
<br>
+template <class ELFT> void SharedFile<ELFT>::parse() {<br>
+ Elf_Sym_Range Syms = this->getNonLocalSymbols();<br>
uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());<br>
SymbolBodies.reserve(NumSymbols);<br>
for (const Elf_Sym &Sym : Syms) {<br>
<br>
Modified: lld/trunk/ELF/InputFiles.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=249061&r1=249060&r2=249061&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=249061&r1=249060&r2=249061&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.h (original)<br>
+++ lld/trunk/ELF/InputFiles.h Thu Oct 1 14:52:48 2015<br>
@@ -116,6 +116,7 @@ protected:<br>
llvm::object::ELFFile<ELFT> ELFObj;<br>
const Elf_Shdr *Symtab = nullptr;<br>
StringRef StringTable;<br>
+ void initStringTable();<br>
Elf_Sym_Range getNonLocalSymbols();<br>
Elf_Sym_Range getSymbolsHelper(bool);<br>
};<br>
@@ -194,6 +195,7 @@ public:<br>
: ELFFileBase(SharedKind, EKind, M) {}<br>
static bool classof(const InputFile *F) { return F->kind() == SharedKind; }<br>
StringRef getSoName() const { return SoName; }<br>
+ virtual void parseSoName() = 0;<br>
};<br>
<br>
template <class ELFT><br>
@@ -217,6 +219,7 @@ public:<br>
<br>
explicit SharedFile(MemoryBufferRef M);<br>
<br>
+ void parseSoName() override;<br>
void parse() override;<br>
};<br>
<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249061&r1=249060&r2=249061&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249061&r1=249060&r2=249061&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SymbolTable.cpp (original)<br>
+++ lld/trunk/ELF/SymbolTable.cpp Thu Oct 1 14:52:48 2015<br>
@@ -41,6 +41,11 @@ void SymbolTable::addFile(std::unique_pt<br>
addLazy(&Sym);<br>
return;<br>
}<br>
+ if (auto *S = dyn_cast<SharedFileBase>(File.get())) {<br>
+ S->parseSoName();<br>
+ if (!IncludedSoNames.insert(S->getSoName()).second)<br>
+ return;<br>
+ }<br>
File->parse();<br>
addELFFile(cast<ELFFileBase>(File.release()));<br>
}<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=249061&r1=249060&r2=249061&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=249061&r1=249060&r2=249061&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SymbolTable.h (original)<br>
+++ lld/trunk/ELF/SymbolTable.h Thu Oct 1 14:52:48 2015<br>
@@ -93,6 +93,7 @@ private:<br>
std::vector<std::unique_ptr<ObjectFileBase>> ObjectFiles;<br>
<br>
std::vector<std::unique_ptr<SharedFileBase>> SharedFiles;<br>
+ llvm::DenseSet<StringRef> IncludedSoNames;<br>
<br>
SymbolBody *EntrySym = nullptr;<br>
};<br>
<br>
Modified: lld/trunk/test/elf2/soname.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname.s?rev=249061&r1=249060&r2=249061&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname.s?rev=249061&r1=249060&r2=249061&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/soname.s (original)<br>
+++ lld/trunk/test/elf2/soname.s Thu Oct 1 14:52:48 2015<br>
@@ -1,9 +1,10 @@<br>
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o<br>
// RUN: lld -flavor gnu2 %t.o -shared -soname=bar -o %t.so<br>
-// RUN: lld -flavor gnu2 %t.o %t.so -o %t<br>
+// RUN: lld -flavor gnu2 %t.o %t.so %t.so -o %t<br>
// RUN: llvm-readobj --dynamic-table %t | FileCheck %s<br>
<br>
// CHECK: 0x0000000000000001 NEEDED SharedLibrary (bar)<br>
+// CHECK-NOT: NEEDED<br>
<br>
.global _start<br>
_start:<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>