<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 - GC Optimization incorrectly determines when to keep init-sections"
href="https://bugs.llvm.org/show_bug.cgi?id=48156">48156</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>GC Optimization incorrectly determines when to keep init-sections
</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>All
</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>wasm
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>trybka@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, sbc@chromium.org
</td>
</tr></table>
<p>
<div>
<pre>I believe the optimization added here (<a href="https://reviews.llvm.org/D85062">https://reviews.llvm.org/D85062</a>) has an
error which was revealed after <a href="https://reviews.llvm.org/D89290">https://reviews.llvm.org/D89290</a>.
Fairly small example here:
<a href="https://github.com/trybka/scraps/tree/master/lld-test">https://github.com/trybka/scraps/tree/master/lld-test</a>
Depending on the link order, the `bug::Foo` object is never initialized in
`foo.cc`.
I believe this is due to an error in the logic in MarkLive.cpp and Symbols.cpp.
In MarkLive.cpp enqueue:
<a href="https://github.com/llvm/llvm-project/blob/dd8723d348c9e6182155233a62769024dd345c6b/lld/wasm/MarkLive.cpp#L62">https://github.com/llvm/llvm-project/blob/dd8723d348c9e6182155233a62769024dd345c6b/lld/wasm/MarkLive.cpp#L62</a>
The check `bool needInitFunctions = file && !file->isLive() &&
sym->isDefined();`
will be False for an undefined symbol.
However, when the symbol is marked live, it sets its file to live as well. In
the case of an undefined symbol, that is the wrong file.
Subsequent queued symbols actually in that file will then fail the
needInitFunctions check (as they are already apparently live) and so the init
is never added.
In the example above, __cxa_atexit would be undefined in foo.o. When marking
__cxa_atexit as "referenced", foo.o would be marked live, but the init is never
added.</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>