<br><br>On Friday, 12 February 2016, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 10, 2016 at 11:08 PM, Simon Atanasyan <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','simon@atanasyan.com');" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">atanasyan added a comment.<br>
<br>
GNU ld 2.22 has the following default linker script for `.ctors/.dtors` sections. I am sure that other versions have the same declarations.<br>
<br>
  .ctors          :<br>
  {<br>
    KEEP (*crtbegin.o(.ctors))<br>
    KEEP (*crtbegin?.o(.ctors))<br>
    /* We don't want to include the .ctor section from<br>
       the crtend.o file until after the sorted ctors.<br>
       The .ctor section from the crtend file contains the<br>
       end of ctors marker and it must be last */<br>
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))<br>
    KEEP (*(SORT(.ctors.*)))<br>
    KEEP (*(.ctors))<br>
  }<br>
  .dtors          :<br>
  {<br>
    KEEP (*crtbegin.o(.dtors))<br>
    KEEP (*crtbegin?.o(.dtors))<br>
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))<br>
    KEEP (*(SORT(.dtors.*)))<br>
    KEEP (*(.dtors))<br>
  }<br>
<br>
So the order should be follow:<br>
<br>
1. .ctors section from *crtbegin.o<br>
2. .ctors section from *crtbegin?.o<br>
3. .ctors sections from other object files except *crtend.o and *crtend?.o<br>
4. .ctors.* from any files sorted by priority<br>
5. .ctors sections from *crtend.o and *crtend?.o<br></blockquote><div> </div><div>I think my patch implements that order except it doesn't distinguish case 1 and 2, which is not significant I believe.</div></div></div></div></blockquote><div><br></div><div>But in the test case first bytes are c1 and c2 which come from <span style="background-color:rgba(255,255,255,0);font-size:small">ctors_dtors_priority3.s which becomes </span><font size="2"><span style="background-color:rgba(255,255,255,0)"> %t-crtend.o. Am I miss something?</span></font></div><br><br>-- <br>Simon Atanasyan<br>