Update.
[glibc.git] / elf / soinit.c
blob1dee73c3be37a5a888fd4d0ff06aa4d81cf82261
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 static void (*const __CTOR_LIST__[1]) (void)
7 __attribute__ ((section (".ctors")))
8 = { (void (*) (void)) -1 };
9 static void (*const __DTOR_LIST__[1]) (void)
10 __attribute__ ((section (".dtors")))
11 = { (void (*) (void)) -1 };
13 static inline void
14 run_hooks (void (*const list[]) (void))
16 while (*++list)
17 (**list) ();
20 #ifdef HAVE_DWARF2_UNWIND_INFO
21 static char __EH_FRAME_BEGIN__[]
22 __attribute__ ((section (".eh_frame")))
23 = { };
24 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
25 /* This must match what's in frame.h in gcc. How can one do that? */
26 struct object
28 void *pc_begin;
29 void *pc_end;
30 void *fde_begin;
31 void *fde_array;
32 __SIZE_TYPE__ count;
33 struct object *next;
35 extern void __register_frame_info (const void *, struct object *);
36 extern void __deregister_frame_info (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__);
49 #ifdef HAVE_DWARF2_UNWIND_INFO
50 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
52 static struct object ob;
53 __register_frame_info (__EH_FRAME_BEGIN__, &ob);
55 # else
56 __register_frame (__EH_FRAME_BEGIN__);
57 # endif
58 #endif
62 /* This function becomes the DT_FINI termination function
63 for the C library. */
64 void _fini (void) __attribute__ ((section (".fini"))); /* Just for kicks. */
65 void
66 _fini (void)
68 /* Call destructor functions. */
69 run_hooks (__DTOR_LIST__);
70 #ifdef HAVE_DWARF2_UNWIND_INFO
71 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
72 __deregister_frame_info (__EH_FRAME_BEGIN__);
73 # else
74 __deregister_frame (__EH_FRAME_BEGIN__);
75 # endif
76 #endif