From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3449 invoked by alias); 20 May 2011 14:02:38 -0000 Received: (qmail 3436 invoked by uid 22791); 20 May 2011 14:02:37 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BX,TW_DB,T_RP_MATCHES_RCVD 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; Fri, 20 May 2011 14:02:21 +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 (8.14.4/8.14.4) with ESMTP id p4KE2Kvr024541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 May 2011 10:02:20 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4KE2JXb001657 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 20 May 2011 10:02:20 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p4KE2ISw004219 for ; Fri, 20 May 2011 16:02:18 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p4KE2I0r004218 for gcc-patches@gcc.gnu.org; Fri, 20 May 2011 16:02:18 +0200 Date: Fri, 20 May 2011 14:51:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up dbxout to avoid referencing static unemitted symbols (PR debug/49032) Message-ID: <20110520140218.GR17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01464.txt.bz2 Hi! As discussed in the PR, similarly to dwarf2out.c's reference_to_unused and late removal of unreferenced symbols, this patch will make sure we don't reference static symbols that were optimized away. So far all dbxout was using was give up if DECL_RTL wasn't set, but DECL_RTL can be set e.g. for const hashing. Bootstrapped/regtested on x86_64-linux, i686-linux, additionally i686-linux with hacked up DBX_DEBUG as PREFERRED_DEBUGGING_TYPE. The new return NULL hasn't been hit during the last bootstrap/regtest but on the new testcase, so I think it doesn't really degrade -gstabs debug info quality (if we can speak about debug info quality in case of stabs at all). Ok for trunk/4.6? 2011-05-20 Jakub Jelinek PR debug/49032 * dbxout.c: Include cgraph.h. (dbxout_expand_expr): If a VAR_DECL is TREE_STATIC, not written and without value expr, return NULL if no varpool node exists for it or if it is not needed. * Makefile.in (dbxout.o): Depend on $(CGRAPH_H). * gcc.dg/debug/pr49032.c: New test. --- gcc/dbxout.c.jj 2011-04-06 16:33:29.000000000 +0200 +++ gcc/dbxout.c 2011-05-20 11:51:23.000000000 +0200 @@ -91,6 +91,7 @@ along with GCC; see the file COPYING3. #include "langhooks.h" #include "obstack.h" #include "expr.h" +#include "cgraph.h" #ifdef XCOFF_DEBUGGING_INFO #include "xcoffout.h" @@ -2470,6 +2471,20 @@ dbxout_expand_expr (tree expr) disable debug info for these variables. */ if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr)) return NULL; + if (TREE_STATIC (expr) + && !TREE_ASM_WRITTEN (expr) + && !DECL_HAS_VALUE_EXPR_P (expr) + && !TREE_PUBLIC (expr) + && DECL_RTL_SET_P (expr) + && MEM_P (DECL_RTL (expr))) + { + /* If this is a var that might not be actually output, + return NULL, otherwise stabs might reference an undefined + symbol. */ + struct varpool_node *node = varpool_get_node (expr); + if (!node || !node->needed) + return NULL; + } /* FALLTHRU */ case PARM_DECL: --- gcc/Makefile.in.jj 2011-05-11 19:39:04.000000000 +0200 +++ gcc/Makefile.in 2011-05-19 18:55:09.000000000 +0200 @@ -2956,7 +2956,8 @@ optabs.o : optabs.c $(CONFIG_H) $(SYSTEM dbxout.o : dbxout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ $(RTL_H) $(FLAGS_H) $(REGS_H) debug.h $(TM_P_H) $(TARGET_H) $(FUNCTION_H) \ langhooks.h insn-config.h reload.h $(GSTAB_H) xcoffout.h output.h dbxout.h \ - toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) $(OBSTACK_H) $(EXPR_H) gt-dbxout.h + toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) $(OBSTACK_H) $(EXPR_H) $(CGRAPH_H) \ + gt-dbxout.h debug.o : debug.c debug.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) sdbout.o : sdbout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) debug.h \ $(TREE_H) $(GGC_H) $(RTL_H) $(REGS_H) $(FLAGS_H) insn-config.h \ --- gcc/testsuite/gcc.dg/debug/pr49032.c.jj 2011-05-19 18:53:02.000000000 +0200 +++ gcc/testsuite/gcc.dg/debug/pr49032.c 2011-05-19 18:52:41.000000000 +0200 @@ -0,0 +1,11 @@ +/* PR debug/49032 */ +/* { dg-do link } */ + +static int s = 42; + +int +main () +{ + int *l[18] = { &s, &s, &s, &s, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + return 0; +} Jakub