<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 - LTO COMDAT elimination can eliminate prevailing symbols"
href="https://bugs.llvm.org/show_bug.cgi?id=40202">40202</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LTO COMDAT elimination can eliminate prevailing symbols
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>7.0
</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>Linker
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>CFSworks@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=21283" name="attach_21283" title="A minimal example project that crashes Clang">attachment 21283</a> <a href="attachment.cgi?id=21283&action=edit" title="A minimal example project that crashes Clang">[details]</a></span>
A minimal example project that crashes Clang
I've attached an example project that demonstrates this bug. When building it
(w/ make), the following error is reported:
Alias must point to a definition
void (%class.X*)* @_ZN1XIiED1Ev
LLVM ERROR: Broken module found, compilation aborted!
---
As I understand it, what's happening is:
common.h contains a template class X (which, being a template, is subject to
instantiation in multiple translation units under the ODR) with a virtual
destructor and a base class with a destructor of its own. This means that the
class would contain the complete set of D0, D1, and D2 destructors.
b.cpp performs an explicit instantiation of X<int> - so b.o contains all 3
destructors (grouped under the D5 COMDAT).
a.cpp contains an inline (due to -O1) copy of the X<int> constructor, which
means a.o contains a copy of X<int>'s vtable and X<int>'s D0 destructor.
When it comes time to link, if a.o's D0 symbol prevails over b.o's copy of the
same, <a href="https://reviews.llvm.org/D34803">https://reviews.llvm.org/D34803</a> means that the entire D5 COMDAT from b.o
must be eliminated. This happens by converting all affected symbols to
available_externally linkage and deleting the COMDAT.
The crash, as seen, is caused by the fact that D1 is an alias of D2, and the
logic that eliminates the COMDAT doesn't check if D2 is an aliasee first.
However, just handling aliased symbols isn't good enough here: even if D1 was a
full definition rather than an alias, then COMDAT elimination would mean that
the prevailing copies of the D1/D2 destructors aren't getting included in the
output binary. This negates the whole purpose of the explicit instantiation in
b.cpp (a user of the shared library might be relying on that instantiation),
and could even result in a broken binary if b.cpp contained a non-inline call
to D1/D2.</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>