public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* don't output strings just because of debug information
@ 2007-11-29 22:03 Alexandre Oliva
  2007-12-05 15:42 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2007-11-29 22:03 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gcc-debug-no-emit-unused-string.patch --]
[-- Type: text/x-patch, Size: 606 bytes --]

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;
 }

[-- Attachment #3: Type: text/plain, Size: 249 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: don't output strings just because of debug information
  2007-11-29 22:03 don't output strings just because of debug information Alexandre Oliva
@ 2007-12-05 15:42 ` Ian Lance Taylor
  2007-12-10  0:24   ` Mark Mitchell
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2007-12-05 15:42 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches

Alexandre Oliva <aoliva@redhat.com> writes:

> From  Alexandre Oliva  <aoliva@redhat.com>
> 
> 	* dwarf2out.c (reference_to_unused): Don't emit strings in
> 	initializers just because of debug information.

This is OK.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: don't output strings just because of debug information
  2007-12-05 15:42 ` Ian Lance Taylor
@ 2007-12-10  0:24   ` Mark Mitchell
  2007-12-15 20:22     ` Alexandre Oliva
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Mitchell @ 2007-12-10  0:24 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Alexandre Oliva, gcc-patches

Ian Lance Taylor wrote:
> Alexandre Oliva <aoliva@redhat.com> writes:
> 
>> From  Alexandre Oliva  <aoliva@redhat.com>
>>
>> 	* dwarf2out.c (reference_to_unused): Don't emit strings in
>> 	initializers just because of debug information.
> 
> This is OK.

I think it's OK too, but I have a couple of follow-on requests. :-)

1. tree.h doesn't document TREE_ASM_WRITTEN as applying to STRING_CST.
I didn't know that we set it on STRING_CST, so I was initially surprised
by Alexandre's patch.  Alexandre, would you mind updating that?

2. Is it possible to write a test case?  I would think that doing
something like:

  const char *p = "astringunlikelytoappearinafile";

with a dg-final to scan the asm file for the string would work.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: don't output strings just because of debug information
  2007-12-10  0:24   ` Mark Mitchell
@ 2007-12-15 20:22     ` Alexandre Oliva
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2007-12-15 20:22 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Ian Lance Taylor, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]

On Dec  9, 2007, Mark Mitchell <mark@codesourcery.com> wrote:

> Ian Lance Taylor wrote:
>> Alexandre Oliva <aoliva@redhat.com> writes:
>> 
>>> From  Alexandre Oliva  <aoliva@redhat.com>
>>> 
>>> * dwarf2out.c (reference_to_unused): Don't emit strings in
>>> initializers just because of debug information.
>> 
>> This is OK.

> I think it's OK too, but I have a couple of follow-on requests. :-)

> 1. tree.h doesn't document TREE_ASM_WRITTEN as applying to STRING_CST.
> I didn't know that we set it on STRING_CST, so I was initially surprised
> by Alexandre's patch.  Alexandre, would you mind updating that?

> 2. Is it possible to write a test case?

Thanks, here's what I've just checked in:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gcc-debug-no-emit-unused-string.patch --]
[-- Type: text/x-patch, Size: 2274 bytes --]

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.
	* tree.h (TREE_ASM_WRITTEN): Document use for STRING_CSTs.

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

	* gcc.dg/debug/const-3.c: New.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c.orig	2007-12-14 04:11:00.000000000 -0200
+++ gcc/dwarf2out.c	2007-12-14 04:13:03.000000000 -0200
@@ -10365,6 +10365,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;
 }
Index: gcc/tree.h
===================================================================
--- gcc/tree.h.orig	2007-12-14 04:11:00.000000000 -0200
+++ gcc/tree.h	2007-12-14 04:14:08.000000000 -0200
@@ -546,7 +546,7 @@ struct gimple_stmt GTY(())
 
        TREE_ASM_WRITTEN in
            VAR_DECL, FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE
-	   BLOCK, SSA_NAME
+	   BLOCK, SSA_NAME, STRING_CST
 
    used_flag:
 
@@ -1300,7 +1300,7 @@ extern void omp_clause_range_check_faile
 /* In integral and pointer types, means an unsigned type.  */
 #define TYPE_UNSIGNED(NODE) (TYPE_CHECK (NODE)->base.unsigned_flag)
 
-/* Nonzero in a VAR_DECL means assembler code has been written.
+/* Nonzero in a VAR_DECL or STRING_CST means assembler code has been written.
    Nonzero in a FUNCTION_DECL means that the function has been compiled.
    This is interesting in an inline function, since it might not need
    to be compiled separately.
Index: gcc/testsuite/gcc.dg/debug/const-3.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/debug/const-3.c	2007-12-14 04:23:45.000000000 -0200
@@ -0,0 +1,7 @@
+/* Make sure we don't emit strings just because of debug information
+   for string initializers.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g" } */
+/* { dg-final { scan-assembler-not "dontgenerate" } } */
+static const char *p = "dontgenerate1";
+static const char *q[2] = { 0, "dontgenerate2" };

[-- Attachment #3: Type: text/plain, Size: 249 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-15 20:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-29 22:03 don't output strings just because of debug information Alexandre Oliva
2007-12-05 15:42 ` Ian Lance Taylor
2007-12-10  0:24   ` Mark Mitchell
2007-12-15 20:22     ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).