From 067458d3e4d7e3ca6e967ce3ae9e59c217b2d319 Mon Sep 17 00:00:00 2001 From: guenther <> Date: Sun, 2 Jun 2019 01:03:01 +0000 Subject: Complete the ld.so boot cleanup: move most libc initialization from _csu_finish() to _libc_preinit(), which is an .init_array function in shared libc (and mark it INITFIRST) or a .preinit_array function in static libc, grabbing the _dl_cb callback there from ld.so. Then in _csu_finish(), invoke the dl_clean_boot() callback to free ld.so's startup bits before main() gets control. Other cleanups this permits: - move various startup structures into .data.rel.ro - the dl* stubs in libc can be strong and call the callbacks provided via _dl_cb - no longer need to conditionalize dlctl() calls on presence of _DYNAMIC original concept and full diff ok kettenis@ ok deraadt@ --- src/lib/libc/include/namespace.h | 4 +++- src/lib/libc/stdlib/thread_atexit.c | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h index 79692af0bc..330af4050a 100644 --- a/src/lib/libc/include/namespace.h +++ b/src/lib/libc/include/namespace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: namespace.h,v 1.13 2019/05/13 20:00:32 guenther Exp $ */ +/* $OpenBSD: namespace.h,v 1.14 2019/06/02 01:03:01 guenther Exp $ */ #ifndef _LIBC_NAMESPACE_H_ #define _LIBC_NAMESPACE_H_ @@ -59,6 +59,8 @@ #define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) HIDDEN(dst) \ __attribute__((alias (HIDDEN_STRING(src)))) +#define __relro __attribute__((section(".data.rel.ro"))) + /* * gcc and clang will generate calls to the functions below. diff --git a/src/lib/libc/stdlib/thread_atexit.c b/src/lib/libc/stdlib/thread_atexit.c index 2e00428eba..ef0423c428 100644 --- a/src/lib/libc/stdlib/thread_atexit.c +++ b/src/lib/libc/stdlib/thread_atexit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: thread_atexit.c,v 1.1 2017/12/16 20:06:56 guenther Exp $ */ +/* $OpenBSD: thread_atexit.c,v 1.2 2019/06/02 01:03:01 guenther Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -16,15 +16,11 @@ */ #include -#include -#pragma weak _DYNAMIC #include #include #include "atexit.h" -typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak)); - __weak_alias(__cxa_thread_atexit, __cxa_thread_atexit_impl); int @@ -37,8 +33,7 @@ __cxa_thread_atexit_impl(void (*func)(void *), void *arg, void *dso) if (fnp == NULL) return -1; - if (_DYNAMIC) - dlctl(NULL, DL_REFERENCE, dso); + dlctl(NULL, DL_REFERENCE, dso); fnp->func = func; fnp->arg = arg; -- cgit v1.2.3-55-g6feb