<p dir="ltr">If we want to be able to add functions to init_array using command line we can introduce new options like -init-array / -fini-array</p>
<div class="gmail_quote">On Dec 8, 2014 10:22 PM, "Simon Atanasyan" <<a href="mailto:simon@atanasyan.com">simon@atanasyan.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Dec 8, 2014 at 8:39 PM, Shankar Easwaran<br>
<<a href="mailto:shankare@codeaurora.org">shankare@codeaurora.org</a>> wrote:<br>
> On 12/8/2014 11:09 AM, Joerg Sonnenberger wrote:<br>
>><br>
>> On Mon, Dec 08, 2014 at 10:21:49AM -0600, Shankar Easwaran wrote:<br>
>>><br>
>>> The DT_INIT/DT_FINI correspond to one initializer function,where as<br>
>>> DT_INIT_ARRAY/DT_FINI_ARRAY is used when there is more than one<br>
>>> initalizer function/finalizer function respectively.<br>
>><br>
>> This is not true. The difference is that the DT_INIT / DT_FINI function<br>
>> is responsible for calling into the .init / .fini block and for<br>
>> DT_INIT_ARRAY / DT_FINI_ARRAY, the block is explicitly defined as a<br>
>> list of pointers and it is the responsibility of either the CRT logic or<br>
>> the dynamic linker to call them.<br>
>><br>
>> That said, I don't think more than one DT_INIT / DT_FINI entry should be<br>
>> allowed as the latter entry will overwrite the earlier ones.<br>
><br>
> Thanks Joerg, The snip of code that appears to run the init/fini was easily<br>
> browseable with musl.<br>
><br>
> <a href="http://git.musl-libc.org/cgit/musl/tree/src/ldso/dynlink.c" target="_blank">http://git.musl-libc.org/cgit/musl/tree/src/ldso/dynlink.c</a> (function:<br>
> do_init_fini).<br>
><br>
> That said, all of the code is essentially under NO_LEGACY_INITFINI, is the<br>
> linker responsible to convert DT_INIT to DT_INITARRAY's ?<br>
><br>
> If so, I think more than one init/fini option should be converted to<br>
> DT_INIT_ARRAY (or) DT_FINI_ARRAY respectively ?<br>
<br>
By the way, gnu linker support both DT_INIT and DT_INIT_ARRAY tags at<br>
the same time. For example, if input objects contain .init_array<br>
section and _init symbol, gnu linker emits both DT_INIT and<br>
DT_INIT_ARRAY tags. And I still do not see any reason to assign more<br>
complicated semantic to the -init/-fini options and introduce<br>
incompatibility with gnu linker.<br>
<br>
--<br>
Simon Atanasyan<br>
</blockquote></div>