A global .rodata constant is created in the following case and then memcpy() to the variable in the stack, instead of just calling the intended memset. etienne@cygne:~/projet/gujin$ cat > tmp.c int sub (int i) { int array[1000000] = { 0 }; sub2 (&array[i]); } etienne@cygne:~/projet/gujin$ ~/projet/toolchain/bin/gcc -S -Os tmp.c -o tmp.s etienne@cygne:~/projet/gujin$ cat tmp.s .file "tmp.c" .section .rodata .align 32 .type C.0.1134, @object .size C.0.1134, 4000000 C.0.1134: .zero 4000000 .text .globl sub .type sub, @function sub: pushl %ebp movl %esp, %ebp pushl %ebx subl $4000000, %esp pushl $4000000 pushl $C.0.1134 leal -4000004(%ebp), %ebx pushl %ebx call memcpy movl 8(%ebp), %eax leal (%ebx,%eax,4), %eax pushl %eax call sub2 addl $16, %esp movl -4(%ebp), %ebx leave ret .size sub, .-sub .ident "GCC: (GNU) 4.0.2 20050811 (prerelease)" .section .note.GNU-stack,"",@progbits etienne@cygne:~/projet/gujin$ ~/projet/toolchain/bin/gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../configure --prefix=/home/etienne/projet/toolchain --enable- l anguages=c Thread model: posix gcc version 4.0.2 20050811 (prerelease) See also the thread at: http://gcc.gnu.org/ml/gcc/2005-08/msg00660.html Thanks to Jim Wilson (GNU Tools Support, http://www.specifix.com) for the reduced test case and the analysis of the bug in gcc@gcc.gnu.org list. Etienne.
The issue is the same as PR 23477. *** This bug has been marked as a duplicate of 23477 ***
Same bug still present in gcc version 4.0.3 20051201 (prerelease) (Debian 4.0.2-5). http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23477 is itself corrected, but this current bug has never been corrected.
PR 23477 was fixed in 4.1.0 and not 4.0.3. This is still a dup of that bug. *** This bug has been marked as a duplicate of 23477 ***
(In reply to comment #3) > PR 23477 was fixed in 4.1.0 and not 4.0.3. This is still a dup of that bug. > *** This bug has been marked as a duplicate of 23477 *** For me, 23477 is fixed in "GCC: (GNU) 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)" (this bug is in C++ so compile with g++); but the current bug 23631 is still present (use pure C). Etienne.
Fixed in 4.1.0.