From patchwork Wed Nov 28 21:03:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 202548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EC2132C008C for ; Thu, 29 Nov 2012 08:03:46 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1354741427; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=jkeQ+TG tX2Nb4Ju99+5z2PToztk=; b=M9xcC92G7FXIrGUx1wdXaKU0ZY3haQEPE2S1UJv 6cPdCbkfxLD8XAyScwud6cWqgseZt0+tkSBwrI+SnP6JImWFbiHeIq8IrucdzRm6 c94/2lBQVrNmcmh8rPPFhs7PRgS969Zb8mGC7+sEfnC7imeXJ6g+9vgtJ4KlgAgr TRl8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Wp04fROUidslSDwbmK7U/F4Wrpn9r4g20Yh8UHmz6uay49EJlogtzZW0iQHi1p QA+d9bQSQ2AO2BQH90qNoh2IkU9KRvmQvVEh5pY7GoZL3lCRog9CfHdMZQPjTusd FZzMegUql8OVxGPI3FqqWcRDe0DIp7sjJVGO6YllHRMgI=; Received: (qmail 11728 invoked by alias); 28 Nov 2012 21:03:43 -0000 Received: (qmail 11717 invoked by uid 22791); 28 Nov 2012 21:03:42 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Nov 2012 21:03:34 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qASL3XH7022268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Nov 2012 16:03:33 -0500 Received: from anchor.twiddle.home (vpn-227-95.phx2.redhat.com [10.3.227.95]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qASL3XbO011664 for ; Wed, 28 Nov 2012 16:03:33 -0500 Message-ID: <50B67C25.5020502@redhat.com> Date: Wed, 28 Nov 2012 13:03:33 -0800 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: GCC Patches Subject: [4.8] Fix PR48076 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Thanks to Torvald for the many sanity checks analyzing this problem. Tested on x86_64 and alpha-linux. r~ PR libgcc/48076 * emutls.c (__emutls_get_address): Avoid race condition between obj->loc.offset read and emutls_key initialization. diff --git a/libgcc/emutls.c b/libgcc/emutls.c index 22ea440..f1b653b 100644 --- a/libgcc/emutls.c +++ b/libgcc/emutls.c @@ -136,7 +136,7 @@ __emutls_get_address (struct __emutls_object *obj) #ifndef __GTHREADS abort (); #else - pointer offset = obj->loc.offset; + pointer offset = __atomic_load_n (&obj->loc.offset, __ATOMIC_ACQUIRE); if (__builtin_expect (offset == 0, 0)) { @@ -147,7 +147,7 @@ __emutls_get_address (struct __emutls_object *obj) if (offset == 0) { offset = ++emutls_size; - obj->loc.offset = offset; + __atomic_store_n (&obj->loc.offset, offset, __ATOMIC_RELEASE); } __gthread_mutex_unlock (&emutls_mutex); }