Browse Source

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@
OPENBSD_6_6
guenther 5 years ago
parent
commit
f0934b0e07
2 changed files with 28 additions and 4 deletions
  1. +5
    -3
      src/etc/rc
  2. +23
    -1
      src/include/tib.h

+ 5
- 3
src/etc/rc View File

@ -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


+ 23
- 1
src/include/tib.h View File

@ -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 <guenther@openbsd.org>
*
@ -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;


Loading…
Cancel
Save