]>
Commit | Line | Data |
---|---|---|
0324daa0 RM |
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 | ||
4a531bb0 | 6 | #ifndef NO_CTORS_DTORS_SECTIONS |
8bdf4e6e UD |
7 | # include <libc-internal.h> |
8 | # include <stdlib.h> | |
66539a73 | 9 | |
0324daa0 | 10 | static void (*const __CTOR_LIST__[1]) (void) |
78a7eee7 RM |
11 | __attribute__ ((used, section (".ctors"))) |
12 | = { (void (*) (void)) -1 }; | |
0324daa0 | 13 | static void (*const __DTOR_LIST__[1]) (void) |
78a7eee7 RM |
14 | __attribute__ ((used, section (".dtors"))) |
15 | = { (void (*) (void)) -1 }; | |
0324daa0 RM |
16 | |
17 | static inline void | |
18 | run_hooks (void (*const list[]) (void)) | |
19 | { | |
20 | while (*++list) | |
21 | (**list) (); | |
22 | } | |
23 | ||
0324daa0 RM |
24 | /* This function will be called from _init in init-first.c. */ |
25 | void | |
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. */ | |
6def43e6 UD |
35 | void |
36 | __libc_fini (void) | |
0324daa0 RM |
37 | { |
38 | /* Call destructor functions. */ | |
39 | run_hooks (__DTOR_LIST__); | |
40 | } | |
ce33ee7c | 41 | |
6def43e6 UD |
42 | void (*_fini_ptr) (void) __attribute__ ((section (".fini_array"))) |
43 | = &__libc_fini; | |
4a531bb0 | 44 | #endif |