<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="mailto: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>