Support cancellation in librt.
[glibc.git] / csu / elf-init.c
blobf2af752c26396827d6e93aac53a1a7756d2fb94e
1 /* Startup support for ELF initializers/finalizers in the main executable.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stddef.h>
22 #ifdef HAVE_INITFINI_ARRAY
23 /* These magic symbols are provided by the linker. */
24 extern void (*__preinit_array_start []) (void) attribute_hidden;
25 extern void (*__preinit_array_end []) (void) attribute_hidden;
26 extern void (*__init_array_start []) (void) attribute_hidden;
27 extern void (*__init_array_end []) (void) attribute_hidden;
28 extern void (*__fini_array_start []) (void) attribute_hidden;
29 extern void (*__fini_array_end []) (void) attribute_hidden;
30 #endif
32 /* These function symbols are provided for the .init/.fini section entry
33 points automagically by the linker. */
34 extern void _init (void);
35 extern void _fini (void);
37 /* These functions are passed to __libc_start_main by the startup code.
38 These get statically linked into each program. For dynamically linked
39 programs, this module will come from libc_nonshared.a and differs from
40 the libc.a module in that it doesn't call the preinit array. */
42 void
43 __libc_csu_init (void)
45 #ifdef HAVE_INITFINI_ARRAY
46 /* For dynamically linked executables the preinit array is executed by
47 the dynamic linker (before initializing any shared object. */
49 # ifndef LIBC_NONSHARED
50 /* For static executables, preinit happens rights before init. */
52 const size_t size = __preinit_array_end - __preinit_array_start;
53 size_t i;
54 for (i = 0; i < size; i++)
55 (*__preinit_array_start [i]) ();
57 # endif
58 #endif
60 _init ();
62 #ifdef HAVE_INITFINI_ARRAY
64 const size_t size = __init_array_end - __init_array_start;
65 size_t i;
66 for (i = 0; i < size; i++)
67 (*__init_array_start [i]) ();
69 #endif
72 void
73 __libc_csu_fini (void)
75 #ifdef HAVE_INITFINI_ARRAY
76 size_t i = __fini_array_end - __fini_array_start;
77 while (i-- > 0)
78 (*__fini_array_start [i]) ();
79 #endif
81 _fini ();