Update.
[glibc.git] / elf / soinit.c
blob3cb5584f6c44a101a86e18ea5f9155f42ae57f7b
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 /* We have to initialize the thread library at least if bit. */
44 extern void __pthread_initialize_minimal (void) __attribute__ ((weak));
46 /* This function will be called from _init in init-first.c. */
47 void
48 __libc_global_ctors (void)
50 /* Call constructor functions. */
51 run_hooks (__CTOR_LIST__);
53 /* Initialize the thread library at least a bit since the libgcc functions
54 are using thread functions if these are available. */
55 if (__pthread_initialize_minimal)
56 __pthread_initialize_minimal ();
58 #ifdef HAVE_DWARF2_UNWIND_INFO
59 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
61 static struct object ob;
62 __register_frame_info (__EH_FRAME_BEGIN__, &ob);
64 # else
65 __register_frame (__EH_FRAME_BEGIN__);
66 # endif
67 #endif
71 /* This function becomes the DT_FINI termination function
72 for the C library. */
73 void _fini (void) __attribute__ ((section (".fini"))); /* Just for kicks. */
74 void
75 _fini (void)
77 /* Call destructor functions. */
78 run_hooks (__DTOR_LIST__);
79 #ifdef HAVE_DWARF2_UNWIND_INFO
80 # ifdef HAVE_DWARF2_UNWIND_INFO_STATIC
81 __deregister_frame_info (__EH_FRAME_BEGIN__);
82 # else
83 __deregister_frame (__EH_FRAME_BEGIN__);
84 # endif
85 #endif