summaryrefslogtreecommitdiff
path: root/lib/csu/common_elf
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
commitea72182faa98806557ba6170604b3ce6ca5c9eda (patch)
tree52f017367cab0025480befd06a8474a198fe0871 /lib/csu/common_elf
parentd5cabb42a1a17d02ebac157f110b3835dbc64959 (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/common_elf')
-rw-r--r--lib/csu/common_elf/crtbegin.c15
-rw-r--r--lib/csu/common_elf/crtbeginS.c23
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/csu/common_elf/crtbegin.c b/lib/csu/common_elf/crtbegin.c
index 66099e4f0b7..4c6eedcd94b 100644
--- a/lib/csu/common_elf/crtbegin.c
+++ b/lib/csu/common_elf/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/common_elf/crtbeginS.c b/lib/csu/common_elf/crtbeginS.c
index f8151b21e10..0874e31d2ef 100644
--- a/lib/csu/common_elf/crtbeginS.c
+++ b/lib/csu/common_elf/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.