public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/12818] New: -fwritable strings triggers bad code generation Date: Tue, 28 Oct 2003 22:21:00 -0000 [thread overview] Message-ID: <20031028221041.12818.fnf@ninemoons.com> (raw) 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
next reply other threads:[~2003-10-28 22:10 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-10-28 22:21 gcc-bugzilla at gcc dot gnu dot org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20031028221041.12818.fnf@ninemoons.com \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).