From patchwork Tue Nov 20 20:16:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 200503 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 D92F52C009F for ; Wed, 21 Nov 2012 07:20:45 +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=1354047647; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:Subject:From:To:Cc: In-Reply-To:References:Content-Type:Date:Message-ID:Mime-Version: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=jI67IUKVsQnAcJyCJ/wzHipleWQ=; b=WnM5/DeE9WfkB0W YsPEzKa9PpUEFYQQiAh8XOJaDxI27VhJE1kHKcRnKlNHP66oPmTRpPl3IDRY7P3G iPCwpF/4/YvENGdzLFfBisCnCYzkwUIErW9/OzK3V9dx3VDsqdNyOpGSbSuwYqh9 K4CxtDE+ti3pWk2AiFhwP3mfATU0= 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:Received:Received:Received:Received:Subject:From:To:Cc:In-Reply-To:References:Content-Type:Date:Message-ID:Mime-Version:Content-Transfer-Encoding:X-Content-Scanned:x-cbid:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=shGBfc2cXgF6rCbDuin6zFaFGYLdwMb0/d8yEIpK0IsrB155MbOiXh2aTWcwQm j4QTJQGzByMCCOhNuaAbT0NMYDcJZk522nln3Q3DWo5/vWTxewfIXdpjVvomkZyH soQvoDmwlsBPSEOtnFGmLe/XAGCuVzb1t4wVDXV56yteg=; Received: (qmail 5279 invoked by alias); 20 Nov 2012 20:20:28 -0000 Received: (qmail 5206 invoked by uid 22791); 20 Nov 2012 20:20:25 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from e39.co.us.ibm.com (HELO e39.co.us.ibm.com) (32.97.110.160) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Nov 2012 20:20:19 +0000 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Nov 2012 13:20:18 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e39.co.us.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Nov 2012 13:20:15 -0700 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 54BA019D8036 for ; Tue, 20 Nov 2012 13:20:15 -0700 (MST) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qAKKK1nE301304 for ; Tue, 20 Nov 2012 13:20:04 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qAKKK18R010523 for ; Tue, 20 Nov 2012 13:20:01 -0700 Received: from [192.168.1.113] (vorma.rchland.ibm.com [9.10.86.174]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qAKKJxS3010386; Tue, 20 Nov 2012 13:20:00 -0700 Subject: Re: [PATCH, RFC] Enable libsanitizer on powerpc{,64} From: Peter Bergner To: Konstantin Serebryany Cc: Evgeniy Stepanov , "gcc-patches@gcc.gnu.org" , Alexey Samsonov , Alexander Potapenko , Dmitry Vyukov In-Reply-To: References: <1353107286.17833.36.camel@otta> <1353355471.17833.58.camel@otta> <1353418876.17833.101.camel@otta> <1353438480.17833.118.camel@otta> Date: Tue, 20 Nov 2012 14:16:44 -0600 Message-ID: <1353442604.17833.131.camel@otta> Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12112020-3620-0000-0000-0000006B496D 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 On Tue, 2012-11-20 at 23:24 +0400, Konstantin Serebryany wrote: > On Tue, Nov 20, 2012 at 11:08 PM, Peter Bergner wrote: > > diff -urpN -X /home/bergner/cvs/dontdiff gcc-fsf-mainline-kcc/libsanitizer/sanitizer_common/sanitizer_stacktrace.h gcc-fsf-mainline-asan/libsanitizer/sanitizer_common/sanitizer_stacktrace.h > > --- gcc-fsf-mainline-kcc/libsanitizer/sanitizer_common/sanitizer_stacktrace.h 2012-11-20 11:42:08.821389243 -0600 > > +++ gcc-fsf-mainline-asan/libsanitizer/sanitizer_common/sanitizer_stacktrace.h 2012-11-20 11:12:44.551390980 -0600 > > @@ -23,6 +23,7 @@ struct StackTrace { > > uptr size; > > uptr max_size; > > uptr trace[kStackTraceMax]; > > + uptr frame[kStackTraceMax]; // For use by _Unwind_Backtrace architectures. > > This is bad. The objects of this type are already too big, we should > not make them 2x larger. > Hopefully Evgeniy can handle this tomorrow. Ok, here's another attempt that doesn't require storing the frame pointers. In this case, we pass down the frame pointer we're looking for into the unwind code and if we come across it while building up the trace, we immediately empty the trace and start over, effectively popping the ASAN functions from the trace. If we never encounter the passed down frame pointer, then the code will just behave as before. Thoughts? Peter diff -urpN -X /home/bergner/cvs/dontdiff gcc-fsf-mainline-kcc/LAST_UPDATED gcc-fsf-mainline-asan/LAST_UPDATED --- gcc-fsf-mainline-kcc/LAST_UPDATED 2012-11-20 11:40:17.232777673 -0600 +++ gcc-fsf-mainline-asan/LAST_UPDATED 2012-11-19 10:33:36.362778406 -0600 @@ -1,2 +1,2 @@ -Tue Nov 20 11:40:17 CST 2012 -Tue Nov 20 17:40:17 UTC 2012 (revision 193626) +Mon Nov 19 10:33:36 CST 2012 +Mon Nov 19 16:33:36 UTC 2012 (revision 193626) diff -urpN -X /home/bergner/cvs/dontdiff gcc-fsf-mainline-kcc/libsanitizer/asan/asan_linux.cc gcc-fsf-mainline-asan/libsanitizer/asan/asan_linux.cc --- gcc-fsf-mainline-kcc/libsanitizer/asan/asan_linux.cc 2012-11-20 12:52:33.961664485 -0600 +++ gcc-fsf-mainline-asan/libsanitizer/asan/asan_linux.cc 2012-11-20 14:12:31.231751746 -0600 @@ -141,11 +141,27 @@ uptr Unwind_GetIP(struct _Unwind_Context #endif } +uptr Unwind_GetBP(struct _Unwind_Context *ctx) { + return _Unwind_GetCFA(ctx); +} + +struct Unwind_Trace_Info { + StackTrace *stack; + uptr bp; +}; + _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) { - StackTrace *b = (StackTrace*)param; - CHECK(b->size < b->max_size); + Unwind_Trace_Info *p = (Unwind_Trace_Info *)param; + StackTrace *b = p->stack; uptr pc = Unwind_GetIP(ctx); + if (Unwind_GetBP(ctx) == p->bp) { + // We just encountered the frame pointer we want to start + // our backtrace with, so empty the backtrace before adding + // this frame to the backtrace. + b->size = 0; + } + CHECK(b->size < b->max_size); b->trace[b->size++] = pc; if (b->size == b->max_size) return UNWIND_STOP; return UNWIND_CONTINUE; @@ -157,9 +173,10 @@ void GetStackTrace(StackTrace *stack, up if ((max_s) > 1) { stack->max_size = max_s; #if defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__) - _Unwind_Backtrace(Unwind_Trace, stack); - // Pop off the two ASAN functions from the backtrace. - stack->PopStackFrames(2); + Unwind_Trace_Info param; + param.stack = stack; + param.bp = bp; + _Unwind_Backtrace(Unwind_Trace, ¶m); #else if (!asan_inited) return; if (AsanThread *t = asanThreadRegistry().GetCurrent())