Joerg Sonnenberger
2014-Dec-08 17:09 UTC
[LLVMdev] [lld] Handling multiple -init/-fini command line options
On Mon, Dec 08, 2014 at 10:21:49AM -0600, Shankar Easwaran wrote:> The DT_INIT/DT_FINI correspond to one initializer function,where as > DT_INIT_ARRAY/DT_FINI_ARRAY is used when there is more than one > initalizer function/finalizer function respectively.This is not true. The difference is that the DT_INIT / DT_FINI function is responsible for calling into the .init / .fini block and for DT_INIT_ARRAY / DT_FINI_ARRAY, the block is explicitly defined as a list of pointers and it is the responsibility of either the CRT logic or the dynamic linker to call them. That said, I don't think more than one DT_INIT / DT_FINI entry should be allowed as the latter entry will overwrite the earlier ones. Joerg
Shankar Easwaran
2014-Dec-08 17:39 UTC
[LLVMdev] [lld] Handling multiple -init/-fini command line options
On 12/8/2014 11:09 AM, Joerg Sonnenberger wrote:> On Mon, Dec 08, 2014 at 10:21:49AM -0600, Shankar Easwaran wrote: >> The DT_INIT/DT_FINI correspond to one initializer function,where as >> DT_INIT_ARRAY/DT_FINI_ARRAY is used when there is more than one >> initalizer function/finalizer function respectively. > This is not true. The difference is that the DT_INIT / DT_FINI function > is responsible for calling into the .init / .fini block and for > DT_INIT_ARRAY / DT_FINI_ARRAY, the block is explicitly defined as a > list of pointers and it is the responsibility of either the CRT logic or > the dynamic linker to call them. > > That said, I don't think more than one DT_INIT / DT_FINI entry should be > allowed as the latter entry will overwrite the earlier ones.Thanks Joerg, The snip of code that appears to run the init/fini was easily browseable with musl. http://git.musl-libc.org/cgit/musl/tree/src/ldso/dynlink.c (function: do_init_fini). That said, all of the code is essentially under NO_LEGACY_INITFINI, is the linker responsible to convert DT_INIT to DT_INITARRAY's ? If so, I think more than one init/fini option should be converted to DT_INIT_ARRAY (or) DT_FINI_ARRAY respectively ? Shankar Easwaran -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation
Simon Atanasyan
2014-Dec-08 19:22 UTC
[LLVMdev] [lld] Handling multiple -init/-fini command line options
On Mon, Dec 8, 2014 at 8:39 PM, Shankar Easwaran <shankare at codeaurora.org> wrote:> On 12/8/2014 11:09 AM, Joerg Sonnenberger wrote: >> >> On Mon, Dec 08, 2014 at 10:21:49AM -0600, Shankar Easwaran wrote: >>> >>> The DT_INIT/DT_FINI correspond to one initializer function,where as >>> DT_INIT_ARRAY/DT_FINI_ARRAY is used when there is more than one >>> initalizer function/finalizer function respectively. >> >> This is not true. The difference is that the DT_INIT / DT_FINI function >> is responsible for calling into the .init / .fini block and for >> DT_INIT_ARRAY / DT_FINI_ARRAY, the block is explicitly defined as a >> list of pointers and it is the responsibility of either the CRT logic or >> the dynamic linker to call them. >> >> That said, I don't think more than one DT_INIT / DT_FINI entry should be >> allowed as the latter entry will overwrite the earlier ones. > > Thanks Joerg, The snip of code that appears to run the init/fini was easily > browseable with musl. > > http://git.musl-libc.org/cgit/musl/tree/src/ldso/dynlink.c (function: > do_init_fini). > > That said, all of the code is essentially under NO_LEGACY_INITFINI, is the > linker responsible to convert DT_INIT to DT_INITARRAY's ? > > If so, I think more than one init/fini option should be converted to > DT_INIT_ARRAY (or) DT_FINI_ARRAY respectively ?By the way, gnu linker support both DT_INIT and DT_INIT_ARRAY tags at the same time. For example, if input objects contain .init_array section and _init symbol, gnu linker emits both DT_INIT and DT_INIT_ARRAY tags. And I still do not see any reason to assign more complicated semantic to the -init/-fini options and introduce incompatibility with gnu linker. -- Simon Atanasyan
Joerg Sonnenberger
2014-Dec-08 20:20 UTC
[LLVMdev] [lld] Handling multiple -init/-fini command line options
On Mon, Dec 08, 2014 at 11:39:01AM -0600, Shankar Easwaran wrote:> That said, all of the code is essentially under NO_LEGACY_INITFINI, > is the linker responsible to convert DT_INIT to DT_INITARRAY's ?No. It can't do that. There are some non-trivial differences in the semantics of the two.> If so, I think more than one init/fini option should be converted to > DT_INIT_ARRAY (or) DT_FINI_ARRAY respectively ?No, the GNU behavior is correct here. Only one DT_INIT and one DT_FINI should be written and the last option should win. It is like the dynamic linker path in this regard. Joerg