From be385217fea47335303ec1cb08f45a1b28fdf497 Mon Sep 17 00:00:00 2001 From: guenther <> Date: Tue, 10 Nov 2015 04:14:03 +0000 Subject: [PATCH] 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@ --- src/lib/libc/stdlib/atexit.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/libc/stdlib/atexit.c b/src/lib/libc/stdlib/atexit.c index a44de37c..83cc1282 100644 --- a/src/lib/libc/stdlib/atexit.c +++ b/src/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. @@ -109,6 +109,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'.