* include/errno.h [__cplusplus]: Avoid extra header magic for C++.
[glibc.git] / elf / soinit.c
blob29e4707cebcc3d6f33543aeea0d148a65a0fcef4
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
82 __libc_fini (void)
84 /* Call destructor functions. */
85 run_hooks (__DTOR_LIST__);
86 #ifdef HAVE_DWARF2_UNWIND_INFO
87 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
88 # if defined CRT_GET_RFIB_TEXT || defined CRT_GET_RFIB_DATA
89 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
90 # else
91 __deregister_frame_info (__EH_FRAME_BEGIN__);
92 # endif
93 # else
94 __deregister_frame (__EH_FRAME_BEGIN__);
95 # endif
96 #endif
99 void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
100 = &__libc_fini;