<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - wasm-ld satisfies weak external from archive"
href="https://bugs.llvm.org/show_bug.cgi?id=43696">43696</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>wasm-ld satisfies weak external from archive
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Other
</td>
</tr>
<tr>
<th>OS</th>
<td>other
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>wasm
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dan433584@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, sbc@chromium.org
</td>
</tr></table>
<p>
<div>
<pre>wasm-ld (in LLVM 9.0) is pulling in symbols from an archive to satisfy weak
external references, which is different from what ELF linkers do, and precludes
a common use case.
Consider this testcase:
```c
#include <stdio.h>
extern int x __attribute__((weak));
int main(void) {
if (&x) {
printf("we have x: %d\n", x);
}
return 0;
}
```
This shouldn't cause `x` to be linked by itself, because `x` is weak, even if
`x` is available in an archive library. But if I create an archive library
containing this:
```c
int x = 42;
```
then `x` does get linked.
With the above snippets in a.c and b.c respectively, this command-line
reproduces the issue with wasi-sdk (clang configured to target wasm32 by
default):
$ clang -c b.c && llvm-ar crs b.a b.o && clang a.c b.a -Wl,-y,x
/tmp/a-5e48c9.o: reference to x
b.a: lazy definition of x
For comparison, on an ELF target, I get this:
$ clang -c b.c && llvm-ar crs b.a b.o && clang a.c b.a -Wl,-y,x
/tmp/a-4c66f3.o: reference to x</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>