Revert "Register __libc_fini as early as possible."
This reverts commit e880c736d6c1d947f6309d5f1f63c74e8345c6a6.
Change-Id: Ide83e442eb5dbfef5298a15bc602c3fe1dda1862
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index f2e34c2..bc11f3d 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -61,9 +61,6 @@
extern "C" int __cxa_atexit(void (*)(void *), void *, void *);
-__attribute__ ((section (".fini_array")))
-void (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
-
static void call_array(void(**list)()) {
// First element is -1, list is null-terminated
while (*++list) {
@@ -102,13 +99,14 @@
// do never use it. Therefore, we ignore it.
call_array(structors->preinit_array);
+ call_array(structors->init_array);
// The executable may have its own destructors listed in its .fini_array
// so we need to ensure that these are called when the program exits
// normally.
- __cxa_atexit(__libc_fini,&__FINI_ARRAY__, NULL);
-
- call_array(structors->init_array);
+ if (structors->fini_array != NULL) {
+ __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+ }
exit(slingshot(args.argc, args.argv, args.envp));
}