From patchwork Wed Jun 10 13:09:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 482642 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 16B9814029D for ; Wed, 10 Jun 2015 23:10:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=y4cwM2FL; 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:references :in-reply-to:content-type; q=dns; s=default; b=sQlPqmDi/l8DRW10R wpsDzCQEJgASd1cHKzaBi2CApeMKP11+QePNVPbQgrzMckIdvY50zlnfYmAZlMSR I83BSNcL+IZCug1d2c6Pkc+bX1S0mmfRa8480JoU1saBZzO28XwEQ1qOkSSRBk6O SLWKukRJy5C6sLib9vJOqbI4oQ= 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:references :in-reply-to:content-type; s=default; bh=usnwCUFQ3rEsDWNkvBxnrfn HRv8=; b=y4cwM2FLFemgeSaAI4tHwGdgQXjjx0PENF5O2rKYdUDxO9M4gQAhX+j aj/JzYNpJ0aMWL6mwxhl+w6p2tHpb7XTBZ3xLMF1IHGF/NKU5Ma+9cS5XS2eqwlW Po50bj0IHLhWfrRTeMLrn8tTYCF/BvkClZ/garEysaLioNaBrl7w= Received: (qmail 67570 invoked by alias); 10 Jun 2015 13:09:53 -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 67560 invoked by uid 89); 10 Jun 2015 13:09:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 10 Jun 2015 13:09:50 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 0FFEB2853820; Wed, 10 Jun 2015 15:09:48 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CILaPXzHzio0; Wed, 10 Jun 2015 15:09:48 +0200 (CEST) Received: from [10.10.1.112] (cacatoes.act-europe.fr [10.10.1.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 00325285381E; Wed, 10 Jun 2015 15:09:48 +0200 (CEST) Message-ID: <55783717.8060505@adacore.com> Date: Wed, 10 Jun 2015 15:09:43 +0200 From: Pierre-Marie de Rodat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Richard Biener CC: GCC Patches Subject: Re: [PATCH][PR debug/65549] Restore DW_AT_abstract_origin for cross-unit call sites References: <55775CDE.2060101@adacore.com> In-Reply-To: X-IsSubscribed: yes Thank you for your answer, Richard! On 06/10/2015 08:58 AM, Richard Biener wrote: > Hmm, so the underlying issue is that we don't associate comp_unit_die () > with any TRANSLATION_UNIT_DECL. Indeed. > For the LTO early debug work I did the following at the very > beginning of dwarf2out_early_finish: > > /* Pick the first TRANSLATION_UNIT_DECL we didn't create a DIE for > and equate it with our default CU DIE. LTO output needs to be > able to lookup DIEs for translation unit decls. */ > unsigned i; > tree decl; > FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, decl) > if (!lookup_decl_die (decl)) > equate_decl_number_to_die (decl, comp_unit_die ()); If I understand correctly, this does not only "pick the first" (as the comment says) but do equate for all DIE-less units, right? Why isn't this hunk in mainline yet by the way? > We create some DIEs for builtin types too early before frontends > got a chance to build their TRANSLATION_UNIT_DECL, so comp_unit_die > gets created before there is any TRANSLATION_UNIT_DECL. Another > approach would of course be that the Frontends register their main > TRANSLATION_UNIT_DECL with dwarf2out via a debug hook. > > But - does the above work for you and fix the regression? If so > adding a debug hook would probably be the cleaner solution still. Yes it does, thanks! However we need to fix this on the 4.9 branch as well and this patch would need reworking to be applied there (no debug early). So here's a patch that introduce a register_main_translation_unit debug hook: is this what you had in mind? This works for me on the 4.9 branch and on mainline as well, regtested on x86_64-linux. From 285ea98dfdf3d45f32fc0141aa182f07d172612d Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Wed, 10 Jun 2015 10:59:40 +0200 Subject: [PATCH] Restore DW_AT_abstract_origin for cross-unit call sites gcc/ChangeLog: * debug.h (struct gcc_debug_hooks): Add a register_main_translation_unit hook. * debug.c (do_nothing_debug_hooks): Provide a function for this new hook. * dbxout.c (dbx_debug_hooks): Likewise. * sdbout.c (sdb_debug_hooks): Likewise. * vmsdbgout.c (vmsdbg_debug_hooks): Likewise. * dwarf2out.c (main_translation_unit): New global variable. (dwarf2out_register_main_translation_unit): New function implementing the new hook. (dwarf2_debug_hooks): Assign dwarf2out_register_main_translation_unit to this new hook. (dwarf2out_init): Associate any main translation unit to comp_unit_die (). * c/c-decl.c (pop_scope): Register the main translation unit through the new debug hook. * cp/decl.c (cxx_init_decl_processing): Likewise. gcc/ada/ChangeLog: * gcc-interface/utils.c (get_global_context): Register the main translation unit through the new debug hook. gcc/fortran/ChangeLog: * f95-lang.c (gfc_create_decls): Register the main translation unit through the new debug hook. --- gcc/ada/gcc-interface/utils.c | 5 ++++- gcc/c/c-decl.c | 1 + gcc/cp/decl.c | 2 ++ gcc/dbxout.c | 1 + gcc/debug.c | 1 + gcc/debug.h | 4 ++++ gcc/dwarf2out.c | 27 +++++++++++++++++++++++++++ gcc/fortran/f95-lang.c | 1 + gcc/sdbout.c | 1 + gcc/vmsdbgout.c | 1 + 10 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 9076529..655bfa1 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -667,7 +667,10 @@ static tree get_global_context (void) { if (!global_context) - global_context = build_translation_unit_decl (NULL_TREE); + { + global_context = build_translation_unit_decl (NULL_TREE); + debug_hooks->register_main_translation_unit (global_context); + } return global_context; } diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 7fd662d..3fde22f 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1196,6 +1196,7 @@ pop_scope (void) { tree file_decl = build_translation_unit_decl (NULL_TREE); context = file_decl; + debug_hooks->register_main_translation_unit (file_decl); } else context = block; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3bed538..ffd068a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3831,6 +3831,8 @@ cxx_init_decl_processing (void) global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name, void_type_node); DECL_CONTEXT (global_namespace) = build_translation_unit_decl (NULL_TREE); + debug_hooks->register_main_translation_unit + (DECL_CONTEXT (global_namespace)); TREE_PUBLIC (global_namespace) = 1; begin_scope (sk_namespace, global_namespace); diff --git a/gcc/dbxout.c b/gcc/dbxout.c index 48b5065..94fac42 100644 --- a/gcc/dbxout.c +++ b/gcc/dbxout.c @@ -380,6 +380,7 @@ const struct gcc_debug_hooks dbx_debug_hooks = debug_nothing_tree, /* begin_function */ #endif debug_nothing_int, /* end_function */ + debug_nothing_tree, /* register_main_translation_unit */ dbxout_function_decl, dbxout_early_global_decl, /* early_global_decl */ dbxout_late_global_decl, /* late_global_decl */ diff --git a/gcc/debug.c b/gcc/debug.c index 9c621f8..ab92cc8 100644 --- a/gcc/debug.c +++ b/gcc/debug.c @@ -46,6 +46,7 @@ const struct gcc_debug_hooks do_nothing_debug_hooks = debug_nothing_int_charstar, /* end_epilogue */ debug_nothing_tree, /* begin_function */ debug_nothing_int, /* end_function */ + debug_nothing_tree, /* register_main_translation_unit */ debug_nothing_tree, /* function_decl */ debug_nothing_tree, /* early_global_decl */ debug_nothing_tree, /* late_global_decl */ diff --git a/gcc/debug.h b/gcc/debug.h index e7e1334..269c4d8 100644 --- a/gcc/debug.h +++ b/gcc/debug.h @@ -89,6 +89,10 @@ struct gcc_debug_hooks /* Record end of function. LINE is highest line number in function. */ void (* end_function) (unsigned int line); + /* Register UNIT as the main translation unit. Called from front-ends when + they create their main translation unit. */ + void (* register_main_translation_unit) (tree); + /* Debug information for a function DECL. This might include the function name (a symbol), its parameters, and the block that makes up the function's body, and the local variables of the diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index ee2bcb1..8a36fe8 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -2446,6 +2446,7 @@ static void dwarf2out_abstract_function (tree); static void dwarf2out_var_location (rtx_insn *); static void dwarf2out_begin_function (tree); static void dwarf2out_end_function (unsigned int); +static void dwarf2out_register_main_translation_unit (tree unit); static void dwarf2out_set_name (tree, tree); /* The debug hooks structure. */ @@ -2475,6 +2476,7 @@ const struct gcc_debug_hooks dwarf2_debug_hooks = dwarf2out_end_epilogue, dwarf2out_begin_function, dwarf2out_end_function, /* end_function */ + dwarf2out_register_main_translation_unit, dwarf2out_function_decl, /* function_decl */ dwarf2out_early_global_decl, dwarf2out_late_global_decl, @@ -22505,6 +22507,26 @@ dwarf2out_end_function (unsigned int) maybe_at_text_label_p = false; } +/* Temporary holder for dwarf2out_register_main_translation_unit. Used to let + front-ends register a translation unit even before dwarf2out_init is + called. */ +static tree main_translation_unit = NULL_TREE; + +/* Hook called by front-ends after they built their main translation unit. + Associate comp_unit_die to UNIT. */ + +static void +dwarf2out_register_main_translation_unit (tree unit) +{ + gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL + && main_translation_unit == NULL_TREE); + main_translation_unit = unit; + /* If dwarf2out_init has not been called yet, it will perform the association + itself looking at main_translation_unit. */ + if (decl_die_table != NULL) + equate_decl_number_to_die (unit, comp_unit_die ()); +} + /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */ static void @@ -23242,6 +23264,11 @@ dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) /* Make sure the line number table for .text always exists. */ text_section_line_info = new_line_info_table (); text_section_line_info->end_label = text_end_label; + + /* If front-ends already registered a main translation unit but we were not + ready to perform the association, do this now. */ + if (main_translation_unit != NULL_TREE) + equate_decl_number_to_die (main_translation_unit, comp_unit_die ()); } /* Called before compile () starts outputtting functions, variables diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 6daac83..2c055f5 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -204,6 +204,7 @@ gfc_create_decls (void) /* Build our translation-unit decl. */ current_translation_unit = build_translation_unit_decl (NULL_TREE); + debug_hooks->register_main_translation_unit (current_translation_unit); } diff --git a/gcc/sdbout.c b/gcc/sdbout.c index f5671c6..033886a 100644 --- a/gcc/sdbout.c +++ b/gcc/sdbout.c @@ -296,6 +296,7 @@ const struct gcc_debug_hooks sdb_debug_hooks = sdbout_end_epilogue, /* end_epilogue */ sdbout_begin_function, /* begin_function */ sdbout_end_function, /* end_function */ + debug_nothing_tree, /* register_main_translation_unit */ debug_nothing_tree, /* function_decl */ sdbout_early_global_decl, /* early_global_decl */ sdbout_late_global_decl, /* late_global_decl */ diff --git a/gcc/vmsdbgout.c b/gcc/vmsdbgout.c index 8297e02..8c917e0 100644 --- a/gcc/vmsdbgout.c +++ b/gcc/vmsdbgout.c @@ -194,6 +194,7 @@ const struct gcc_debug_hooks vmsdbg_debug_hooks vmsdbgout_end_epilogue, vmsdbgout_begin_function, vmsdbgout_end_function, + debug_nothing_tree, /* register_main_translation_unit */ vmsdbgout_function_decl, vmsdbgout_early_global_decl, vmsdbgout_late_global_decl, -- 2.3.3.199.g52cae64