This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: necessity of .init section !!
ashwani raina <ashwani.raina@gmail.com> writes:
> Is it necessary to have .init section in an ELF ( especially
> shared object) ?
The .init section is not necessary. There is nothing special about
the .init section.
> Because I have seen the ELF which has no .init section ? Also is it
> possible to have a my code in .init section which should be executed
> before control goes to main ..because i wanted to debug my executable.
To have code executed before main, you want to set a DT_INIT,
DT_INIT_ARRAY or DT_PREINIT_ARRAY entry in the dynamic tags (if you
are doing a static link, there is no way to force code to be executed
before main; DT_PREINIT_ARRAY is only permitted in an executable, not
in a shared library). The dynamic linker ld.so will look for DT_INIT,
DT_INIT_ARRAY, or DT_PREINIT_ARRAY and invoke the code to which it
points.
By default the GNU linker will set DT_INIT to the address of a
function named "_init", if there is one. See the -init option. And
by default the GNU linker will set DT_INIT_ARRAY to the address of a
section named ".init_array", if there is one.
Ian