Blame elf/soinit.c

Packit 6c4009
/* Initializer module for building the ELF shared C library.  This file and
Packit 6c4009
   sofini.c do the work normally done by crtbeginS.o and crtendS.o, to wrap
Packit 6c4009
   the `.ctors' and `.dtors' sections so the lists are terminated, and
Packit 6c4009
   calling those lists of functions.  */
Packit 6c4009
Packit 6c4009
#ifndef NO_CTORS_DTORS_SECTIONS
Packit 6c4009
# include <stdlib.h>
Packit 6c4009
Packit 6c4009
static void (*const __CTOR_LIST__[1]) (void)
Packit 6c4009
  __attribute__ ((used, section (".ctors")))
Packit 6c4009
  = { (void (*) (void)) -1 };
Packit 6c4009
static void (*const __DTOR_LIST__[1]) (void)
Packit 6c4009
  __attribute__ ((used, section (".dtors")))
Packit 6c4009
  = { (void (*) (void)) -1 };
Packit 6c4009
Packit 6c4009
static inline void
Packit 6c4009
run_hooks (void (*const list[]) (void))
Packit 6c4009
{
Packit 6c4009
  while (*++list)
Packit 6c4009
    (**list) ();
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* This function will be called from _init in init-first.c.  */
Packit 6c4009
void
Packit 6c4009
__libc_global_ctors (void)
Packit 6c4009
{
Packit 6c4009
  /* Call constructor functions.  */
Packit 6c4009
  run_hooks (__CTOR_LIST__);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* This function becomes the DT_FINI termination function
Packit 6c4009
   for the C library.  */
Packit 6c4009
void
Packit 6c4009
__libc_fini (void)
Packit 6c4009
{
Packit 6c4009
  /* Call destructor functions.  */
Packit 6c4009
  run_hooks (__DTOR_LIST__);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
Packit 6c4009
     = &__libc_fini;
Packit 6c4009
#endif