Update.
[glibc.git] / elf / soinit.c
blob2015ea2d66265dc64b4d3964c215bb343abbfa4e
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 #include <libc-internal.h>
7 #include <stdlib.h>
9 #ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
10 # include <gccframe.h>
11 #endif
13 static void (*const __CTOR_LIST__[1]) (void)
14 __attribute__ ((section (".ctors")))
15 = { (void (*) (void)) -1 };
16 static void (*const __DTOR_LIST__[1]) (void)
17 __attribute__ ((section (".dtors")))
18 = { (void (*) (void)) -1 };
20 static inline void
21 run_hooks (void (*const list[]) (void))
23 while (*++list)
24 (**list) ();
27 #ifdef HAVE_DWARF2_UNWIND_INFO
28 static char __EH_FRAME_BEGIN__[]
29 __attribute__ ((section (".eh_frame")))
30 = { };
31 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
32 extern void __register_frame_info (const void *, struct object *);
33 extern void __register_frame_info_bases (const void *, struct object *,
34 void *, void *);
35 extern void __deregister_frame_info (const void *);
36 extern void __deregister_frame_info_bases (const void *);
37 # else
38 extern void __register_frame (const void *);
39 extern void __deregister_frame (const void *);
40 # endif
41 #endif
43 /* This function will be called from _init in init-first.c. */
44 void
45 __libc_global_ctors (void)
47 /* Call constructor functions. */
48 run_hooks (__CTOR_LIST__);
50 #ifdef HAVE_DWARF2_UNWIND_INFO
51 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
53 static struct object ob;
54 # if defined CRT_GET_RFIB_TEXT || defined CRT_GET_RFIB_DATA
55 void *tbase, *dbase;
57 # ifdef CRT_GET_RFIB_TEXT
58 CRT_GET_RFIB_TEXT (tbase);
59 # else
60 tbase = NULL;
61 # endif
62 # ifdef CRT_GET_RFIB_DATA
63 CRT_GET_RFIB_DATA (dbase);
64 # else
65 dbase = NULL;
66 # endif
67 __register_frame_info_bases (__EH_FRAME_BEGIN__, &ob, tbase, dbase);
68 # else
69 __register_frame_info (__EH_FRAME_BEGIN__, &ob);
70 # endif
72 # else
73 __register_frame (__EH_FRAME_BEGIN__);
74 # endif
75 #endif
79 /* This function becomes the DT_FINI termination function
80 for the C library. */
81 #ifndef HAVE_INITFINI_ARRAY
82 void _fini (void) __attribute__ ((section (".fini"))); /* Just for kicks. */
83 void
84 _fini (void)
85 #else
86 void
87 __libc_fini (void)
88 #endif
90 /* Call destructor functions. */
91 run_hooks (__DTOR_LIST__);
92 #ifdef HAVE_DWARF2_UNWIND_INFO
93 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
94 # if defined CRT_GET_RFIB_TEXT || defined CRT_GET_RFIB_DATA
95 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
96 # else
97 __deregister_frame_info (__EH_FRAME_BEGIN__);
98 # endif
99 # else
100 __deregister_frame (__EH_FRAME_BEGIN__);
101 # endif
102 #endif
104 #ifdef HAVE_INITFINI_ARRAY
105 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
106 = &__libc_fini;
107 #endif