Port-arm archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
TLS support patch
Hi all,
the attached patch allows TLS support on ARM. I won't commit it, since
it will make pthread usage inacceptable slow. I hope someone is going to
write the magic for __eabi_read_tp and __lwp_getprivate_fast().
Joerg
Index: lib/libc/arch/arm/Makefile.inc
===================================================================
RCS file: /home/joerg/repo/netbsd/src/lib/libc/arch/arm/Makefile.inc,v
retrieving revision 1.9
diff -u -p -r1.9 Makefile.inc
--- lib/libc/arch/arm/Makefile.inc 6 Jul 2010 05:59:52 -0000 1.9
+++ lib/libc/arch/arm/Makefile.inc 2 Apr 2011 21:51:30 -0000
@@ -2,7 +2,7 @@
.include <bsd.own.mk>
-SRCS+= __sigaction14_sigtramp.c __sigtramp2.S
+SRCS+= __aeabi_read_tp.S __sigaction14_sigtramp.c __sigtramp2.S
CPPFLAGS += -DSOFTFLOAT
Index: lib/libc/arch/arm/sys/__aeabi_read_tp.S
===================================================================
RCS file: lib/libc/arch/arm/sys/__aeabi_read_tp.S
diff -N lib/libc/arch/arm/sys/__aeabi_read_tp.S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libc/arch/arm/sys/__aeabi_read_tp.S 2 Apr 2011 22:04:13 -0000
@@ -0,0 +1,5 @@
+#include "SYS.h"
+
+ENTRY(__aeabi_read_tp)
+ SYSTRAP(_lwp_getprivate)
+ RET
Index: lib/libpthread/pthread_int.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/lib/libpthread/pthread_int.h,v
retrieving revision 1.78
diff -u -p -r1.78 pthread_int.h
--- lib/libpthread/pthread_int.h 17 Mar 2011 00:43:48 -0000 1.78
+++ lib/libpthread/pthread_int.h 2 Apr 2011 19:54:25 -0000
@@ -261,17 +261,13 @@ pthread__self(void)
{
#ifdef __HAVE___LWP_GETTCB_FAST
struct tls_tcb * const tcb = __lwp_gettcb_fast();
-#else
+#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
struct tls_tcb * const tcb = __lwp_getprivate_fast();
+#else
+ struct tls_tcb * const tcb = _lwp_getprivate();
#endif
return (pthread_t)tcb->tcb_pthread;
}
-#elif 0 && defined(__HAVE___LWP_GETPRIVATE_FAST)
-static inline pthread_t __constfunc
-pthread__self(void)
-{
- return (pthread_t)__lwp_getprivate_fast();
-}
#else
/* Stack location of pointer to a particular thread */
extern vaddr_t pthread__mainbase;
Index: libexec/ld.elf_so/tls.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/libexec/ld.elf_so/tls.c,v
retrieving revision 1.5
diff -u -p -r1.5 tls.c
--- libexec/ld.elf_so/tls.c 29 Mar 2011 20:56:35 -0000 1.5
+++ libexec/ld.elf_so/tls.c 2 Apr 2011 20:47:40 -0000
@@ -280,8 +280,10 @@ __tls_get_addr(void *arg_)
void **dtv;
#ifdef __HAVE___LWP_GETTCB_FAST
struct tls_tcb * const tcb = __lwp_gettcb_fast();
-#else
+#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
struct tls_tcb * const tcb = __lwp_getprivate_fast();
+#else
+ struct tls_tcb * const tcb = _lwp_getprivate();
#endif
size_t idx = arg[0], offset = arg[1] + TLS_DTV_OFFSET;
Index: libexec/ld.elf_so/arch/arm/mdreloc.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/libexec/ld.elf_so/arch/arm/mdreloc.c,v
retrieving revision 1.35
diff -u -p -r1.35 mdreloc.c
--- libexec/ld.elf_so/arch/arm/mdreloc.c 25 Mar 2011 18:07:05 -0000
1.35
+++ libexec/ld.elf_so/arch/arm/mdreloc.c 2 Apr 2011 21:24:37 -0000
@@ -179,6 +179,59 @@ _rtld_relocate_nonplt_objects(Obj_Entry
rdbg(("COPY (avoid in main)"));
break;
+ case R_TYPE(TLS_DTPOFF32):
+ def = _rtld_find_symdef(symnum, obj, &defobj, false);
+ if (def == NULL)
+ return -1;
+
+ tmp = (Elf_Addr)(def->st_value);
+ if (__predict_true(RELOC_ALIGNED_P(where)))
+ *where = tmp;
+ else
+ store_ptr(where, tmp);
+
+ rdbg(("TLS_DTPOFF32 %s in %s --> %p",
+ obj->strtab + obj->symtab[symnum].st_name,
+ obj->path, (void *)tmp));
+
+ break;
+ case R_TYPE(TLS_DTPMOD32):
+ def = _rtld_find_symdef(symnum, obj, &defobj, false);
+ if (def == NULL)
+ return -1;
+
+ tmp = (Elf_Addr)(defobj->tlsindex);
+ if (__predict_true(RELOC_ALIGNED_P(where)))
+ *where = tmp;
+ else
+ store_ptr(where, tmp);
+
+ rdbg(("TLS_DTPMOD32 %s in %s --> %p",
+ obj->strtab + obj->symtab[symnum].st_name,
+ obj->path, (void *)tmp));
+
+ break;
+
+ case R_TYPE(TLS_TPOFF32):
+ def = _rtld_find_symdef(symnum, obj, &defobj, false);
+ if (def == NULL)
+ return -1;
+
+ if (!defobj->tls_done &&
+ _rtld_tls_offset_allocate(obj))
+ return -1;
+
+ tmp = (Elf_Addr)def->st_value + defobj->tlsoffset +
+ sizeof(struct tls_tcb);
+ if (__predict_true(RELOC_ALIGNED_P(where)))
+ *where = tmp;
+ else
+ store_ptr(where, tmp);
+ rdbg(("TLS_TPOFF32 %s in %s --> %p",
+ obj->strtab + obj->symtab[symnum].st_name,
+ obj->path, (void *)tmp));
+ break;
+
default:
rdbg(("sym = %lu, type = %lu, offset = %p, "
"contents = %p, symbol = %s",
Index: sys/arch/arm/include/types.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/sys/arch/arm/include/types.h,v
retrieving revision 1.18
diff -u -p -r1.18 types.h
--- sys/arch/arm/include/types.h 22 Dec 2010 01:04:23 -0000 1.18
+++ sys/arch/arm/include/types.h 2 Apr 2011 20:48:09 -0000
@@ -83,7 +83,9 @@ typedef volatile int __cpu_simple_lock_
#define __HAVE_SYSCALL_INTERN
#define __HAVE_MINIMAL_EMUL
-#define __HAVE_CPU_DATA_FIRST
+#define __HAVE_CPU_DATA_FIRST
+#define __HAVE_COMMON___TLS_GET_ADDR
+#define __HAVE_TLS_VARIANT_I
#if defined(_KERNEL)
#define __HAVE_RAS
Home |
Main Index |
Thread Index |
Old Index