summaryrefslogtreecommitdiff
path: root/lib/csu
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2007-09-03 14:40:17 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2007-09-03 14:40:17 +0000
commit124df25a7eccf983dda17aa5c53af66f2224f6e8 (patch)
tree72caf1ff6d525787fa840ec2270305380d0ee8c4 /lib/csu
parentf5832479ed1842383e8167f0e753f4bb40ab451d (diff)
Add __cxa_atexit() support for gcc3. This provides support for shared object destructors called at dlclose() time. Inspired by similar changes in FreeBSD and NetBSD.
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/crtbegin.c15
-rw-r--r--lib/csu/crtbeginS.c23
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/csu/crtbegin.c b/lib/csu/crtbegin.c
index 66099e4f0b7..4c6eedcd94b 100644
--- a/lib/csu/crtbegin.c
+++ b/lib/csu/crtbegin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbegin.c,v 1.11 2004/10/26 20:18:24 kettenis Exp $ */
+/* $OpenBSD: crtbegin.c,v 1.12 2007/09/03 14:40:16 millert Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -59,6 +59,19 @@ void __register_frame_info(const void *begin, struct dwarf2_eh_object *ob)
static const char __EH_FRAME_BEGIN__[]
__attribute__((section(".eh_frame"), aligned(4))) = { };
+/*
+ * Include support for the __cxa_atexit/__cxa_finalize C++ abi for
+ * gcc > 2.x. __dso_handle is NULL in the main program and a unique
+ * value for each C++ shared library. For more info on this API, see:
+ *
+ * http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
+ */
+
+#if (__GNUC__ > 2)
+void *__dso_handle = NULL;
+__asm(".hidden __dso_handle");
+#endif
+
static const init_f __CTOR_LIST__[1]
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
static const init_f __DTOR_LIST__[1]
diff --git a/lib/csu/crtbeginS.c b/lib/csu/crtbeginS.c
index f8151b21e10..0874e31d2ef 100644
--- a/lib/csu/crtbeginS.c
+++ b/lib/csu/crtbeginS.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbeginS.c,v 1.7 2004/01/26 20:04:11 espie Exp $ */
+/* $OpenBSD: crtbeginS.c,v 1.8 2007/09/03 14:40:16 millert Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -44,6 +44,21 @@
#include "md_init.h"
#include "extern.h"
+/*
+ * Include support for the __cxa_atexit/__cxa_finalize C++ abi for
+ * gcc > 2.x. __dso_handle is NULL in the main program and a unique
+ * value for each C++ shared library. For more info on this API, see:
+ *
+ * http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
+ */
+
+#if (__GNUC__ > 2)
+void *__dso_handle = &__dso_handle;
+__asm(".hidden __dso_handle");
+
+extern void __cxa_finalize(void *) __attribute__((weak));
+#endif
+
static init_f __CTOR_LIST__[1]
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
static init_f __DTOR_LIST__[1]
@@ -111,6 +126,12 @@ _do_fini(void)
static int finalized = 0;
if (!finalized) {
finalized = 1;
+
+#if (__GNUC__ > 2)
+ if (__cxa_finalize != NULL)
+ __cxa_finalize(__dso_handle);
+#endif
+
/*
* since the _init() function sets up the destructors to
* be called by atexit, do not call the destructors here.