public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/12818] New: -fwritable strings triggers bad code generation
@ 2003-10-28 22:21 gcc-bugzilla at gcc dot gnu dot org
  2003-10-28 22:28 ` [Bug c/12818] [3.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2003-10-28 22:21 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818

           Summary: -fwritable strings triggers bad code generation
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fnf at ninemoons dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


When using -fwritable-strings, the compiler emits two copies of the
strings.  In the supplied example, one of the copies is emitted into a
data area that is supposed to contain pointers to the strings.

In checking some older versions of gcc, it would appear that this
bug first appeared in late May 2003 or early June 2003.

Environment:
System: Linux fred.ninemoons.com 2.4.20-20.9 #1 Mon Aug 18 11:27:43 EDT 2003 i686 athlon i386 GNU/Linux
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /src/sourceware/gcc/gcc/configure -v --prefix=/usr/local/sourceware --enable-languages=c,c++

How-To-Repeat:

Here is the source code:

	char *names[] = {"alice", "bob", "john"};

	main ()
	{
	  printf ("names[0] = %s\n", names[0]);
	}

This works without -fwritable-strings:

	$ gcc -o j j.c
	$ ./j
	names[0] = alice
	$

It coredumps with -fwritable-strings:

	$ gcc -fwritable-strings -o j j.c
	$ ./j
	Segmentation fault (core dumped)
	$

Here is the generated code:

		 .file   "j.c"
		 .data
	 .LC0:
		 .string "alice"
	 .LC1:
		 .string "bob"
	 .LC2:
		 .string "john"
	 .globl names
		 .align 4
		 .type   names, @object
		 .size   names, 12
	 names:
	 .LC3:
		 .string "alice"
		 .long   .LC3
	 .LC4:
		 .string "bob"
		 .long   .LC4
	 .LC5:
		 .string "john"
		 .long   .LC5
	 .LC6:
		 .string "names[0] = %s\n"
		 .text
	 .globl main
		 .type   main, @function
	 main:
		 pushl   %ebp
		 movl    %esp, %ebp
		 subl    $8, %esp
		 andl    $-16, %esp
		 movl    $0, %eax
		 addl    $15, %eax
		 addl    $15, %eax
		 shrl    $4, %eax
		 sall    $4, %eax
		 subl    %eax, %esp
		 movl    names, %eax
		 movl    %eax, 4(%esp)
		 movl    $.LC6, (%esp)
		 call    printf
		 leave
		 ret
		 .size   main, .-main
		 .section        .note.GNU-stack,"",@progbits
		 .ident  "GCC: (GNU) 3.4 20031028 (experimental)"

 >Fix:
	Workaround is to not use -fwritable-strings


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

* [Bug c/12818] [3.4 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
@ 2003-10-28 22:28 ` pinskia at gcc dot gnu dot org
  2003-10-28 22:43 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-28 22:28 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|-fwritable strings triggers |[3.4 Regression] -fwritable
                   |bad code generation         |strings triggers bad code
                   |                            |generation
   Target Milestone|---                         |3.4


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-28 22:27 -------
I can confirm this on the mainline (20031028), I want to say it is related to deferring of writing 
globals.


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

* [Bug c/12818] [3.4 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
  2003-10-28 22:28 ` [Bug c/12818] [3.4 Regression] " pinskia at gcc dot gnu dot org
@ 2003-10-28 22:43 ` pinskia at gcc dot gnu dot org
  2003-12-29 17:54 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-28 22:43 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2003-10-28 22:28:08
               date|                            |


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

* [Bug c/12818] [3.4 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
  2003-10-28 22:28 ` [Bug c/12818] [3.4 Regression] " pinskia at gcc dot gnu dot org
  2003-10-28 22:43 ` pinskia at gcc dot gnu dot org
@ 2003-12-29 17:54 ` pinskia at gcc dot gnu dot org
  2004-01-06  5:15 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-29 17:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-29 17:51 -------
We might remove or oboslete -fwritable-strings for 3.4.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2003-12-29 17:54 ` pinskia at gcc dot gnu dot org
@ 2004-01-06  5:15 ` pinskia at gcc dot gnu dot org
  2004-01-11  0:05 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-06  5:15 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-01-06  5:15 ` pinskia at gcc dot gnu dot org
@ 2004-01-11  0:05 ` pinskia at gcc dot gnu dot org
  2004-01-29 13:14 ` [Bug c/12818] [3.4/3.5 " ebotcazou at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-11  0:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-11 00:05 -------
Can we remove this option, please or do something with this bug.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4/3.5 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2004-01-11  0:05 ` pinskia at gcc dot gnu dot org
@ 2004-01-29 13:14 ` ebotcazou at gcc dot gnu dot org
  2004-01-29 18:40 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2004-01-29 13:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2004-01-29 13:14 -------
Investigating.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |ebotcazou at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4/3.5 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2004-01-29 13:14 ` [Bug c/12818] [3.4/3.5 " ebotcazou at gcc dot gnu dot org
@ 2004-01-29 18:40 ` pinskia at gcc dot gnu dot org
  2004-01-30 14:17 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-29 18:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-29 18:40 -------
Path here: <http://gcc.gnu.org/ml/gcc-patches/2004-01/msg03268.html>.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4/3.5 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2004-01-29 18:40 ` pinskia at gcc dot gnu dot org
@ 2004-01-30 14:17 ` cvs-commit at gcc dot gnu dot org
  2004-01-30 14:23 ` cvs-commit at gcc dot gnu dot org
  2004-01-30 14:25 ` ebotcazou at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-01-30 14:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-01-30 14:16 -------
Subject: Bug 12818

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2004-01-30 14:16:44

Modified files:
	gcc            : ChangeLog varasm.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: fwritable-strings-1.c 

Log message:
	PR c/12818
	* varasm.c (const_hash_1) <STRING_CST>: Use the
	address to compute the hash value if flag_writable_strings.
	(compare_constant) <STRING_CST>: Compare the addresses
	if flag_writable_strings.
	(build_constant_desc): Do not copy the expression for a
	STRING_CST if flag_writable_strings.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2561&r2=2.2562
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.405&r2=1.406
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3442&r2=1.3443
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/fwritable-strings-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4/3.5 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2004-01-30 14:17 ` cvs-commit at gcc dot gnu dot org
@ 2004-01-30 14:23 ` cvs-commit at gcc dot gnu dot org
  2004-01-30 14:25 ` ebotcazou at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-01-30 14:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-01-30 14:23 -------
Subject: Bug 12818

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	ebotcazou@gcc.gnu.org	2004-01-30 14:23:24

Modified files:
	gcc            : ChangeLog varasm.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: fwritable-strings-1.c 

Log message:
	PR c/12818
	* varasm.c (const_hash_1) <STRING_CST>: Use the
	address to compute the hash value if flag_writable_strings.
	(compare_constant) <STRING_CST>: Compare the addresses
	if flag_writable_strings.
	(build_constant_desc): Do not copy the expression for a
	STRING_CST if flag_writable_strings.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.111&r2=2.2326.2.112
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.405&r2=1.405.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.32&r2=1.3389.2.33
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/fwritable-strings-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

* [Bug c/12818] [3.4/3.5 Regression] -fwritable strings triggers bad code generation
  2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2004-01-30 14:23 ` cvs-commit at gcc dot gnu dot org
@ 2004-01-30 14:25 ` ebotcazou at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2004-01-30 14:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2004-01-30 14:25 -------
See the aforementioned patch.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12818


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

end of thread, other threads:[~2004-01-30 14:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-28 22:21 [Bug c/12818] New: -fwritable strings triggers bad code generation gcc-bugzilla at gcc dot gnu dot org
2003-10-28 22:28 ` [Bug c/12818] [3.4 Regression] " pinskia at gcc dot gnu dot org
2003-10-28 22:43 ` pinskia at gcc dot gnu dot org
2003-12-29 17:54 ` pinskia at gcc dot gnu dot org
2004-01-06  5:15 ` pinskia at gcc dot gnu dot org
2004-01-11  0:05 ` pinskia at gcc dot gnu dot org
2004-01-29 13:14 ` [Bug c/12818] [3.4/3.5 " ebotcazou at gcc dot gnu dot org
2004-01-29 18:40 ` pinskia at gcc dot gnu dot org
2004-01-30 14:17 ` cvs-commit at gcc dot gnu dot org
2004-01-30 14:23 ` cvs-commit at gcc dot gnu dot org
2004-01-30 14:25 ` ebotcazou at gcc dot gnu dot org

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).