This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

don't output strings just because of debug information


A program as simple as:

static const char *x = "x";

compiled with -O2 will produce an empty rodata section, but with -O2
-g, the "x" string will be output, because it is referenced in the
debug information for variable "x".

In theory, we could output the string in a debug string section, but
since the variable is a pointer, rather than a string value, this
transformation wouldn't be correct.  The variable was optimized away,
and there's no pointer in the program that can represent the location
of the string, because the string was also optimized away.

This patch fixes this problem, such that now:

make bootstrap-debug &&
make prepare-bootstrap4-debug-lib-g0 && make bootstrap4-debug &&
rm -f compare3-debug && make compare3-debug

succeeds on x86_64-linux-gnu in the VTA branch, and also in mainline,
once the patches for bootstrap4-debug-related stuff are installed.

Ok to install?

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* dwarf2out.c (reference_to_unused): Don't emit strings in
	initializers just because of debug information.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c.orig	2007-11-29 04:13:12.000000000 -0200
+++ gcc/dwarf2out.c	2007-11-29 04:13:48.000000000 -0200
@@ -10364,6 +10364,8 @@ reference_to_unused (tree * tp, int * wa
       if (!node->output)
 	return *tp;
     }
+  else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
+    return *tp;
 
   return NULL_TREE;
 }
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]