GNU ld and -init/-fini

Ian Lance Taylor ian@zembu.com
Thu Jul 1 00:00:00 GMT 1999


   From: mark@codesourcery.com
   Date: Mon, 21 Jun 1999 16:09:57 -0700

   The IRIX 6 linker provdides -init and -fini switches.  These switches
   set DT_INIT and DT_FINI flags in the dynamic table, which cause the
   named functions to be executed at initialization/finalization time.
   GCC uses these to call global constructors when a shared library is
   loaded.

   There do not seem to be equivalent GNU ld switches.  What is the
   method used on Linux, etc. in order to make the same sort of thing
   happen?

As Richard said, the GNU linker recognizes _init and _fini specially.
It sets DT_INIT to the value of the _init symbol, and sets DT_FINI to
the value of the _fini symbol.  This convention was taken from SVR4,
and indeed it is required in order to work on SVR4 and Solaris.

I think it would be appropriate to add -init and -fini options to work
for any ELF target, and permit them to override the default of _init
and _fini.

Ian


More information about the Binutils mailing list