1 /*
2  * Copyright (C) 2010 CodeSourcery, Inc.
3  *
4  * Permission to use, copy, modify, and distribute this file
5  * for any purpose is hereby granted without fee, provided that
6  * the above copyright notice and this notice appears in all
7  * copies.
8  *
9  * This file is distributed WITHOUT ANY WARRANTY; without even the implied
10  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /* Handle ELF .{pre_init,init,fini}_array sections.  */
14 #include <sys/types.h>
15 
16 #ifdef _HAVE_INITFINI_ARRAY
17 extern void (*__fini_array_start []) (void) __attribute__((weak));
18 extern void (*__fini_array_end []) (void) __attribute__((weak));
19 
20 #ifdef _HAVE_INIT_FINI
21 extern void _fini (void) __attribute__((weak));
22 #endif
23 
24 /* Run all the cleanup routines.  */
25 void
__libc_fini_array(void)26 __libc_fini_array (void)
27 {
28   size_t count;
29   size_t i;
30 
31   count = __fini_array_end - __fini_array_start;
32   for (i = count; i > 0; i--)
33     __fini_array_start[i-1] ();
34 
35 #ifdef _HAVE_INIT_FINI
36   if (_fini)
37     _fini ();
38 #endif
39 }
40 #endif
41