summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2013-12-28 18:38:42 +0000
committerkettenis <kettenis@openbsd.org>2013-12-28 18:38:42 +0000
commit859c67c82abbbc6a47fd83e1b7b5305186273ffd (patch)
treed7b22f6c7c4434d4f249ef2ef2afcbdede54f8ef /lib/csu
parentBack out the previous commit; rodata gets merged with text by the linker. (diff)
downloadwireguard-openbsd-859c67c82abbbc6a47fd83e1b7b5305186273ffd.tar.xz
wireguard-openbsd-859c67c82abbbc6a47fd83e1b7b5305186273ffd.zip
Move atexit(3) into crtbegin.c and certbeginS.c such that we can pass the
right __dso_handle and have dlopen'ed shared objects run their atexit handlers when they get unloaded. This is what Linux does, and several ports depend on this behaviour (and will crash upon exit without this chang). Based on an earlier diff from matthew@ Tested by ajacoutot@ ok deraadt@
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/common_elf/crtbegin.c10
-rw-r--r--lib/csu/common_elf/crtbeginS.c10
-rw-r--r--lib/csu/crtbegin.c10
-rw-r--r--lib/csu/crtbeginS.c10
4 files changed, 36 insertions, 4 deletions
diff --git a/lib/csu/common_elf/crtbegin.c b/lib/csu/common_elf/crtbegin.c
index f594675d78d..bf2c4fb09cd 100644
--- a/lib/csu/common_elf/crtbegin.c
+++ b/lib/csu/common_elf/crtbegin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbegin.c,v 1.16 2012/09/08 20:08:33 matthew Exp $ */
+/* $OpenBSD: crtbegin.c,v 1.17 2013/12/28 18:38:42 kettenis Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -84,6 +84,14 @@ void *__dso_handle = NULL;
__asm(".hidden __dso_handle");
long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
+
+extern int __cxa_atexit(void (*)(void *), void *, void *) __attribute__((weak));
+
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, NULL));
+}
#endif
static const init_f __CTOR_LIST__[1]
diff --git a/lib/csu/common_elf/crtbeginS.c b/lib/csu/common_elf/crtbeginS.c
index b72698fe2b4..f3c784214a7 100644
--- a/lib/csu/common_elf/crtbeginS.c
+++ b/lib/csu/common_elf/crtbeginS.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbeginS.c,v 1.13 2012/09/08 20:08:33 matthew Exp $ */
+/* $OpenBSD: crtbeginS.c,v 1.14 2013/12/28 18:38:42 kettenis Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -72,7 +72,15 @@ __asm(".hidden __dso_handle");
long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
+extern int __cxa_atexit(void (*)(void *), void *, void *) __attribute__((weak));
extern void __cxa_finalize(void *) __attribute__((weak));
+
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, &__dso_handle));
+}
+asm(".hidden atexit");
#endif
static init_f __CTOR_LIST__[1]
diff --git a/lib/csu/crtbegin.c b/lib/csu/crtbegin.c
index f594675d78d..bf2c4fb09cd 100644
--- a/lib/csu/crtbegin.c
+++ b/lib/csu/crtbegin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbegin.c,v 1.16 2012/09/08 20:08:33 matthew Exp $ */
+/* $OpenBSD: crtbegin.c,v 1.17 2013/12/28 18:38:42 kettenis Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -84,6 +84,14 @@ void *__dso_handle = NULL;
__asm(".hidden __dso_handle");
long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
+
+extern int __cxa_atexit(void (*)(void *), void *, void *) __attribute__((weak));
+
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, NULL));
+}
#endif
static const init_f __CTOR_LIST__[1]
diff --git a/lib/csu/crtbeginS.c b/lib/csu/crtbeginS.c
index b72698fe2b4..f3c784214a7 100644
--- a/lib/csu/crtbeginS.c
+++ b/lib/csu/crtbeginS.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbeginS.c,v 1.13 2012/09/08 20:08:33 matthew Exp $ */
+/* $OpenBSD: crtbeginS.c,v 1.14 2013/12/28 18:38:42 kettenis Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -72,7 +72,15 @@ __asm(".hidden __dso_handle");
long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
+extern int __cxa_atexit(void (*)(void *), void *, void *) __attribute__((weak));
extern void __cxa_finalize(void *) __attribute__((weak));
+
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, &__dso_handle));
+}
+asm(".hidden atexit");
#endif
static init_f __CTOR_LIST__[1]