summaryrefslogtreecommitdiffstats
path: root/newlib/libc/misc/fini.c
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2010-06-04 15:30:40 +0000
committerJeff Johnston <jjohnstn@redhat.com>2010-06-04 15:30:40 +0000
commitced5f59df9ba6e869ecd284e568ef5c3be82158f (patch)
tree1f579fec2d51c1eb48eba2b968c10a2ec51b8f49 /newlib/libc/misc/fini.c
parente4f9551b407ad1a538d039fb4be395aab0c7fa51 (diff)
downloadcygnal-ced5f59df9ba6e869ecd284e568ef5c3be82158f.tar.gz
cygnal-ced5f59df9ba6e869ecd284e568ef5c3be82158f.tar.bz2
cygnal-ced5f59df9ba6e869ecd284e568ef5c3be82158f.zip
2010-06-04 Mark Mitchell <mark@codesourcery.com>
* libc/stdlib/__call_atexit.c (__libc_fini): Declare. (register_fini): New function. * libc/misc/init.c (_fini): Remove. (__libc_fini_array): Likewise. * libc/misc/fini.c: New file. * libc/misc/Makefile.am (LIB_SOURCES): Add fini.c. * libc/misc/Makefile.in: Regenerate.
Diffstat (limited to 'newlib/libc/misc/fini.c')
-rw-r--r--newlib/libc/misc/fini.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/newlib/libc/misc/fini.c b/newlib/libc/misc/fini.c
new file mode 100644
index 000000000..ab4203bf8
--- /dev/null
+++ b/newlib/libc/misc/fini.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 CodeSourcery, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this file
+ * for any purpose is hereby granted without fee, provided that
+ * the above copyright notice and this notice appears in all
+ * copies.
+ *
+ * This file is distributed WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* Handle ELF .{pre_init,init,fini}_array sections. */
+#include <sys/types.h>
+
+#ifdef HAVE_INITFINI_ARRAY
+extern void (*__fini_array_start []) (void) __attribute__((weak));
+extern void (*__fini_array_end []) (void) __attribute__((weak));
+
+extern void _fini (void);
+
+/* Run all the cleanup routines. */
+void
+__libc_fini_array (void)
+{
+ size_t count;
+ size_t i;
+
+ count = __fini_array_end - __fini_array_start;
+ for (i = count; i > 0; i--)
+ __fini_array_start[i-1] ();
+
+ _fini ();
+}
+#endif