<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Correctly handle weak references to DSO symbols which do not appear in DT_NEEDED because of --as-needed"
href="https://llvm.org/bugs/show_bug.cgi?id=28335">28335</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Correctly handle weak references to DSO symbols which do not appear in DT_NEEDED because of --as-needed
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>peter@pcc.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider:
declare extern_weak i32 @__pthread_key_create(i32*, void (i8*)*)
(a symbol defined in libpthread)
then later:
br i1 icmp ne (i8* bitcast (i32 (i32*, void (i8*)*)* @__pthread_key_create to
i8*), i8* null), label %if.then.i.i.i, label %if.else.i.i.i
In a non-PIC object, the reference to __pthread_key_create does not go via the
GOT. As a result the static linker needs to create a "pseudo PLT" entry for
__pthread_key_create. This entry is used by the dynamic loader as the canonical
address of __pthread_key_create.
The documented behavior of --as-needed is that if all references to a DSO are
weak, the DSO does not appear in DT_NEEDED. However, this currently does not
affect whether we emit the pseudo PLT entry. As a result, the symbol
__pthread_key_create will be resolved to non-zero regardless of whether
libpthread is dynamically linked, and code which tests the address of
__pthread_key_create to determine whether libpthread was dynamically linked
will get the wrong result.
I see three possible solutions:
1) Treat weak references to non-needed DSOs as non-preemptible. This allows the
static linker to resolve references to zero and will inhibit the creation of a
pseudo PLT entry.
2) Change how we handle --as-needed: any symbol reference no matter the binding
will cause a DT_NEEDED entry to be created. This would be a divergence from the
documented behavior of --as-needed.
3) Treat a copy relocation or a pseudo PLT entry for a symbol as a "use" of
that symbol. That would force the linker to emit a DT_NEEDED for its DSO.
Either 1 or 3 seem like good solutions to me. I'll try implementing 3 first of
all.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>