summaryrefslogtreecommitdiffstats
path: root/libc/bionic/libc_init_static.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-10-21 04:16:50 +0200
committerDavid 'Digit' Turner <digit@google.com>2010-10-21 04:16:50 +0200
commit1df986c21ee52c6756846b4a5e45cb316f772112 (patch)
treeda7effa96dd8e57e1cd718e69b79827d9011038e /libc/bionic/libc_init_static.c
parentd3f0638aeec0b1daf4d3347386a5e441d5a4bcc4 (diff)
downloadbionic-1df986c21ee52c6756846b4a5e45cb316f772112.zip
bionic-1df986c21ee52c6756846b4a5e45cb316f772112.tar.gz
bionic-1df986c21ee52c6756846b4a5e45cb316f772112.tar.bz2
libc: fix executable destruction support.
This change allows an executable to call its destructor functions (declared with __attribute__((destructor))) to be properly called when it normally exits. Note that this is different from calling the destructors of a shared library when it is unloaded with dlclose() or through program exit, which are already supported. Bug: 3106500 Change-Id: I1412ef5407f13b613fc6cb6103e0a691dbee4b1a
Diffstat (limited to 'libc/bionic/libc_init_static.c')
-rw-r--r--libc/bionic/libc_init_static.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c
index d097b6b..3634c7b 100644
--- a/libc/bionic/libc_init_static.c
+++ b/libc/bionic/libc_init_static.c
@@ -85,5 +85,12 @@ __noreturn void __libc_init(uintptr_t *elfdata,
argv = (char**)(elfdata + 1);
envp = argv + argc + 1;
+ /* 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.
+ */
+ if (structors->fini_array)
+ __cxa_atexit(__libc_fini,structors->fini_array,NULL);
+
exit(slingshot(argc, argv, envp));
}