diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2013-12-28 18:38:43 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2013-12-28 18:38:43 +0000 |
commit | bc12c86a75ed337690facd5ac2ed837f666bc171 (patch) | |
tree | 4e95d2fa4f28c783ccc07f63dbf98b9c9aa23c9c | |
parent | 90aa35af34f1764d881c3f88bbcf26688d2694c0 (diff) |
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@
-rw-r--r-- | lib/csu/crtbegin.c | 10 | ||||
-rw-r--r-- | lib/csu/crtbeginS.c | 10 |
2 files changed, 18 insertions, 2 deletions
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] |