This is the mail archive of the gcc-bugs@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]

gcc-4.2 bug, optimizer optimized strings away


Hi,

if you publish this email, please remove my email address from the posting.


Problem description:

	gcc versions >= 4.0 seem to optimize away strings.
	Older versions seem to work.
	For a more detailed description see below.


exact gcc versions containing the bug:
-----------------------------------------------------------------------------------
$ gcc-4.0 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060904 (prerelease) (Debian 4.0.3-7)


$ gcc-4.1 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.3 20071019 (prerelease) (Debian 4.1.2-17)

$ gcc-4.2 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 20071123 (prerelease) (Debian 4.2.2-4)
-----------------------------------------------------------------------------------


the system type:
	Linux phyrex 2.6.22-3-k7 #1 SMP Mon Nov 12 09:12:50 UTC 2007 i686 GNU/Linux


the options given when GCC was configured/built:
	see above

the complete command line that triggers the bug:
	see Makefile

the compiler output (error messages, warnings, etc.):
	no compiler output with -Wall and -pedantic, no errors, no warnings


additional problem description:
	http://pastebin.com/m1aab58d7




detailed problem description:

	The attached code uses inline assembler to directly use x86-32 linux-2.6 system calls.
	Without optimization, the generated assembly code is correct and the generated binary works.
	With optimization (thus with the -O1 flag), the generated optimized assembler code does not
	contain the string at all.
	Obviously, the generated binary code does not work as expected.

	The attachment also includes the generated assembly code.
	As you can see in print_hi_there_no_opt.s, the code contains the string "hi there!\n" in the .rodata section.
	The label .LC0 points to the arrording position. It is used in the .text segment code lateron.

-----------------------------------------------------------------------------------
    .file   "print_hi_there.c"
    .section    .rodata
.LC0:
    .string "hi there !\n"


...
    movl    .LC0, %eax
    movl    %eax, -16(%ebp)
    movl    .LC0+4, %eax
    movl    %eax, -12(%ebp)
    movl    .LC0+8, %eax
    movl    %eax, -8(%ebp)
-----------------------------------------------------------------------------------

	

	The optimized assembly file (print_hi_there_opt.s) does not contain the string at all and neither
	has a .rodata section.
	

sincerly,
markus kammerstetter

Attachment: bad_gcc_optimizer.tar.bz2
Description: application/bzip


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