From patchwork Sun Dec 9 19:08:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 204773 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 D743B2C0193 for ; Mon, 10 Dec 2012 06:08:34 +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=1355684915; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type: Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=IdTXCvYYzJFE/eVwFGcxO2d4/Tg=; b=tQ7D0oftQtW6H3i Y6hKPBvxEyvL5nrd4NGDzVct6ezrbeMPcL0jaPMwY7NLuDDOr5o/rUGt41zWxAFd ijNOMwcb5xKJgP4C6XWINcTnDLWgOOPeIHtC2ZthTyIGyGYd+re0bRnl9GM7yhKB NorYGtpKSY2oJ7Trr8Q6E14YdwSo= 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:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cZhVISmm0gETJaRXF0hC2GYgXooYW96cbloSwViChl7HO7txRZw7oqmVyOo7eF mxQ8JO+gXROZEpuV0OrOadNOwH4lgrTx6gVYKR3iM67/wLX0irPN89H+ez2fcMhU c89tqYfQlYZFwIEaTsNbNjAAhTrUoGLSfzDg1AwBysHso=; Received: (qmail 24498 invoked by alias); 9 Dec 2012 19:08:29 -0000 Received: (qmail 24475 invoked by uid 22791); 9 Dec 2012 19:08:28 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from hiauly1.hia.nrc.ca (HELO hiauly1.hia.nrc.ca) (132.246.10.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 09 Dec 2012 19:08:22 +0000 Received: by hiauly1.hia.nrc.ca (Postfix, from userid 1000) id 5EFDD4CF1; Sun, 9 Dec 2012 14:08:15 -0500 (EST) Date: Sun, 9 Dec 2012 14:08:14 -0500 From: John David Anglin To: gcc-patches@gcc.gnu.org Subject: [PATCH, libbacktrace] Don't call __sync_lock_test_and_set if we don't have sync functions Message-ID: <20121209190812.GA20280@hiauly1.hia.nrc.ca> Reply-To: John David Anglin MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) 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 On hppa*-*-hpux*, we don't have sync functions. However, __sync_lock_test_and_set is called in backtrace_alloc and backtrace_free. This causes an abort before ICE proccessing is fully complete. hppa64 is an ELF target and backtraces are nominally supported. The attached change avoids calling __sync_lock_test_and_set if we don't have sync functions. As a result, the memory is leaked. This fixes the btest failure. OK for trunk? Dave Index: mmap.c =================================================================== --- mmap.c (revision 194055) +++ mmap.c (working copy) @@ -49,6 +49,10 @@ #define MAP_ANONYMOUS MAP_ANON #endif +#ifndef HAVE_SYNC_FUNCTIONS +#define HAVE_SYNC_FUNCTIONS 0 +#endif + /* A list of free memory blocks. */ struct backtrace_freelist_struct @@ -96,7 +100,7 @@ using mmap. __sync_lock_test_and_set returns the old state of the lock, so we have acquired it if it returns 0. */ - if (!__sync_lock_test_and_set (&state->lock_alloc, 1)) + if (HAVE_SYNC_FUNCTIONS && !__sync_lock_test_and_set (&state->lock_alloc, 1)) { for (pp = &state->freelist; *pp != NULL; pp = &(*pp)->next) { @@ -158,7 +162,7 @@ If we can't acquire the lock, just leak the memory. __sync_lock_test_and_set returns the old state of the lock, so we have acquired it if it returns 0. */ - if (!__sync_lock_test_and_set (&state->lock_alloc, 1)) + if (HAVE_SYNC_FUNCTIONS && !__sync_lock_test_and_set (&state->lock_alloc, 1)) { backtrace_free_locked (state, addr, size);