Module Name: src
Committed By: matt
Date: Thu Apr 7 02:19:28 UTC 2011
Modified Files:
src/lib/libc/tls: tls.c
src/libexec/ld.elf_so: tls.c
Log Message:
Add a workaround for older crt0.o that overwrite r2 (tcb pointer).
(save tcb pointer using _lwp_setprivate in ld.elf_so and retrieve the tcb
via _lwp_getprivate in libc and use it to restore the value in r2).
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/tls/tls.c
cvs rdiff -u -r1.5 -r1.6 src/libexec/ld.elf_so/tls.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/tls/tls.c
diff -u src/lib/libc/tls/tls.c:1.5 src/lib/libc/tls/tls.c:1.6
--- src/lib/libc/tls/tls.c:1.5 Fri Mar 18 14:56:01 2011
+++ src/lib/libc/tls/tls.c Thu Apr 7 02:19:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: tls.c,v 1.5 2011/03/18 14:56:01 he Exp $ */
+/* $NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: tls.c,v 1.5 2011/03/18 14:56:01 he Exp $");
+__RCSID("$NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $");
#include "namespace.h"
@@ -154,8 +154,18 @@
{
struct tls_tcb *tcb;
- if (&rtld_DYNAMIC != NULL)
+ if (&rtld_DYNAMIC != NULL) {
+#ifdef __powerpc__
+ /*
+ * Old powerpc crt0's are going to overwrite r2 so we need to
+ * restore it but only do so if the saved value isn't NULL (if
+ * it is NULL, ld.elf_so doesn't have the matching change).
+ */
+ if ((tcb = _lwp_getprivate()) != NULL)
+ __lwp_settcb(tcb);
+#endif
return;
+ }
dl_iterate_phdr(__libc_static_tls_setup_cb, NULL);
Index: src/libexec/ld.elf_so/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.5 src/libexec/ld.elf_so/tls.c:1.6
--- src/libexec/ld.elf_so/tls.c:1.5 Tue Mar 29 20:56:35 2011
+++ src/libexec/ld.elf_so/tls.c Thu Apr 7 02:19:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: tls.c,v 1.5 2011/03/29 20:56:35 joerg Exp $ */
+/* $NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: tls.c,v 1.5 2011/03/29 20:56:35 joerg Exp $");
+__RCSID("$NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $");
#include <sys/param.h>
#include <sys/ucontext.h>
@@ -104,6 +104,13 @@
tcb = _rtld_tls_allocate_locked();
#ifdef __HAVE___LWP_SETTCB
__lwp_settcb(tcb);
+#ifdef __powerpc__
+ /*
+ * Save the tcb pointer so that libc can retrieve it. Older
+ * crt0 will obliterate r2 so there is code in libc to restore it.
+ */
+ _lwp_setprivate(tcb);
+#endif
#else
_lwp_setprivate(tcb);
#endif