<div dir="ltr">On Wed, Sep 4, 2013 at 4:11 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span> wrote:<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Even today, every global with a dynamic initializer gets its own void()<br>
initialization function.  We don't use a single function to initialize everything.<br>
</blockquote>
<br></div>
OK, thanks for explaining.  In that case, will multiple instances of the same<br>
global (the ones you want to eliminate) have the same initialization function?<br></blockquote><div><br></div><div>For the Microsoft C++ ABI, yes, they use the same mangling (?__E*) and are linkonce_odr.</div><div><br></div>
<div>For the Itanium C++ ABI, no, they are all internal and hence different.  It uses a guard variable to avoid double initialization.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

If so, then I guess right now, without your changes, llvm.global_ctors will<br>
have multiple copies of the same function.  Then instead of introducing a third<br>
"global variable" i8* field in llvm.global_ctors, there could instead by a<br>
third boolean field meaning: collapse multiple instances of this initialization<br>
function.  In fact, maybe it is always OK to remove duplicate initialization<br>
functions in llvm.global_ctors?<br></blockquote><div><br></div><div>Richard and I considered this, but cl.exe associates the .CRT$XCU function pointer with the global, and not the initializer function.  I could try to recover the name of the global from the name of the initializer, but this seems fairly terrible, and possibly invalid in the face of GlobalOpt.<br>
</div><div><br></div><div>Consider a constructor which does nothing but tail call to 'void foo()'.  It should be valid to make the .CRT$XCU function pointer point directly to foo and delete the initializer.  We could outlaw this optimization when the unique bit is set, but then I still have to recover the global's symbol to get the MS C++ ABI right.<br>
</div><div><br></div><div>That said, if I only needed one bit, I could steal it from the i32 priority field which only uses 16 bits.  =D</div></div></div></div>