<div dir="ltr">Thanks!<br><br><div>With this patch, a dynamically-linked "hello world" C program worked fine on my system. That's awesome!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 1, 2015 at 8:47 AM, 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 10:47:50 2015<br>
New Revision: 249025<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249025&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249025&view=rev</a><br>
Log:<br>
Copy DT_SONAME to DT_NEEDED.<br>
<br>
If a shared library has a DT_SONAME entry, that is what should be included<br>
in the DT_NEEDED of a program using it.<br>
<br>
We don't implement -soname yet, so check in a .so for now.<br>
<br>
Added:<br>
lld/trunk/test/elf2/Inputs/soname.so (with props)<br>
lld/trunk/test/elf2/soname.s<br>
Modified:<br>
lld/trunk/ELF/InputFiles.cpp<br>
lld/trunk/ELF/InputFiles.h<br>
lld/trunk/ELF/OutputSections.cpp<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=249025&r1=249024&r2=249025&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=249025&r1=249024&r2=249025&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Thu Oct 1 10:47:50 2015<br>
@@ -216,14 +216,39 @@ SharedFile<ELFT>::SharedFile(MemoryBuffe<br>
: SharedFileBase(getStaticELFKind<ELFT>(), M), ELFData<ELFT>(M) {}<br>
<br>
template <class ELFT> void SharedFile<ELFT>::parse() {<br>
- for (const Elf_Shdr &Sec : this->ELFObj.sections()) {<br>
- if (Sec.sh_type == SHT_DYNSYM) {<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>
+<br>
+ const ELFFile<ELFT> Obj = this->ELFObj;<br>
+ for (const Elf_Shdr &Sec : Obj.sections()) {<br>
+ uint32_t Type = Sec.sh_type;<br>
+ if (Type == SHT_DYNSYM)<br>
this->Symtab = &Sec;<br>
- break;<br>
- }<br>
+ else if (Type == SHT_DYNAMIC)<br>
+ DynamicSec = &Sec;<br>
}<br>
<br>
+ // Also sets StringTable<br>
Elf_Sym_Range Syms = this->getNonLocalSymbols();<br>
+ SoName = getName();<br>
+<br>
+ if (DynamicSec) {<br>
+ auto *Begin =<br>
+ reinterpret_cast<const Elf_Dyn *>(Obj.base() + DynamicSec->sh_offset);<br>
+ const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn);<br>
+<br>
+ for (const Elf_Dyn &Dyn : make_range(Begin, End)) {<br>
+ if (Dyn.d_tag == DT_SONAME) {<br>
+ uintX_t Val = Dyn.getVal();<br>
+ if (Val >= this->StringTable.size())<br>
+ error("Invalid DT_SONAME entry");<br>
+ SoName = StringRef(this->StringTable.data() + Val);<br>
+ break;<br>
+ }<br>
+ }<br>
+ }<br>
+<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=249025&r1=249024&r2=249025&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=249025&r1=249024&r2=249025&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.h (original)<br>
+++ lld/trunk/ELF/InputFiles.h Thu Oct 1 10:47:50 2015<br>
@@ -185,10 +185,14 @@ private:<br>
<br>
// .so file.<br>
class SharedFileBase : public ELFFileBase {<br>
+protected:<br>
+ StringRef SoName;<br>
+<br>
public:<br>
SharedFileBase(ELFKind EKind, MemoryBufferRef M)<br>
: ELFFileBase(SharedKind, EKind, M) {}<br>
static bool classof(const InputFile *F) { return F->kind() == SharedKind; }<br>
+ StringRef getSoName() const { return SoName; }<br>
};<br>
<br>
template <class ELFT><br>
<br>
Modified: lld/trunk/ELF/OutputSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249025&r1=249024&r2=249025&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249025&r1=249024&r2=249025&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.cpp Thu Oct 1 10:47:50 2015<br>
@@ -207,7 +207,7 @@ template <class ELFT> void DynamicSectio<br>
const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =<br>
SymTab.getSharedFiles();<br>
for (const std::unique_ptr<SharedFileBase> &File : SharedFiles)<br>
- DynStrSec.add(File->getName());<br>
+ DynStrSec.add(File->getSoName());<br>
NumEntries += SharedFiles.size();<br>
<br>
++NumEntries; // DT_NULL<br>
@@ -266,7 +266,7 @@ template <class ELFT> void DynamicSectio<br>
SymTab.getSharedFiles();<br>
for (const std::unique_ptr<SharedFileBase> &File : SharedFiles) {<br>
P->d_tag = DT_NEEDED;<br>
- P->d_un.d_val = DynStrSec.getFileOff(File->getName());<br>
+ P->d_un.d_val = DynStrSec.getFileOff(File->getSoName());<br>
++P;<br>
}<br>
<br>
<br>
Added: lld/trunk/test/elf2/Inputs/soname.so<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/Inputs/soname.so?rev=249025&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/Inputs/soname.so?rev=249025&view=auto</a><br>
==============================================================================<br>
Binary files lld/trunk/test/elf2/Inputs/soname.so (added) and lld/trunk/test/elf2/Inputs/soname.so Thu Oct 1 10:47:50 2015 differ<br>
<br>
Propchange: lld/trunk/test/elf2/Inputs/soname.so<br>
------------------------------------------------------------------------------<br>
svn:executable = *<br>
<br>
Added: lld/trunk/test/elf2/soname.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname.s?rev=249025&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname.s?rev=249025&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/soname.s (added)<br>
+++ lld/trunk/test/elf2/soname.s Thu Oct 1 10:47:50 2015<br>
@@ -0,0 +1,8 @@<br>
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o<br>
+// RUN: lld -flavor gnu2 %t.o %p/Inputs/soname.so -o %t<br>
+// RUN: llvm-readobj --dynamic-table %t | FileCheck %s<br>
+<br>
+// CHECK: 0x0000000000000001 NEEDED SharedLibrary (bar)<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>