From patchwork Tue Nov 20 19:08:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 200496 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 3BB0F2C0080 for ; Wed, 21 Nov 2012 06:08:24 +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=1354043306; 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=ckWn1eY+3I+LjMUZjEUlgWAFca0=; b=mumezex2D8gO4iJ /r/gSfb1gSug+0lAh8VrD4834aBonEJCEqPBMNJlsZb/6WVg5/eIOMwg+beyyX5t /Xw6xq5PtkD5leLEI3oAwXFmSEv2ifmeN5cXlB2UvNuHXVzNEbwOjia0nWf8CjgE 7y4q/OP5GteSeFrsVqvDXpa4Has4= 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=sCuD6+MZseD2dJxjC+wzFKjIwoKZm0bgrS33B0kmypu53Bp6Rfw+bCpBf5C7Tb lztplDoKP2GVVsX+oXODQl9IPLzxak4hiMzDHMMnKgCvdacD0NqgcjKuBMFulVCt 5SEBm64dx856yZC7jae+/xUlCTPlewulNJa3MunEYhNqE=; Received: (qmail 15105 invoked by alias); 20 Nov 2012 19:08:14 -0000 Received: (qmail 15081 invoked by uid 22791); 20 Nov 2012 19:08:13 -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 e9.ny.us.ibm.com (HELO e9.ny.us.ibm.com) (32.97.182.139) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Nov 2012 19:08:05 +0000 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Nov 2012 14:08:03 -0500 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e9.ny.us.ibm.com (192.168.1.109) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Nov 2012 14:08:03 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 1024FC90046 for ; Tue, 20 Nov 2012 14:08:02 -0500 (EST) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qAKJ81R3301594 for ; Tue, 20 Nov 2012 14:08:01 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qAKJ81Rd022041 for ; Tue, 20 Nov 2012 17:08:01 -0200 Received: from [192.168.1.113] (vorma.rchland.ibm.com [9.10.86.174]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qAKJ80hU021912; Tue, 20 Nov 2012 17:08:00 -0200 Subject: Re: [PATCH, RFC] Enable libsanitizer on powerpc{,64} From: Peter Bergner To: Evgeniy Stepanov Cc: Konstantin Serebryany , "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> Date: Tue, 20 Nov 2012 13:08:00 -0600 Message-ID: <1353438480.17833.118.camel@otta> Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12112019-7182-0000-0000-0000034C067A 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 18:18 +0400, Evgeniy Stepanov wrote: > I wonder if under some conditions we may get a different number of > extra frames (inlining comes to mind). What do you think of removing > any number of frames that belong to the runtime library - we have > memory layout info for that? How about the following hack that needs to be cleaned up, but does work for me. It scans through the trace looking for the frame pointer that is passed in and if it finds it, it pops the stack up to that point. If it doesn't find it (a bug?), it just leaves the trace alone. Maybe it fixes the ARM Android issue you just ran into? Peter 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 11:28:00.646245908 -0600 @@ -141,12 +141,19 @@ uptr Unwind_GetIP(struct _Unwind_Context #endif } +uptr Unwind_GetBP(struct _Unwind_Context *ctx) { + return _Unwind_GetCFA(ctx); +} + _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) { StackTrace *b = (StackTrace*)param; CHECK(b->size < b->max_size); uptr pc = Unwind_GetIP(ctx); - b->trace[b->size++] = pc; + uptr bp = Unwind_GetBP(ctx); + b->trace[b->size] = pc; + b->frame[b->size] = bp; + b->size++; if (b->size == b->max_size) return UNWIND_STOP; return UNWIND_CONTINUE; } @@ -158,8 +165,13 @@ void GetStackTrace(StackTrace *stack, up 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); + // Attempt to pop off the ASAN functions from the backtrace. + uptr cnt; + for (cnt = 0; cnt < stack->size; cnt++) + if (stack->frame[cnt] == bp) { + stack->PopStackFrames(cnt); + break; + } #else if (!asan_inited) return; if (AsanThread *t = asanThreadRegistry().GetCurrent()) diff -urpN -X /home/bergner/cvs/dontdiff gcc-fsf-mainline-kcc/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc gcc-fsf-mainline-asan/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc --- gcc-fsf-mainline-kcc/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc 2012-11-20 11:42:08.834439704 -0600 +++ gcc-fsf-mainline-asan/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc 2012-11-20 12:59:29.896106625 -0600 @@ -144,7 +144,8 @@ void StackTrace::PopStackFrames(uptr cou CHECK(size > count); size -= count; for (uptr i = 0; i < size; i++) { - trace[i] = trace[i + count]; + trace[i] = trace[i+count]; + frame[i] = frame[i+count]; } } 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. static void PrintStack(const uptr *addr, uptr size, bool symbolize, const char *strip_file_prefix, SymbolizeCallback symbolize_callback);