From patchwork Fri Feb 9 13:32:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 871392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-472945-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WuOIy1zO"; dkim-atps=neutral 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 3zdGGX45Vwz9ryk for ; Sat, 10 Feb 2018 00:33:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=tolDvxhc1PweZPJB Hned26vTyB9UGM6AjhYomC6KFdsiZ7pORo0OHyjMqYJzwGvPdx4nWSCSslgHFvMr Ug2gPDh7cQ83bARiE2bUWeG9ls2u9tPdhfq03l41T+7xqFE8r3G7clag7PY4nZsr 8J+A/4Jr9oPA1XNpMEkY585WKB0= 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:from :subject:to:cc:message-id:date:mime-version:content-type :content-transfer-encoding; s=default; bh=N7od/Gwm65grdCL2ew1+BJ 5b30U=; b=WuOIy1zObpN/UDD1REB3YZkSohEc90dl6AHX2M8CMDuKHBQE+IO7dG i5TSPuDcdN5sUaByLjcIj4sSVYn314QuzEHQpEZauXJ0JHhveyeW5LgXmcMTUETn Rsl5mJbc2ZuWElufyzpPnUvm2SBT3W29x2NtB9tksF9KGnZQBZClk= Received: (qmail 105736 invoked by alias); 9 Feb 2018 13:33:00 -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 105726 invoked by uid 89); 9 Feb 2018 13:33:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:224, Hx-spam-relays-external:2a02, H*RU:2a02, H*r:1472 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 ESMTP; Fri, 09 Feb 2018 13:32:58 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6C98981399; Fri, 9 Feb 2018 14:32:56 +0100 (CET) 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 ixhoGoAJfgax; Fri, 9 Feb 2018 14:32:56 +0100 (CET) Received: from [IPv6:2a02:2ab8:224:1:1adb:f2ff:fe3d:1472] (perdrix.act-europe.fr [IPv6:2a02:2ab8:224:1:1adb:f2ff:fe3d:1472]) (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 5872381387; Fri, 9 Feb 2018 14:32:56 +0100 (CET) From: Pierre-Marie de Rodat Subject: [PATCH][PR84213] DWARF: no location for non-definition DECLs with non-trivial DECL_VALUE_EXPR To: Richard Biener Cc: GCC Patches Message-ID: <7989392b-ed57-1a92-077e-e824ea18217f@adacore.com> Date: Fri, 9 Feb 2018 14:32:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-IsSubscribed: yes This patch restricts the set of cases in which we allow the generation of location attributes for variables that are not defined in the current unit. For such variables with complex DECL_VALUE_EXPR trees, generating a location attribute can end up creating relocations to text symbols in the debug section of LTO object files, which is not valid. Richard originally suggested to revert r248792 and then enhance tree_add_const_value_attribute_for_decl to generate a DW_AT_location attribute in the specific case of a DECL_VALUE_EXPR that is an INDIRECT_REF(NOP_EXPR(INTEGER_CST)). I ended up with this patch because changing a function called "tree_add_const_value_attribute*" to generate instead a location attribute whereas there already exists a function called "add_location_or_const_value_attribute" felt really wrong. ;-) Especially if this would either re-implement part of the latter function in the former one. What I did instead was to make dwarf2out_late_global_decl call add_location_or_const_value_attribute only when we know it's safe to do so (i.e. when it won't generate relocations to text symbols). I have the feeling that it is cleaner and from what I could see, it fixes the reported issue with no regression. Bootstrapped and regtested on x86_64-linux. Ok to commit to trunk? gcc/ PR lto/84213 * dwarf2out.c (is_trivial_indirect_ref): New function. (dwarf2out_late_global_decl): Do not generate a location attribute for variables that have a non-trivial DECL_VALUE_EXPR and that are not defined in the current unit. --- gcc/dwarf2out.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) { /* We get called via the symtab code invoking late_global_decl - for symbols that are optimized out. Do not add locations - for those, except if they have a DECL_VALUE_EXPR, in which case - they are relevant for debuggers. */ + for symbols that are optimized out. + + Do not add locations for those, except if they have a + DECL_VALUE_EXPR, in which case they are relevant for debuggers. + Still don't add a location if the DECL_VALUE_EXPR is not a trivial + INDIRECT_REF expression, as this could generate relocations to + text symbols in LTO object files, which is invalid. */ varpool_node *node = varpool_node::get (decl); - if ((! node || ! node->definition) && ! DECL_HAS_VALUE_EXPR_P (decl)) + if ((! node || ! node->definition) + && ! (DECL_HAS_VALUE_EXPR_P (decl) + && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl)))) tree_add_const_value_attribute_for_decl (die, decl); else add_location_or_const_value_attribute (die, decl, false); diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 948b3cb..6538596 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -25716,6 +25716,23 @@ dwarf2out_early_global_decl (tree decl) symtab->global_info_ready = save; } +/* Return whether EXPR is an expression with the following pattern: + INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */ + +static bool +is_trivial_indirect_ref (tree expr) +{ + if (expr == NULL_TREE || TREE_CODE (expr) != INDIRECT_REF) + return false; + + tree nop = TREE_OPERAND (expr, 0); + if (nop == NULL_TREE || TREE_CODE (nop) != NOP_EXPR) + return false; + + tree int_cst = TREE_OPERAND (nop, 0); + return int_cst != NULL_TREE && TREE_CODE (int_cst) == INTEGER_CST; +} + /* Output debug information for global decl DECL. Called from toplev.c after compilation proper has finished. */ @@ -25740,11 +25757,17 @@ dwarf2out_late_global_decl (tree decl) if (die)