<html>
<head>
<base href="http://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 --- - [-cxx-abi microsoft] dynamic initializers for linkonce_odr data run twice when linking clang and MSVC code"
href="http://llvm.org/bugs/show_bug.cgi?id=16959">16959</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[-cxx-abi microsoft] dynamic initializers for linkonce_odr data run twice when linking clang and MSVC code
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Depends on</th>
<td>16888
</td>
</tr>
<tr>
<th>Blocks</th>
<td>12477
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=11080" name="attach_11080" title="double initialization test case">attachment 11080</a> <a href="attachment.cgi?id=11080&action=edit" title="double initialization test case">[details]</a></span>
double initialization test case
The attached test case fails when built with and without -DCONFIG_1 while
mixing compilers.
The Microsoft ABI does *not* use guard variables to avoid double initialization
of linkonce_odr data, but my fix for PR16888 does.
What's supposed to happen is something like the following:
---
.CRT$XCU is a section similar to .init_array on Linux / ELF, an array of void
function pointers.
Each TU with a weak initializer emits two symbols:
void ("?__E" <data>)(void)
void (* <data> "$initializer$")(void)
The __E symbol is the initializer code stub goes into the usual COMDAT
selectany text section, the way we would emit any inline function.
The $initializer$ symbol goes into a .CRT$XCU COMDAT section with the
IMAGE_COMDAT_SELECT_ASSOCIATIVE flag, where it is associated with the __E
symbol.
This way, the linker picks one __E symbol, and then throws away all the
associated function pointers that would have referenced it, thereby leaving
only one call to the initializer.
---
Currently clang orders initializers within a TU by creating one giant function
(__GLOBAL_I_a etc) that calls each initializer stub in turn. This means that
we can't perform COMDAT elimination on the function pointers in .CRT$XCU.
The LLVM LangRef says that initializers in llvm.global_ctors with the same
priority are not ordered, but I wonder if we could loosen that initializers
with the same priority in a single TU are called in the order defined by the
global_ctors array.
With that change, I don't think clang would need to emit __GLOBAL_I_*
functions. Are there any known object file formats or platforms where the
linker would violate that guarantee?</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>