From owner-svn-src-head@freebsd.org Tue Aug 21 18:22:15 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D33F1107B279; Tue, 21 Aug 2018 18:22:14 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 880948F943; Tue, 21 Aug 2018 18:22:14 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5049427A6E; Tue, 21 Aug 2018 18:22:14 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7LIMEVi084460; Tue, 21 Aug 2018 18:22:14 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7LIMCg4084453; Tue, 21 Aug 2018 18:22:12 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <201808211822.w7LIMCg4084453@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Tue, 21 Aug 2018 18:22:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338149 - in head/libexec/rtld-elf: . aarch64 arm mips powerpc powerpc64 riscv X-SVN-Group: head X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: in head/libexec/rtld-elf: . aarch64 arm mips powerpc powerpc64 riscv X-SVN-Commit-Revision: 338149 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2018 18:22:15 -0000 Author: brooks Date: Tue Aug 21 18:22:12 2018 New Revision: 338149 URL: https://svnweb.freebsd.org/changeset/base/338149 Log: Revert r337978: Rework rtld's TLS Variant I implementation to match r326794 Michal Meloun reports that it breaks ctype (isspace()..) related functions on armv7 so back out while we diagnose the issue. Reported by: Michal Meloun Modified: head/libexec/rtld-elf/aarch64/rtld_machdep.h head/libexec/rtld-elf/arm/rtld_machdep.h head/libexec/rtld-elf/mips/rtld_machdep.h head/libexec/rtld-elf/powerpc/rtld_machdep.h head/libexec/rtld-elf/powerpc64/rtld_machdep.h head/libexec/rtld-elf/riscv/rtld_machdep.h head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/aarch64/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/aarch64/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/aarch64/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -69,8 +69,6 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr targe #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) \ - round(TLS_TCB_SIZE, align) - TLS_TCB_SIZE #define TLS_TCB_SIZE 16 typedef struct { Modified: head/libexec/rtld-elf/arm/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/arm/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/arm/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -69,8 +69,6 @@ typedef struct { #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) \ - round(TLS_TCB_SIZE, align) - TLS_TCB_SIZE extern void *__tls_get_addr(tls_index *ti); Modified: head/libexec/rtld-elf/mips/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/mips/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/mips/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -64,11 +64,10 @@ typedef struct { #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) #define calculate_first_tls_offset(size, align) \ - TLS_TCB_SIZE + round(TLS_TCB_SIZE, align) #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) 0 extern void *__tls_get_addr(tls_index *ti); Modified: head/libexec/rtld-elf/powerpc/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/powerpc/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/powerpc/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -74,11 +74,10 @@ void _rtld_powerpc_pltcall(void); #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) #define calculate_first_tls_offset(size, align) \ - TLS_TCB_SIZE + round(8, align) #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) 0 typedef struct { unsigned long ti_module; Modified: head/libexec/rtld-elf/powerpc64/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/powerpc64/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/powerpc64/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -66,11 +66,10 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr targe #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) #define calculate_first_tls_offset(size, align) \ - TLS_TCB_SIZE + round(16, align) #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) 0 typedef struct { unsigned long ti_module; Modified: head/libexec/rtld-elf/riscv/rtld_machdep.h ============================================================================== --- head/libexec/rtld-elf/riscv/rtld_machdep.h Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/riscv/rtld_machdep.h Tue Aug 21 18:22:12 2018 (r338149) @@ -89,11 +89,10 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr targe #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) #define calculate_first_tls_offset(size, align) \ - TLS_TCB_SIZE + round(16, align) #define calculate_tls_offset(prev_offset, prev_size, size, align) \ round(prev_offset + prev_size, align) #define calculate_tls_end(off, size) ((off) + (size)) -#define calculate_tls_post_size(align) 0 typedef struct { unsigned long ti_module; Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Tue Aug 21 17:13:51 2018 (r338148) +++ head/libexec/rtld-elf/rtld.c Tue Aug 21 18:22:12 2018 (r338149) @@ -4693,87 +4693,47 @@ tls_get_addr_common(Elf_Addr **dtvp, int index, size_t defined(__powerpc__) || defined(__riscv) /* - * Return pointer to allocated TLS block - */ -static void * -get_tls_block_ptr(void *tcb, size_t tcbsize) -{ - size_t extra_size, post_size, pre_size, tls_block_size; - size_t tls_init_align; - - tls_init_align = MAX(obj_main->tlsalign, 1); - - /* Compute fragments sizes. */ - extra_size = tcbsize - TLS_TCB_SIZE; - post_size = calculate_tls_post_size(tls_init_align); - tls_block_size = tcbsize + post_size; - pre_size = roundup2(tls_block_size, tls_init_align) - tls_block_size; - - return ((char *)tcb - pre_size - extra_size); -} - -/* * Allocate Static TLS using the Variant I method. - * - * For details on the layout, see lib/libc/gen/tls.c. - * - * NB: rtld's tls_static_space variable includes TLS_TCB_SIZE and post_size as - * it is based on tls_last_offset, and TLS offsets here are really TCB - * offsets, whereas libc's tls_static_space is just the executable's static - * TLS segment. */ void * allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign) { Obj_Entry *obj; - char *tls_block; - Elf_Addr *dtv, **tcb; + char *tcb; + Elf_Addr **tls; + Elf_Addr *dtv; Elf_Addr addr; int i; - size_t extra_size, maxalign, post_size, pre_size, tls_block_size; - size_t tls_init_align; if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE) return (oldtcb); assert(tcbsize >= TLS_TCB_SIZE); - maxalign = MAX(tcbalign, tls_static_max_align); - tls_init_align = MAX(obj_main->tlsalign, 1); + tcb = xcalloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize); + tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); - /* Compute fragmets sizes. */ - extra_size = tcbsize - TLS_TCB_SIZE; - post_size = calculate_tls_post_size(tls_init_align); - tls_block_size = tcbsize + post_size; - pre_size = roundup2(tls_block_size, tls_init_align) - tls_block_size; - tls_block_size += pre_size + tls_static_space - TLS_TCB_SIZE - post_size; - - /* Allocate whole TLS block */ - tls_block = malloc_aligned(tls_block_size, maxalign); - tcb = (Elf_Addr **)(tls_block + pre_size + extra_size); - if (oldtcb != NULL) { - memcpy(tls_block, get_tls_block_ptr(oldtcb, tcbsize), - tls_static_space); - free_aligned(get_tls_block_ptr(oldtcb, tcbsize)); + memcpy(tls, oldtcb, tls_static_space); + free(oldtcb); /* Adjust the DTV. */ - dtv = tcb[0]; + dtv = tls[0]; for (i = 0; i < dtv[1]; i++) { if (dtv[i+2] >= (Elf_Addr)oldtcb && dtv[i+2] < (Elf_Addr)oldtcb + tls_static_space) { - dtv[i+2] = dtv[i+2] - (Elf_Addr)oldtcb + (Elf_Addr)tcb; + dtv[i+2] = dtv[i+2] - (Elf_Addr)oldtcb + (Elf_Addr)tls; } } } else { dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); - tcb[0] = dtv; + tls[0] = dtv; dtv[0] = tls_dtv_generation; dtv[1] = tls_max_index; for (obj = globallist_curr(objs); obj != NULL; obj = globallist_next(obj)) { if (obj->tlsoffset > 0) { - addr = (Elf_Addr)tcb + obj->tlsoffset; + addr = (Elf_Addr)tls + obj->tlsoffset; if (obj->tlsinitsize > 0) memcpy((void*) addr, obj->tlsinit, obj->tlsinitsize); if (obj->tlssize > obj->tlsinitsize) @@ -4792,19 +4752,14 @@ free_tls(void *tcb, size_t tcbsize, size_t tcbalign) { Elf_Addr *dtv; Elf_Addr tlsstart, tlsend; - size_t post_size; - size_t dtvsize, i, tls_init_align; + int dtvsize, i; assert(tcbsize >= TLS_TCB_SIZE); - tls_init_align = MAX(obj_main->tlsalign, 1); - /* Compute fragments sizes. */ - post_size = calculate_tls_post_size(tls_init_align); + tlsstart = (Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE; + tlsend = tlsstart + tls_static_space; - tlsstart = (Elf_Addr)tcb + TLS_TCB_SIZE + post_size; - tlsend = (Elf_Addr)tcb + tls_static_space; - - dtv = *(Elf_Addr **)tcb; + dtv = *(Elf_Addr **)tlsstart; dtvsize = dtv[1]; for (i = 0; i < dtvsize; i++) { if (dtv[i+2] && (dtv[i+2] < tlsstart || dtv[i+2] >= tlsend)) { @@ -4812,7 +4767,7 @@ free_tls(void *tcb, size_t tcbsize, size_t tcbalign) } } free(dtv); - free_aligned(get_tls_block_ptr(tcb, tcbsize)); + free(tcb); } #endif