From patchwork Tue Apr 9 11:04:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Sionneau X-Patchwork-Id: 1082139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=kalray.eu Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=kalray.eu header.i=@kalray.eu header.b="U5KpYbwx"; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44dkvY20Knz9sSC for ; Tue, 9 Apr 2019 21:04:41 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 5E0CD106A5; Tue, 9 Apr 2019 13:04:37 +0200 (CEST) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from zimbra2.kalray.eu (zimbra2.kalray.eu [92.103.151.219]) by helium.openadk.org (Postfix) with ESMTPS id 835D2102E5 for ; Tue, 9 Apr 2019 13:04:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id 6393927E0492 for ; Tue, 9 Apr 2019 13:04:36 +0200 (CEST) Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 03mRgUqw3-DR; Tue, 9 Apr 2019 13:04:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id A1B0227E0491; Tue, 9 Apr 2019 13:04:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra2.kalray.eu A1B0227E0491 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalray.eu; s=32AE1B44-9502-11E5-BA35-3734643DEF29; t=1554807875; bh=y9eOGPVbvfRYpf8UPvfajP+wOHZ8xu8NxUvf1J5zoyk=; h=From:To:Date:Message-Id:MIME-Version; b=U5KpYbwxR3wOqjD8A5yw5SEkifMfIyEknRTs65k0EmTec0Z+2abIhkL1TNUKOmMkW 1JA3o9thygD43R1Rfxb41LWATWVXr0W1e/zcBaaO3xocN5RJc2l8zDXSN++sfSqy6G mkBbejq9Q4XjCZwBY2PJk/Taod8DTIt/qsgIE848= X-Virus-Scanned: amavisd-new at zimbra2.kalray.eu Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id DIt9uDxjVmwP; Tue, 9 Apr 2019 13:04:35 +0200 (CEST) Received: from junon.lin.mbt.kalray.eu (unknown [192.168.37.161]) by zimbra2.kalray.eu (Postfix) with ESMTPSA id 7F21B27E02F3; Tue, 9 Apr 2019 13:04:35 +0200 (CEST) From: Yann Sionneau To: devel@uclibc-ng.org Date: Tue, 9 Apr 2019 13:04:21 +0200 Message-Id: <20190409110421.23987-1-ysionneau@kalray.eu> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [uclibc-ng-devel] [PATCH] Fix _dl_deallocate_tls in !SHARED case X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" This patch seems needed in builds where - SHARED is not defined (no shared lib support) - and USE_TLS is set Without this patch, static_dtv is free'ed. See the following backtrace: 0 __do_check_chunk (p=0x52638 ) at libc/stdlib/malloc-standard/malloc.c:80 1 0x0000000000017fa0 in __do_check_inuse_chunk (p=0x52638 ) at libc/stdlib/malloc-standard/malloc.c:143 2 0x0000000000017354 in free (mem=0x52648 ) at libc/stdlib/malloc-standard/free.c:293 3 0x000000000002d5b0 in _dl_deallocate_tls (tcb=0x58690, dealloc_tcb=false) at libpthread/nptl/sysdeps/generic/dl-tls.c:588 4 0x0000000000021c0c in __deallocate_stack (pd=0x58000) at libpthread/nptl/allocatestack.c:717 5 0x0000000000024408 in __free_tcb (pd=0x58000) at libpthread/nptl/pthread_create.c:217 6 0x00000000000200ac in pthread_join (threadid=360448, thread_return=0x0 ) at libpthread/nptl/pthread_join.c:109 7 0x0000000000010354 in tf (a=0x58000) at tst-basic3.c:42 8 0x00000000000247c8 in start_thread (arg=0x4000200960) at libpthread/nptl/pthread_create.c:285 9 0x0000000000026560 in ?? () This backtrace is obtained while debugging tst-basic3 from the uclibc-ng nptl testsuite. It aborts because of the assert in malloc: https://elixir.bootlin.com/uclibc-ng/v1.0.31/source/libc/stdlib/malloc-standard/malloc.c#L80 Signed-off-by: Yann Sionneau --- libpthread/nptl/sysdeps/generic/dl-tls.c | 5 +++++ libpthread/nptl/sysdeps/generic/libc-tls.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libpthread/nptl/sysdeps/generic/dl-tls.c b/libpthread/nptl/sysdeps/generic/dl-tls.c index 989e587a2..7d25e4706 100644 --- a/libpthread/nptl/sysdeps/generic/dl-tls.c +++ b/libpthread/nptl/sysdeps/generic/dl-tls.c @@ -48,6 +48,9 @@ /* Value used for dtv entries for which the allocation is delayed. */ # define TLS_DTV_UNALLOCATED ((void *) -1l) +#ifndef SHARED +extern dtv_t static_dtv; +#endif /* Out-of-memory handler. */ # ifdef SHARED @@ -584,6 +587,8 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb) /* The array starts with dtv[-1]. */ #ifdef SHARED if (dtv != GL(dl_initial_dtv)) +#else + if ((dtv - 1) != &static_dtv) #endif free (dtv - 1); diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index a6df4cdc4..d746c9a38 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -42,7 +42,10 @@ extern size_t _dl_phnum; extern int __tdata_start; #endif -static dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS]; +#ifdef SHARED +static +#endif +dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS]; static struct