From patchwork Thu Apr 30 00:56:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 466336 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A4DA31402B0 for ; Thu, 30 Apr 2015 10:56:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rghc8m+f; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=R30Fta6Nz5ztUiPCegCZJEnYXRUfMgH32oXmvS/xK6C Bc3yTB+yqrkjOs4k55Js2p2aHKINFMAVV2LSgUP51Utq7YnX2tUtdpvMehsHqxj3 JfoHZV8BXWoanTP3H4RktXnR9Kr6C/uZ7GBFe6njaJjGSojMNLylagIhVIsUhw/M = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=m2HkEzsCI+ugEB/YPHQO0rDGiic=; b=rghc8m+f3TyjGRXbV w5oukNzoLaex35BkTrV/SXan5IoG34sjkZYf9DaDgqMmXan+RA6dDhuZz93mss/Y Rl1rAe3LV4dddoaimISwcUhYkjiMTpOd4aD6CYJUgHYK6AAN0dFZVY814Ci1so9s 7/VbZEjICqupVaJG5/vFj9yAZQ= Received: (qmail 106153 invoked by alias); 30 Apr 2015 00:56:51 -0000 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 Received: (qmail 106136 invoked by uid 89); 30 Apr 2015 00:56:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 30 Apr 2015 00:56:48 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 1CFED8EA21; Thu, 30 Apr 2015 00:56:47 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-48-175.rdu2.redhat.com [10.10.48.175]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3U0ujW1030723; Wed, 29 Apr 2015 20:56:46 -0400 Message-ID: <55417DCC.2090708@redhat.com> Date: Wed, 29 Apr 2015 17:56:44 -0700 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Ian Lance Taylor , jason merrill CC: gcc-patches Subject: [debug-early] fix -fdump-go-spec Hi guys! Despite what Go thinks: /* The debug hooks are used to implement -fdump-go-spec because it gives a simple and stable API for all the information we need to dump. */ ...the debug hooks are not stable... :). The godump-1.c test is failing in the debug-early branch. It seems that Go is hijacking the debug_hook machinery to access globals generated by the front-ends. In debug-early, things have moved around. With this patch I have done my best to give Go what it wants without recreating what the front-ends were doing. I've made the go_decl() call work from within the early_global_decl() hook which gets called as we parse (rest_of_decl_compilation). I far as I understand, this hack is a one-time thing for use internally in the build process, so we don't care whether go_decl() will receive location information?? I have also relaxed the condition in rest_of_decl_compilation to allow function prototypes. Go was expecting to be fed function prototypes as part of the global_decl machinery. However, it won't ever see these, as the early_global_decl code iterating through functions uses the symbol table, which does not have prototypes: /* Emit early debug for reachable functions, and by consequence, locally scoped symbols. */ struct cgraph_node *cnode; FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode) if (!decl_function_context (cnode->decl)) (*debug_hooks->early_global_decl) (cnode->decl); (By the way, even iterating through symbols, without regards to gimple body, we end up with nothing...and even before we analyze_functions() and prune unreachable nodes.). Relaxing the condition does the trick, and the dwarf early_global_decl debug hook just works because it avoids functions with no body anyhow. In a world with Go and non dwarf (stabs, etc) debug hooks, I may have to adjust the calls to debug_hooks->{early,late}_global_decl a bit more to get all debugging backends to get what they want. This may involve feeding more to the debug hooks while making the individual hooks disregard DECLs they don't want/need. Is there not a more modern way of Go getting the DECLs it needs without abusing the debug_hook machinery? Anyways... this is what I have so far. It may change, as I have at least one stabs problem that may regarding tweaking things again. Committed to branch. Aldy commit 040d95e2436d7fa1ef75761dfe50b7481726373d Author: Aldy Hernandez Date: Wed Apr 29 17:37:21 2015 -0700 Fix -fdump-go-spec. diff --git a/gcc/godump.c b/gcc/godump.c index 94d0c8b..5de34db 100644 --- a/gcc/godump.c +++ b/gcc/godump.c @@ -517,6 +517,7 @@ go_function_decl (tree decl) static void go_early_global_decl (tree decl) { + go_decl (decl); real_debug_hooks->early_global_decl (decl); } @@ -526,7 +527,6 @@ static void go_late_global_decl (tree decl) { real_debug_hooks->late_global_decl (decl); - go_decl (decl); } /* A type declaration. */ diff --git a/gcc/passes.c b/gcc/passes.c index 3bb0e5d..4dee8ad 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -297,10 +297,20 @@ rest_of_decl_compilation (tree decl, /* Generate early debug for global variables. Any local variables will be handled by either handling reachable functions from finalize_compilation_unit (and by consequence, locally scoped - symbols), or by rest_of_type_compilation below. */ + symbols), or by rest_of_type_compilation below. + + Also, pick up function prototypes, which will be mostly ignored + by the different early_global_decl() hooks, but will at least be + used by Go's hijack of the debug_hooks to implement + -fdump-go-spec. */ if (!flag_wpa && !in_lto_p - && TREE_CODE (decl) != FUNCTION_DECL + && (TREE_CODE (decl) != FUNCTION_DECL + /* This will pick up function prototypes with no bodies, + which are not visible in finalize_compilation_unit() + while iterating with FOR_EACH_*_FUNCTION through the + symbol table. */ + || !DECL_SAVED_TREE (decl)) && !decl_function_context (decl) && !current_function_decl && !decl_type_context (decl))