From patchwork Thu Jan 31 10:02:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 217146 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 DA1372C029F for ; Thu, 31 Jan 2013 21:03:20 +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=1360231401; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc: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=I1geHywjyHzuSPI3zc+j Iwx8zOk=; b=aZE5Ktffsf5CmKSSG3yOa7F/iFPEdoys005tt1KhR1o5FpxaGBVw XdKHu9pjnyr6XxVvd+DMqMQKNvrYNxwLuouz/BsmEIKQmfBd8NMAajWhP7W9ZoF6 gF0RqfPLkJmvYE5JtvObh2T2DGVwCYByeo813VQzzGEqOVhH+aO92BA= 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:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=hGn0LZxOLQgaUbLDZF0YMnorCzaPBXZEtmYVBYX1ht+RbCp2bxuPW6+V/Qy5x8 HeqaEJRDdvzBawHbUejUrAHcdpFo9eh/RY0iGxloFPgcbrjAZcuH6cHM+wuJkpD8 TdT7nKTNQRzz/dNqZKbhbLXjCi2U2mMt38gy+hfHBpbFU=; Received: (qmail 4906 invoked by alias); 31 Jan 2013 10:03:14 -0000 Received: (qmail 4896 invoked by uid 22791); 31 Jan 2013 10:03:13 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, 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; Thu, 31 Jan 2013 10:03:03 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0VA32kv007195 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 31 Jan 2013 05:03:02 -0500 Received: from zalov.redhat.com (vpn1-4-80.ams2.redhat.com [10.36.4.80]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0VA30rh013514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 31 Jan 2013 05:03:01 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r0VA30aY026528; Thu, 31 Jan 2013 11:03:00 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r0VA2xk6026527; Thu, 31 Jan 2013 11:02:59 +0100 Date: Thu, 31 Jan 2013 11:02:59 +0100 From: Jakub Jelinek To: Richard Henderson , Jason Merrill , Alexandre Oliva Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] If possible, include range of profile hunk before prologue in .debug_loc ranges (PR debug/54793) Message-ID: <20130131100259.GH4385@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Hi! The Linux kernel started (recently?) using -mfentry -p on x86_64/i686? for some instrumentation, I believe they normally overwrite the -mfentry prologues with nops and only when some function needs to be instrumented, overwrite it with some call or jump. The problem in this PR is that var-tracking notes that are meant to live on the very first insn in the function (info about fn arguments and the like) no longer do so, they all start after the profile prologue, so when *gdb/systemtap or similar debug info consumer inspects debug info at the beginning of the function, it thinks the arguments are optimized away. This patch attempts to extend those ranges over the profiler snippet before prologue on some targets. I'm not doing it everywhere, because some targets emit some assembly in their targetm.asm_out.function_prologue hook even for HAVE_prologue, and it is likely the profiler hook isn't prepared to handle it (think about e.g. ia64 or a few other targets). Also, sometimes the profiler code might e.g. use push/pop in it and invalidate potential sp based locations, either we could stop doing this if cfun->returns_struct or cfun->static_chain_decl, but Alex argued that it isn't any different from inline asm which uses push/pop inside of it. The debug info there is also correct only on the first insn in the inline asm and right after the inline asm, not necessary inside of it, and similarly with this patch it isn't necessarily right inside of the profiler snippet (the kernel won't care, as it overwrites the snippet with nops or call/jmp). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-31 Jakub Jelinek PR debug/54793 * final.c (need_profile_function): New variable. (final_start_function): Drop ATTRIBUTE_UNUSED from first argument. If first of NOTE_INSN_BASIC_BLOCK or NOTE_INSN_FUNCTION_BEG is only preceeded by NOTE_INSN_VAR_LOCATION or NOTE_INSN_DELETED notes, targetm.asm_out.function_prologue doesn't emit anything, HAVE_prologue and profiler should be emitted before prologue, set need_profile_function instead of emitting it. (final_scan_insn): If need_profile_function, emit profile_function on the first NOTE_INSN_BASIC_BLOCK or NOTE_INSN_FUNCTION_BEG note. Jakub --- gcc/final.c.jj 2013-01-15 17:20:37.000000000 +0100 +++ gcc/final.c 2013-01-25 10:31:48.848897310 +0100 @@ -200,6 +200,9 @@ rtx current_insn_predicate; /* True if printing into -fdump-final-insns= dump. */ bool final_insns_dump_p; +/* True if profile_function should be called, but hasn't been called yet. */ +static bool need_profile_function; + static int asm_insn_count (rtx); static void profile_function (FILE *); static void profile_after_prologue (FILE *); @@ -1668,13 +1671,15 @@ reemit_insn_block_notes (void) test and compare insns. */ void -final_start_function (rtx first ATTRIBUTE_UNUSED, FILE *file, +final_start_function (rtx first, FILE *file, int optimize_p ATTRIBUTE_UNUSED) { block_depth = 0; this_is_asm_operands = 0; + need_profile_function = false; + last_filename = LOCATION_FILE (prologue_location); last_linenum = LOCATION_LINE (prologue_location); last_discriminator = discriminator = 0; @@ -1695,7 +1700,41 @@ final_start_function (rtx first ATTRIBUT /* The Sun386i and perhaps other machines don't work right if the profiling code comes after the prologue. */ if (targetm.profile_before_prologue () && crtl->profile) - profile_function (file); + { + if (targetm.asm_out.function_prologue + == default_function_pro_epilogue +#ifdef HAVE_prologue + && HAVE_prologue +#endif + ) + { + rtx insn; + for (insn = first; insn; insn = NEXT_INSN (insn)) + if (!NOTE_P (insn)) + { + insn = NULL_RTX; + break; + } + else if (NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK + || NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG) + break; + else if (NOTE_KIND (insn) == NOTE_INSN_DELETED + || NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION) + continue; + else + { + insn = NULL_RTX; + break; + } + + if (insn) + need_profile_function = true; + else + profile_function (file); + } + else + profile_function (file); + } /* If debugging, assign block numbers to all of the blocks in this function. */ @@ -2075,6 +2114,12 @@ final_scan_insn (rtx insn, FILE *file, i break; case NOTE_INSN_BASIC_BLOCK: + if (need_profile_function) + { + profile_function (asm_out_file); + need_profile_function = false; + } + if (targetm.asm_out.unwind_emit) targetm.asm_out.unwind_emit (asm_out_file, insn); @@ -2130,6 +2175,12 @@ final_scan_insn (rtx insn, FILE *file, i break; case NOTE_INSN_FUNCTION_BEG: + if (need_profile_function) + { + profile_function (asm_out_file); + need_profile_function = false; + } + app_disable (); if (!DECL_IGNORED_P (current_function_decl)) debug_hooks->end_prologue (last_linenum, last_filename);