1/* Initializer module for building the ELF shared C library. This file and
2 sofini.c do the work normally done by crtbeginS.o and crtendS.o, to wrap
3 the `.ctors' and `.dtors' sections so the lists are terminated, and
4 calling those lists of functions. */
5
6#ifndef NO_CTORS_DTORS_SECTIONS
7# include <libc-internal.h>
8# include <stdlib.h>
9
10static void (*const __CTOR_LIST__[1]) (void)
11 __attribute__ ((used, section (".ctors")))
12 = { (void (*) (void)) -1 };
13static void (*const __DTOR_LIST__[1]) (void)
14 __attribute__ ((used, section (".dtors")))
15 = { (void (*) (void)) -1 };
16
17static inline void
18run_hooks (void (*const list[]) (void))
19{
20 while (*++list)
21 (**list) ();
22}
23
24/* This function will be called from _init in init-first.c. */
25void
26__libc_global_ctors (void)
27{
28 /* Call constructor functions. */
29 run_hooks (__CTOR_LIST__);
30}
31
32
33/* This function becomes the DT_FINI termination function
34 for the C library. */
35void
36__libc_fini (void)
37{
38 /* Call destructor functions. */
39 run_hooks (__DTOR_LIST__);
40}
41
42void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
43 = &__libc_fini;
44#endif
45