1 /* Startup support for ELF initializers/finalizers in the main executable.
2 Copyright (C) 2002 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
22 #ifdef HAVE_INITFINI_ARRAY
23 /* These magic symbols are provided by the linker. */
24 extern void (*__preinit_array_start
[]) (void);
25 extern void (*__preinit_array_end
[]) (void);
26 extern void (*__init_array_start
[]) (void);
27 extern void (*__init_array_end
[]) (void);
28 extern void (*__fini_array_start
[]) (void);
29 extern void (*__fini_array_end
[]) (void);
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. */
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
;
54 for (i
= 0; i
< size
; i
++)
55 (*__preinit_array_start
[i
]) ();
62 #ifdef HAVE_INITFINI_ARRAY
64 const size_t size
= __init_array_end
- __init_array_start
;
66 for (i
= 0; i
< size
; i
++)
67 (*__init_array_start
[i
]) ();
73 __libc_csu_fini (void)
75 #ifdef HAVE_INITFINI_ARRAY
76 size_t i
= __fini_array_end
- __fini_array_start
;
78 (*__fini_array_start
[i
]) ();