Don't crash when dependencies are missing
[glibc.git] / elf / soinit.c
blob76033ea90c65f7b65e4d22471c22eb0cea6be570
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. */
6 #ifndef NO_CTORS_DTORS_SECTIONS
7 # include <libc-internal.h>
8 # include <stdlib.h>
10 static void (*const __CTOR_LIST__[1]) (void)
11 __attribute__ ((section (".ctors")))
12 = { (void (*) (void)) -1 };
13 static void (*const __DTOR_LIST__[1]) (void)
14 __attribute__ ((section (".dtors")))
15 = { (void (*) (void)) -1 };
17 static inline void
18 run_hooks (void (*const list[]) (void))
20 while (*++list)
21 (**list) ();
24 /* This function will be called from _init in init-first.c. */
25 void
26 __libc_global_ctors (void)
28 /* Call constructor functions. */
29 run_hooks (__CTOR_LIST__);
33 /* This function becomes the DT_FINI termination function
34 for the C library. */
35 void
36 __libc_fini (void)
38 /* Call destructor functions. */
39 run_hooks (__DTOR_LIST__);
42 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
43 = &__libc_fini;
44 #endif