<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 4, 2014 at 2:55 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

How would this work in ELF? In ELF all the pointer are in a single<br>
section, .init_array, so they cannot be in multiple comdats.</blockquote><div><br></div><div>I think it's OK to have multiple sections with the same name.  Won't the linker simply concatenate the multiple .init_array's during the link?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
> While the code as is doesn't put the initializer function into a comdat, why<br>
> do you think we can't do this?  It seems like it'd be a nice code size<br>
> optimization.  Right now the initializer function has internal linkage<br>
> because there is no mangling for it in Itanium, and we end up with lots of<br>
> unmerged duplicate code.<br>
><br>
> My plan for the future is to put both the initializer function and the guard<br>
> variable into the comdat group of the data being initialized using section<br>
> IR.  Then either GlobalOpt or Clang can replace the global with a constant,<br>
> so long as the initializer of the guard variable is updated.<br>
<br>
</div>If the function currently is not in a comdat, it should be safe.<br>
<br>
Now that I think of it, what will not work is putting the two<br>
variables in a comdat with the same name as the variable (as suggested<br>
in the ABI). It would break linking with old objects. For example, a<br>
new .o file would look like<br>
<br>
----------------------------------------------------------------<br>
.section .var, "G", @nobits, comdat_sym,comdat<br>
var:<br>
        .long 42<br>
.section .guard, "G", @nobits, comdat_sym,comdat<br>
guard:<br>
        .long 42<br>
<br>
.data<br>
        .quad guard<br>
----------------------------------------------------------------<br>
<br>
and an old one looks like<br>
<br>
----------------------------------------------------------------<br>
.section .var, "G", @nobits, comdat_sym,comdat<br>
var:<br>
        .long 42<br>
<br>
.section .guard, "G", @nobits, comdat_sym2,comdat<br>
guard:<br>
        .long 42<br>
------------------------------------------------------------------<br>
<br>
Depending on on the link order we get an warning and invalid output<br>
from the linker:<br>
<br>
warning: relocation refers to discarded section<br>
<br>
What is needed is a new comdat symbol name for both variable and<br>
guard, something like<br>
<br>
----------------------------------------------------------------------------<br>
.section .var, "G", @nobits, new_comdat_sym,comdat<br>
var:<br>
        .long 42<br>
.section .guard, "G", @nobits, new_comdat_sym,comdat<br>
guard:<br>
        .long 42<br>
.data<br>
        .quad guard<br>
-----------------------------------------------------------------------<br>
<br>
This is equivalent to using a *C5* comdat symbol to hold the *C1* and<br>
*C2* constructors.<br>
<br>
Should we report  a bug on the itanium abi?<br></blockquote><div><br></div><div>Yes.  Also, this completely breaks the intended design of the comdat key in global ctors, because now it needs to support an arbitrary symbol and not a specific GV.  Maybe we can find a way to replace this with an explicit section which will have the comdat, but I'll have to think of that later.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>