diff options
author | David 'Digit' Turner <digit@google.com> | 2010-10-21 09:43:19 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-10-21 09:43:19 -0700 |
commit | f7ad13b0ce5ad2d2f0340c066b09eb8174877739 (patch) | |
tree | 21a0fc62890f7df4b1315fc41f298ce8fd5bcc9e /libc/bionic/libc_init_dynamic.c | |
parent | aeb41ec103103c37bf4a1700de714d9ff1befe8e (diff) | |
parent | 1df986c21ee52c6756846b4a5e45cb316f772112 (diff) | |
download | android_bionic-f7ad13b0ce5ad2d2f0340c066b09eb8174877739.tar.gz android_bionic-f7ad13b0ce5ad2d2f0340c066b09eb8174877739.tar.bz2 android_bionic-f7ad13b0ce5ad2d2f0340c066b09eb8174877739.zip |
am 1df986c2: libc: fix executable destruction support.
Merge commit '1df986c21ee52c6756846b4a5e45cb316f772112' into gingerbread-plus-aosp
* commit '1df986c21ee52c6756846b4a5e45cb316f772112':
libc: fix executable destruction support.
Diffstat (limited to 'libc/bionic/libc_init_dynamic.c')
-rw-r--r-- | libc/bionic/libc_init_dynamic.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/libc/bionic/libc_init_dynamic.c b/libc/bionic/libc_init_dynamic.c index 97e80eaec..4bb2a8133 100644 --- a/libc/bionic/libc_init_dynamic.c +++ b/libc/bionic/libc_init_dynamic.c @@ -57,9 +57,9 @@ * This ensures that the function is called by the dynamic linker * as soon as the shared library is loaded. */ -void __attribute__((constructor)) __libc_prenit(void); +void __attribute__((constructor)) __libc_preinit(void); -void __libc_prenit(void) +void __libc_preinit(void) { /* Read the ELF data pointer from a special slot of the * TLS area, then call __libc_init_common with it. @@ -83,14 +83,19 @@ void __libc_prenit(void) malloc_debug_init(); } +/* This function is called from the executable's _start entry point + * (see arch-$ARCH/bionic/crtbegin_dynamic.S), which is itself + * called by the dynamic linker after it has loaded all shared + * libraries the executable depends on. + * + * Note that the dynamic linker has also run all constructors in the + * executable at this point. + */ __noreturn void __libc_init(uintptr_t *elfdata, void (*onexit)(void), int (*slingshot)(int, char**, char**), structors_array_t const * const structors) { - /* When we reach this point, all initializers have been already - * run by the dynamic linker, so ignore 'structors'. - */ int argc = (int)*elfdata; char** argv = (char**)(elfdata + 1); char** envp = argv + argc + 1; @@ -99,5 +104,12 @@ __noreturn void __libc_init(uintptr_t *elfdata, * do never use it. Therefore, we ignore it. */ + /* 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)); } |