summaryrefslogtreecommitdiffstats
path: root/lib/librthread
diff options
context:
space:
mode:
authormatthew <matthew@openbsd.org>2012-08-22 23:43:32 +0000
committermatthew <matthew@openbsd.org>2012-08-22 23:43:32 +0000
commit28e55bae51448fde7bb6522006faf91d11ee8da2 (patch)
tree00a4bff462187def0557ae2a4ecb9f5cb26ea358 /lib/librthread
parentWe cannot just copy mcount.o to mcount.po, since the former may be PIE and (diff)
downloadwireguard-openbsd-28e55bae51448fde7bb6522006faf91d11ee8da2.tar.xz
wireguard-openbsd-28e55bae51448fde7bb6522006faf91d11ee8da2.zip
We want to check that the dynamic linker is available at run-time, so
we should actually check for _DYNAMIC at run-time rather than checking for __PIC__ at compile time, since the two are actually independent. Problem and solution identified by guenther; minor tweaks by me. ok guenther
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/rthread.c36
-rw-r--r--lib/librthread/rthread.h4
-rw-r--r--lib/librthread/rthread_fork.c28
3 files changed, 42 insertions, 26 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c
index 17b7aed61fa..f19fc926d49 100644
--- a/lib/librthread/rthread.c
+++ b/lib/librthread/rthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.c,v 1.65 2012/08/22 22:34:57 matthew Exp $ */
+/* $OpenBSD: rthread.c,v 1.66 2012/08/22 23:43:32 matthew Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -26,6 +26,10 @@
#include <sys/socket.h>
#include <sys/mman.h>
#include <sys/msg.h>
+#if defined(__ELF__)
+#include <sys/exec_elf.h>
+#pragma weak _DYNAMIC
+#endif
#include <stdlib.h>
#include <unistd.h>
@@ -174,19 +178,21 @@ _rthread_init(void)
_rthread_debug(1, "rthread init\n");
-#if defined(__ELF__) && defined(__PIC__)
- /*
- * To avoid recursion problems in ld.so, we need to trigger the
- * functions once to fully bind them before registering them
- * for use.
- */
- _rthread_dl_lock(0);
- _rthread_dl_lock(1);
- _rthread_bind_lock(0);
- _rthread_bind_lock(1);
- sched_yield();
- dlctl(NULL, DL_SETTHREADLCK, _rthread_dl_lock);
- dlctl(NULL, DL_SETBINDLCK, _rthread_bind_lock);
+#if defined(__ELF__)
+ if (_DYNAMIC) {
+ /*
+ * To avoid recursion problems in ld.so, we need to trigger the
+ * functions once to fully bind them before registering them
+ * for use.
+ */
+ _rthread_dl_lock(0);
+ _rthread_dl_lock(1);
+ _rthread_bind_lock(0);
+ _rthread_bind_lock(1);
+ sched_yield();
+ dlctl(NULL, DL_SETTHREADLCK, _rthread_dl_lock);
+ dlctl(NULL, DL_SETBINDLCK, _rthread_bind_lock);
+ }
#endif
/*
@@ -582,7 +588,7 @@ _thread_dump_info(void)
_spinunlock(&_thread_lock);
}
-#if defined(__ELF__) && defined(__PIC__)
+#if defined(__ELF__)
/*
* _rthread_dl_lock() provides the locking for dlopen(), dlclose(), and
* the function called via atexit() to invoke all destructors. The latter
diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h
index 4cb86446491..76271cea022 100644
--- a/lib/librthread/rthread.h
+++ b/lib/librthread/rthread.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.h,v 1.39 2012/05/03 09:07:17 pirofti Exp $ */
+/* $OpenBSD: rthread.h,v 1.40 2012/08/22 23:43:32 matthew Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -204,7 +204,7 @@ void _rthread_tls_destructors(pthread_t);
void _rthread_debug(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
void _rthread_debug_init(void);
-#if defined(__ELF__) && defined(PIC)
+#if defined(__ELF__)
void _rthread_dl_lock(int what);
void _rthread_bind_lock(int);
#endif
diff --git a/lib/librthread/rthread_fork.c b/lib/librthread/rthread_fork.c
index d5786ed5449..c5847363929 100644
--- a/lib/librthread/rthread_fork.c
+++ b/lib/librthread/rthread_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_fork.c,v 1.5 2012/08/22 22:34:57 matthew Exp $ */
+/* $OpenBSD: rthread_fork.c,v 1.6 2012/08/22 23:43:32 matthew Exp $ */
/*
* Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
@@ -30,6 +30,12 @@
* $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $
*/
+#if defined(__ELF__)
+#include <sys/types.h>
+#include <sys/exec_elf.h>
+#pragma weak _DYNAMIC
+#endif
+
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
@@ -77,30 +83,34 @@ _dofork(int is_vfork)
* binding in the other locking functions can succeed.
*/
-#if defined(__ELF__) && defined(__PIC__)
- _rthread_dl_lock(0);
+#if defined(__ELF__)
+ if (_DYNAMIC)
+ _rthread_dl_lock(0);
#endif
_thread_atexit_lock();
_thread_malloc_lock();
_thread_arc4_lock();
-#if defined(__ELF__) && defined(__PIC__)
- _rthread_bind_lock(0);
+#if defined(__ELF__)
+ if (_DYNAMIC)
+ _rthread_bind_lock(0);
#endif
newid = sys_fork();
-#if defined(__ELF__) && defined(__PIC__)
- _rthread_bind_lock(1);
+#if defined(__ELF__)
+ if (_DYNAMIC)
+ _rthread_bind_lock(1);
#endif
_thread_arc4_unlock();
_thread_malloc_unlock();
_thread_atexit_unlock();
-#if defined(__ELF__) && defined(__PIC__)
- _rthread_dl_lock(1);
+#if defined(__ELF__)
+ if (_DYNAMIC)
+ _rthread_dl_lock(1);
#endif
if (newid == 0) {