Index: contrib/jemalloc/include/jemalloc/jemalloc_FreeBSD.h =================================================================== --- contrib/jemalloc/include/jemalloc/jemalloc_FreeBSD.h +++ contrib/jemalloc/include/jemalloc/jemalloc_FreeBSD.h @@ -46,6 +46,7 @@ #else # define LG_SIZEOF_PTR 2 #endif +# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) #endif #ifdef __powerpc64__ # define LG_SIZEOF_PTR 3 Index: lib/libc/mips/gen/_set_tp.c =================================================================== --- lib/libc/mips/gen/_set_tp.c +++ lib/libc/mips/gen/_set_tp.c @@ -30,11 +30,12 @@ #include #include +#include #include "libc_private.h" void _set_tp(void *tp) { - sysarch(MIPS_SET_TLS, tp); + sysarch(MIPS_SET_TLS, (char *)tp + TLS_TP_OFFSET + TLS_TCB_SIZE); } Index: lib/libthr/arch/mips/include/pthread_md.h =================================================================== --- lib/libthr/arch/mips/include/pthread_md.h +++ lib/libthr/arch/mips/include/pthread_md.h @@ -40,6 +40,7 @@ #define CPU_SPINWAIT #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) +#define TP_OFFSET (TLS_TP_OFFSET + TLS_TCB_SIZE) /* * Variant I tcb. The structure layout is fixed, don't blindly @@ -55,7 +56,7 @@ _tcb_set(struct tcb *tcb) { - sysarch(MIPS_SET_TLS, tcb); + sysarch(MIPS_SET_TLS, (char *)tcb + TP_OFFSET); } /* @@ -64,10 +65,10 @@ static __inline struct tcb * _tcb_get(void) { - struct tcb *tcb; + char *tcb; sysarch(MIPS_GET_TLS, &tcb); - return tcb; + return (struct tcb *)(tcb - TP_OFFSET); } extern struct pthread *_thr_initial; Index: libexec/rtld-elf/mips/reloc.c =================================================================== --- libexec/rtld-elf/mips/reloc.c +++ libexec/rtld-elf/mips/reloc.c @@ -621,7 +621,7 @@ allocate_initial_tls(Obj_Entry *objs) { char *tls; - + /* * Fix the size of the static TLS block by using the maximum * offset allocated so far and adding a bit for dynamic modules to @@ -629,7 +629,8 @@ */ tls_static_space = tls_last_offset + tls_last_size + RTLD_STATIC_TLS_EXTRA; - tls = (char *) allocate_tls(objs, NULL, TLS_TCB_SIZE, 8); + tls = (char *)allocate_tls(objs, NULL, TLS_TCB_SIZE, 8) + + TLS_TP_OFFSET + TLS_TCB_SIZE; sysarch(MIPS_SET_TLS, tls); } @@ -637,12 +638,13 @@ void * __tls_get_addr(tls_index* ti) { - Elf_Addr** tls; + Elf_Addr** tp; char *p; - sysarch(MIPS_GET_TLS, &tls); + sysarch(MIPS_GET_TLS, &tp); - p = tls_get_addr_common(tls, ti->ti_module, ti->ti_offset + TLS_DTP_OFFSET); + p = tls_get_addr_common((Elf_Addr**)((Elf_Addr)tp - TLS_TP_OFFSET + - TLS_TCB_SIZE), ti->ti_module, ti->ti_offset); - return (p); + return (p + TLS_DTP_OFFSET); } Index: sys/mips/mips/trap.c =================================================================== --- sys/mips/mips/trap.c +++ sys/mips/mips/trap.c @@ -899,12 +899,6 @@ if (inst.RType.rd == 29) { frame_regs = &(trapframe->zero); frame_regs[inst.RType.rt] = (register_t)(intptr_t)td->td_md.md_tls; -#if defined(__mips_n64) && defined(COMPAT_FREEBSD32) - if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) - frame_regs[inst.RType.rt] += TLS_TP_OFFSET + TLS_TCB_SIZE32; - else -#endif - frame_regs[inst.RType.rt] += TLS_TP_OFFSET + TLS_TCB_SIZE; trapframe->pc += sizeof(int); goto out; } Index: sys/mips/mips/vm_machdep.c =================================================================== --- sys/mips/mips/vm_machdep.c +++ sys/mips/mips/vm_machdep.c @@ -492,7 +492,7 @@ cpu_set_user_tls(struct thread *td, void *tls_base) { - td->td_md.md_tls = (char*)tls_base; + td->td_md.md_tls = (char*)tls_base + TLS_TP_OFFSET + TLS_TCP_SIZE; return (0); }