summaryrefslogtreecommitdiff
path: root/libexec/ld.so/library.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-05-07 19:05:25 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-05-07 19:05:25 +0000
commitbe4e94637d7117375492627b79c41629c7da9bc3 (patch)
tree61a9fabcc07d38d2720bbb937e83103928286550 /libexec/ld.so/library.c
parent33d8693716b4a6d503e0ba97f94a783905b87f28 (diff)
Use a Thread Information Block in both single and multi-threaded programs.
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
Diffstat (limited to 'libexec/ld.so/library.c')
-rw-r--r--libexec/ld.so/library.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c
index 9a945b37b37..5318af38592 100644
--- a/libexec/ld.so/library.c
+++ b/libexec/ld.so/library.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: library.c,v 1.74 2016/03/20 02:29:51 guenther Exp $ */
+/* $OpenBSD: library.c,v 1.75 2016/05/07 19:05:23 guenther Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
@@ -104,6 +104,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags)
Elf_Dyn *dynp = NULL;
Elf_Ehdr *ehdr;
Elf_Phdr *phdp;
+ Elf_Phdr *ptls = NULL;
struct stat sb;
void *prebind_data;
@@ -164,6 +165,17 @@ _dl_tryload_shlib(const char *libname, int type, int flags)
dynp = (Elf_Dyn *)phdp->p_vaddr;
break;
case PT_TLS:
+ if (phdp->p_filesz > phdp->p_memsz) {
+ _dl_printf("%s: invalid tls data in %s.\n",
+ __progname, libname);
+ _dl_close(libfile);
+ _dl_errno = DL_CANT_LOAD_OBJ;
+ return(0);
+ }
+ if (!_dl_tib_static_done) {
+ ptls = phdp;
+ break;
+ }
_dl_printf("%s: unsupported TLS program header in %s\n",
__progname, libname);
_dl_close(libfile);
@@ -283,6 +295,8 @@ _dl_tryload_shlib(const char *libname, int type, int flags)
object->inode = sb.st_ino;
object->obj_flags |= flags;
_dl_set_sod(object->load_name, &object->sod);
+ if (ptls != NULL && ptls->p_memsz)
+ _dl_set_tls(object, ptls, libaddr, libname);
} else {
_dl_munmap((void *)libaddr, maxva - minva);
_dl_load_list_free(load_list);