Update.
[glibc.git] / elf / soinit.c
blob32ed4454b5f0434b938d3b2bb437270c5c6659fc
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 void _fini (void) __attribute__ ((section (".fini"))); /* Just for kicks. */
82 void
83 _fini (void)
85 /* Call destructor functions. */
86 run_hooks (__DTOR_LIST__);
87 #ifdef HAVE_DWARF2_UNWIND_INFO
88 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
89 # if defined CRT_GET_RFIB_TEXT || defined CRT_GET_RFIB_DATA
90 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
91 # else
92 __deregister_frame_info (__EH_FRAME_BEGIN__);
93 # endif
94 # else
95 __deregister_frame (__EH_FRAME_BEGIN__);
96 # endif
97 #endif