Back to index

glibc  2.9
soinit.c
Go to the documentation of this file.
00001 /* Initializer module for building the ELF shared C library.  This file and
00002    sofini.c do the work normally done by crtbeginS.o and crtendS.o, to wrap
00003    the `.ctors' and `.dtors' sections so the lists are terminated, and
00004    calling those lists of functions.  */
00005 
00006 #include <libc-internal.h>
00007 #include <stdlib.h>
00008 
00009 static void (*const __CTOR_LIST__[1]) (void)
00010      __attribute__ ((section (".ctors")))
00011      = { (void (*) (void)) -1 };
00012 static void (*const __DTOR_LIST__[1]) (void)
00013      __attribute__ ((section (".dtors")))
00014      = { (void (*) (void)) -1 };
00015 
00016 static inline void
00017 run_hooks (void (*const list[]) (void))
00018 {
00019   while (*++list)
00020     (**list) ();
00021 }
00022 
00023 /* This function will be called from _init in init-first.c.  */
00024 void
00025 __libc_global_ctors (void)
00026 {
00027   /* Call constructor functions.  */
00028   run_hooks (__CTOR_LIST__);
00029 }
00030 
00031 
00032 /* This function becomes the DT_FINI termination function
00033    for the C library.  */
00034 void
00035 __libc_fini (void)
00036 {
00037   /* Call destructor functions.  */
00038   run_hooks (__DTOR_LIST__);
00039 }
00040 
00041 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
00042      = &__libc_fini;