http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54569
Bug #: 54569 Summary: Compiling code with -O3 results to segfault in MAME/MESS binary Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: agar...@igalia.com Created attachment 28190 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28190 Preprocessed source file Debian bug: http://bugs.debian.org/686645 MAME / MESS segfault when compiled with -O3 using GCC 4.7.1. The problem doesn't seem to happen with GCC < 4.7 GCC version: Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.1-8' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu gcc version 4.7.1 (Debian 4.7.1-8) Command line that triggers the bug: gcc -DCRLF=2 -DINLINE="static inline" -DLSB_FIRST -DNDEBUG -DUSE_SYSTEM_JPEGLIB -DSDLMAME_SDL2=0 -DDISTRO=generic -DSDLMAME_ARCH=-march=pentium2 -DSYNC_IMPLEMENTATION=tc -DSDLMAME_UNIX -DUSE_OPENGL=1 -DUSE_DISPATCH_GL=1 -DSDLMAME_X11 -DNATIVE_DRC=drcbe_x86 -pipe -O3 -fno-strict-aliasing -march=pentium2 -Wall -Wcast-align -Wundef -Wformat-security -Wwrite-strings -Wno-sign-compare -Wno-conversion -DINI_PATH="/etc/mess" -D_GNU_SOURCE=1 -D_REENTRANT -m32 -pthread -pthread -Isrc/mess -Iobj/sdl/mess/layout -Isrc/emu -Iobj/sdl/emu -Iobj/sdl/emu/layout -Isrc/lib/util -Isrc/lib -Isrc/osd -Isrc/osd/sdl -Isrc/debug -include src/osd/sdl/sdlprefix.h -I/usr/include -I/usr/include/gtk-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gconf/2 -I/usr/include/dbus-1.0 -I/usr/lib/i386-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/X11/include -I/usr/X11R6/include -I/usr/openwin/include -Isrc/mame -Iobj/sdl/mame/layout -Isrc/mess/osd -Isrc/mess/osd/sdl -Isrc/mess/tools -Isrc/mess/tools/imgtool -Isrc/mess/tools/castool -Isrc/mess/tools/floptool -x c++ -std=gnu++98 -Woverloaded-virtual -c src/emu/ioport.c -o obj/sdl/emu/ioport.o (no compiler output). The problem disappears if the file is compiled without -O3 or with -O3 -fno-ipa-cp-clone. It also disappears if you remove the '__attribute__((optimize("O0")))' line from the source file. You can see a few more details -including a backtrace- in the Debian bug report (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=686645#60).