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 #include <sys/_initfini.h>
16 
17 #ifdef _HAVE_INITFINI_ARRAY
18 
19 /* Run all the cleanup routines.  */
20 void
__libc_fini_array(void)21 __libc_fini_array (void)
22 {
23   size_t count;
24   size_t i;
25 
26   count = __fini_array_end - __fini_array_start;
27   for (i = count; i > 0; i--)
28     __fini_array_start[i-1] ();
29 
30 #ifdef _HAVE_INIT_FINI
31   if (_fini)
32     _fini ();
33 #endif
34 }
35 #endif
36