Subject: Re: dynamic linker support for .preinit_array
To: Jason Thorpe <thorpej@shagadelic.org>
From: Ian Lance Taylor <ian@airs.com>
List: tech-toolchain
Date: 07/18/2005 09:48:15
Jason Thorpe <thorpej@shagadelic.org> writes:

> On Jul 18, 2005, at 3:49 AM, Ben Elliston wrote:
> 
> > Sorry if this is the wrong place to ask (if so, please point me in the
> > right direction).  Does NetBSD's dynamic linker support ELF
> > .preinit_array and .fini_array sections?  GNU ld has recently added
> > support for them, but the tests for such are failing on my NetBSD/i386
> > 1.6 system.
> 
> No, AFAIK our ld.elf_so has no support for those sections.
> 
> What do those sections do?

There are like .init and .fini, except that instead of being a
function which the dynamic linker should call, they are an array of
function pointers, and the dynamic linker should call each one in
order.  The .fini_array pointers are called in reverse order.

There is also .init_array, which is the same except that the functions
are called after .init is called.  .preinit_array functions are called
before .init is called.  .fini_array is called before .fini.  For some
reason nobody has invented .postfini_array.

There are section types to go with these:

#define SHT_INIT_ARRAY	  14		/* Array of ptrs to init functions */
#define SHT_FINI_ARRAY	  15		/* Array of ptrs to finish functions */
#define SHT_PREINIT_ARRAY 16		/* Array of ptrs to pre-init funcs */

as well as dynamic tags for the dynamic linker:

#define DT_INIT_ARRAY	25
#define DT_FINI_ARRAY	26
#define DT_INIT_ARRAYSZ 27
#define DT_FINI_ARRAYSZ 28
#define DT_PREINIT_ARRAY   32
#define DT_PREINIT_ARRAYSZ 33

Ian