From f0934b0e076ff5b7db77c1b99d7ca70dcb288ad3 Mon Sep 17 00:00:00 2001 From: guenther <> Date: Fri, 10 May 2019 13:29:21 +0000 Subject: [PATCH] ld.so boot cleanup support: - put functions and data which are only used before calling the executable's start function into their own page-aligned segments for unmapping (only done on amd64, arm64, armv7, powerpc, and sparc64 so far) - pass .init_array and .preinit_array functions an addition argument which is a callback to get a structure which includes a function that frees the boot text and data - sometimes delay doing RELRO processing: for a shared-object marked DF_1_INITFIRST do it after the object's .init_array, for the executable do it after the .preinit_array - improve test-ld.so to link against libpthread and trigger its initialization late libc changes to use this will come later ok kettenis@ --- src/etc/rc | 8 +++++--- src/include/tib.h | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/etc/rc b/src/etc/rc index f697f568..9a391798 100644 --- a/src/etc/rc +++ b/src/etc/rc @@ -1,4 +1,4 @@ -# $OpenBSD: rc,v 1.536 2019/04/01 11:39:46 tedu Exp $ +# $OpenBSD: rc,v 1.537 2019/05/10 13:29:21 guenther Exp $ # System startup script run by init on autoboot or after single-user. # Output and error are redirected to console by init, and the console is the @@ -210,9 +210,11 @@ reorder_libs() { cd $_tmpdir ar x $_liba if [[ $_lib == ld.so ]]; then - ld -g -x -e _dl_start \ + args="-g -x -e _dl_start \ --version-script=Symbols.map --shared -Bsymbolic \ - --no-undefined -o ld.so.test $(ls *.o | sort -R) + --no-undefined" + [[ -f ld.script ]] && args="$args -T ld.script" + ld $args -o ld.so.test $(ls *.o | sort -R) chmod u+x test-ld.so [[ $(./test-ld.so ok) == './test-ld.so: ok!' ]] $_install /usr/libexec/ld.so /usr/libexec/ld.so.save diff --git a/src/include/tib.h b/src/include/tib.h index 1c610222..8d9216f1 100644 --- a/src/include/tib.h +++ b/src/include/tib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tib.h,v 1.6 2017/11/28 18:57:02 kettenis Exp $ */ +/* $OpenBSD: tib.h,v 1.7 2019/05/10 13:29:21 guenther Exp $ */ /* * Copyright (c) 2011,2014 Philip Guenther * @@ -225,6 +225,28 @@ struct tib { __BEGIN_DECLS +struct dl_info; +struct dl_phdr_info; +struct dl_cb_0 { + void *(*dl_allocate_tib)(size_t); + void (*dl_free_tib)(void *, size_t); + void (*dl_clean_boot)(void); + void *(*dlopen)(const char *, int); + int (*dlclose)(void *); + void *(*dlsym)(void *, const char *); + int (*dladdr)(const void *, struct dl_info *); + int (*dlctl)(void *, int, void *); + char *(*dlerror)(void); + int (*dl_iterate_phdr)(int (*)(struct dl_phdr_info *, + size_t, void *), void *); +}; + +#define DL_CB_CUR 0 +typedef struct dl_cb_0 dl_cb; + +/* type of function passed to init functions that returns a dl_cb */ +typedef const void *dl_cb_cb(int _version); + void *_dl_allocate_tib(size_t _extra) __dso_public; void _dl_free_tib(void *_tib, size_t _extra) __dso_public;