summaryrefslogtreecommitdiffstats
path: root/libc/arch-x86
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-06-18 14:47:22 -0700
committerDavid 'Digit' Turner <digit@google.com>2010-06-18 16:07:10 -0700
commit6a9b888d7c4b246f6f66360789c72b754ff85021 (patch)
treed27e4487c13f200d4cfe193f950e25a01efa7743 /libc/arch-x86
parent6a09cfd9f916e3a60de707ff0806cdeb143d77a4 (diff)
downloadbionic-6a9b888d7c4b246f6f66360789c72b754ff85021.zip
bionic-6a9b888d7c4b246f6f66360789c72b754ff85021.tar.gz
bionic-6a9b888d7c4b246f6f66360789c72b754ff85021.tar.bz2
Allow static C++ destructors to be properly called on dlclose().
With this patch, _and_ an upcoming build/ patch, the destruction of static C++ objects contained in shared libraries will happen properly when dlclose() is called. Note that this change introduces crtbegin_so.S and crtend_so.S which are currently ignored by the build system. + move definition of __dso_handle to the right place (before that, all shared libraries used the __dso_handle global variable from the C library). Note that we keep a 'weak' __dso_handle in aeabi.c to avoid breaking the build until the next patch to build/core/combo/ appears. We will be able to remove that later. + move bionic/aeabi.c to arch-arm/bionic/ (its proper location) Change-Id: Ie771aa204e3acbdf02fd30ebd4150373a1398f39 NOTE: The NDK will need to be modified to enable this feature in the shared libraries that are generated through it.
Diffstat (limited to 'libc/arch-x86')
-rw-r--r--libc/arch-x86/bionic/crtbegin_dynamic.S3
-rw-r--r--libc/arch-x86/bionic/crtbegin_so.S10
-rw-r--r--libc/arch-x86/bionic/crtbegin_static.S7
3 files changed, 13 insertions, 7 deletions
diff --git a/libc/arch-x86/bionic/crtbegin_dynamic.S b/libc/arch-x86/bionic/crtbegin_dynamic.S
index 3b47b18..88e7e6a 100644
--- a/libc/arch-x86/bionic/crtbegin_dynamic.S
+++ b/libc/arch-x86/bionic/crtbegin_dynamic.S
@@ -30,7 +30,7 @@
.globl _start
# this is the small startup code that is first run when
-# any executable that is statically-linked with Bionic
+# any executable that is dynamically-linked with Bionic
# runs.
#
# it's purpose is to call __libc_init with appropriate
@@ -94,3 +94,4 @@ __FINI_ARRAY__:
__CTOR_LIST__:
.long -1
+#include "__dso_handle.S"
diff --git a/libc/arch-x86/bionic/crtbegin_so.S b/libc/arch-x86/bionic/crtbegin_so.S
index d49e9df..d879fef 100644
--- a/libc/arch-x86/bionic/crtbegin_so.S
+++ b/libc/arch-x86/bionic/crtbegin_so.S
@@ -1,3 +1,10 @@
+# This function is to be called when the shared library
+# is unloaded through dlclose()
+_on_dlclose:
+ lea __dso_handle, %eax
+ call __cxa_finalize
+ ret
+
/* we put the _init() function here in case the user files for the shared
* libs want to drop things into .init section.
* We then will call our ctors from crtend_so.o */
@@ -20,6 +27,7 @@ __INIT_ARRAY__:
.globl __FINI_ARRAY__
__FINI_ARRAY__:
.long -1
+ .long _on_dlclose
.section .ctors, "aw"
.align 4
@@ -27,3 +35,5 @@ __FINI_ARRAY__:
.globl __CTOR_LIST__
__CTOR_LIST__:
.long -1
+
+#include "__dso_handle.S"
diff --git a/libc/arch-x86/bionic/crtbegin_static.S b/libc/arch-x86/bionic/crtbegin_static.S
index eb4acee..3f8446e 100644
--- a/libc/arch-x86/bionic/crtbegin_static.S
+++ b/libc/arch-x86/bionic/crtbegin_static.S
@@ -67,12 +67,6 @@ _start:
.long __FINI_ARRAY__
.long __CTOR_LIST__
-# the .ctors section contains a list of pointers to "constructor"
-# functions that need to be called in order during C library initialization,
-# just before the program is being run. This is a C++ requirement
-#
-# the last entry shall be 0, and is defined in crtend.S
-#
.section .preinit_array, "aw"
.globl __PREINIT_ARRAY__
__PREINIT_ARRAY__:
@@ -93,3 +87,4 @@ __FINI_ARRAY__:
__CTOR_LIST__:
.long -1
+#include "__dso_handle.S"