summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-11-10 04:14:03 +0000
committerguenther <guenther@openbsd.org>2015-11-10 04:14:03 +0000
commit6897476f8d3f1ad745809cc8163365f785e57a2d (patch)
tree3a49f02e6a0fda10fd2852d3b3faef4867992778 /lib/libc/stdlib
parentAlways honor ${DESTDIR}. OK miod@ (diff)
downloadwireguard-openbsd-6897476f8d3f1ad745809cc8163365f785e57a2d.tar.xz
wireguard-openbsd-6897476f8d3f1ad745809cc8163365f785e57a2d.zip
libc.so can't be unloaded, so move the hidden atexit() and pthread_atfork()
stubs for the executable from crtbegin.o into libc, which lets them be excluded from static links that don't use them. For this, drop the normal crt{begin,end}S.o from libc.so: the .init and .fini sections for libc aren't called at the right times anyway, so it's good that they're unused. libc.so just needs __guard_local and the .note.openbsd.ident section, so add them to stack_protector.c for now (this will be improved) "good time" deraadt@
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/atexit.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c
index a44de37c880..83cc1282a98 100644
--- a/lib/libc/stdlib/atexit.c
+++ b/lib/libc/stdlib/atexit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atexit.c,v 1.23 2015/10/25 18:03:17 guenther Exp $ */
+/* $OpenBSD: atexit.c,v 1.24 2015/11/10 04:14:03 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
@@ -110,6 +110,18 @@ unlock:
DEF_STRONG(__cxa_atexit);
/*
+ * Copy of atexit() used by libc and anything staticly linked into the
+ * executable. This passes NULL for the dso, so the callbacks are only
+ * invoked by exit() and not dlclose()
+ */
+int
+atexit(void (*fn)(void))
+{
+ return (__cxa_atexit((void (*)(void *))fn, NULL, NULL));
+}
+DEF_STRONG(atexit);
+
+/*
* Call all handlers registered with __cxa_atexit() for the shared
* object owning 'dso'.
* Note: if 'dso' is NULL, then all remaining handlers are called.