Updated.
[glibc.git] / elf / soinit.c
blobff65af4a36aee212f1f1ee40afa565b2bbffe17e
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>
8 #ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
9 # include <gccframe.h>
10 #endif
12 static void (*const __CTOR_LIST__[1]) (void)
13 __attribute__ ((section (".ctors")))
14 = { (void (*) (void)) -1 };
15 static void (*const __DTOR_LIST__[1]) (void)
16 __attribute__ ((section (".dtors")))
17 = { (void (*) (void)) -1 };
19 static inline void
20 run_hooks (void (*const list[]) (void))
22 while (*++list)
23 (**list) ();
26 #ifdef HAVE_DWARF2_UNWIND_INFO
27 static char __EH_FRAME_BEGIN__[]
28 __attribute__ ((section (".eh_frame")))
29 = { };
30 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
31 extern void __register_frame_info (const void *, struct object *);
32 extern void __deregister_frame_info (const void *);
33 # else
34 extern void __register_frame (const void *);
35 extern void __deregister_frame (const void *);
36 # endif
37 #endif
39 /* This function will be called from _init in init-first.c. */
40 void
41 __libc_global_ctors (void)
43 /* Call constructor functions. */
44 run_hooks (__CTOR_LIST__);
46 #ifdef HAVE_DWARF2_UNWIND_INFO
47 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
49 static struct object ob;
50 __register_frame_info (__EH_FRAME_BEGIN__, &ob);
52 # else
53 __register_frame (__EH_FRAME_BEGIN__);
54 # endif
55 #endif
59 /* This function becomes the DT_FINI termination function
60 for the C library. */
61 void _fini (void) __attribute__ ((section (".fini"))); /* Just for kicks. */
62 void
63 _fini (void)
65 /* Call destructor functions. */
66 run_hooks (__DTOR_LIST__);
67 #ifdef HAVE_DWARF2_UNWIND_INFO
68 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
69 __deregister_frame_info (__EH_FRAME_BEGIN__);
70 # else
71 __deregister_frame (__EH_FRAME_BEGIN__);
72 # endif
73 #endif