summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2019-05-10 13:29:21 +0000
committerguenther <guenther@openbsd.org>2019-05-10 13:29:21 +0000
commitc0197e40dd4094880fe205f9c12d3e12e14e7ff3 (patch)
tree6882480a3d40ae2f97a06566d8fe24fcd28a10f0 /lib/csu
parentAdd some more edge case tests. (diff)
downloadwireguard-openbsd-c0197e40dd4094880fe205f9c12d3e12e14e7ff3.tar.xz
wireguard-openbsd-c0197e40dd4094880fe205f9c12d3e12e14e7ff3.zip
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@
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/boot.h14
-rw-r--r--lib/csu/crt0.c6
-rw-r--r--lib/csu/extern.h4
3 files changed, 18 insertions, 6 deletions
diff --git a/lib/csu/boot.h b/lib/csu/boot.h
index c899af9303b..6ec5256bb06 100644
--- a/lib/csu/boot.h
+++ b/lib/csu/boot.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.h,v 1.29 2018/11/22 21:37:29 guenther Exp $ */
+/* $OpenBSD: boot.h,v 1.30 2019/05/10 13:29:21 guenther Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -81,6 +81,14 @@ struct boot_dyn {
#endif
};
+static void *relro_addr;
+static size_t relro_size;
+#define RCRT0_RELRO() \
+ do { \
+ if (relro_addr != NULL && relro_size != 0) \
+ mprotect(relro_addr, relro_size, PROT_READ); \
+ } while (0)
+
/*
* Local decls.
*/
@@ -220,8 +228,8 @@ _dl_boot_bind(const long sp, long *dl_data, Elf_Dyn *dynamicp)
break;
#endif
case PT_GNU_RELRO:
- mprotect((void *)(phdp->p_vaddr + loff), phdp->p_memsz,
- PROT_READ);
+ relro_addr = (void *)(phdp->p_vaddr + loff);
+ relro_size = phdp->p_memsz;
/*
* GNU_RELRO (a) covers the GOT, and (b) comes after
* all LOAD sections, so if we found it then we're done
diff --git a/lib/csu/crt0.c b/lib/csu/crt0.c
index ac2966b5490..2c113e73428 100644
--- a/lib/csu/crt0.c
+++ b/lib/csu/crt0.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crt0.c,v 1.13 2019/05/08 20:27:29 guenther Exp $ */
+/* $OpenBSD: crt0.c,v 1.14 2019/05/10 13:29:21 guenther Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -49,6 +49,9 @@ static void ___start(MD_START_ARGS) __used;
#ifndef MD_EPROL_LABEL
#define MD_EPROL_LABEL __asm(" .text\n_eprol:")
#endif
+#ifndef RCRT0_RELRO
+#define RCRT0_RELRO() do {} while (0)
+#endif
char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void));
@@ -89,6 +92,7 @@ ___start(MD_START_ARGS)
size = __preinit_array_end - __preinit_array_start;
for (i = 0; i < size; i++)
__preinit_array_start[i](argc, argv, envp, NULL);
+ RCRT0_RELRO();
size = __init_array_end - __init_array_start;
for (i = 0; i < size; i++)
__init_array_start[i](argc, argv, envp, NULL);
diff --git a/lib/csu/extern.h b/lib/csu/extern.h
index 5cc17413c8a..92dc12a0437 100644
--- a/lib/csu/extern.h
+++ b/lib/csu/extern.h
@@ -17,8 +17,8 @@
void __init(void) __dso_hidden;
int main(int argc, char *argv[], char *envp[]);
-struct dl_cb;
-typedef void (*initarray_f)(int, char **, char **, const struct dl_cb *);
+typedef const void *dl_cb_cb(int);
+typedef void (*initarray_f)(int, char **, char **, dl_cb_cb *);
typedef void (*init_f)(void);
/*