Recently i found that my C++ program was running fine with no
optimization and giving segmentation fault with error code 139 when
compiled with optimization level 2. I searched somewhat but never find
any systematic solution. In my recent attempt, i found the problem with
the optimization tool itself, which iam discussing here.
I found that the problem of segmentation fault was boiled down to a
statement of the form A = B, with no pointer or array usage, so forget
about the illegal memory write problems. When i removed this statement,
the problem disappers, so concluded that the segmentation fault problem
is with this statement. A careful study revealed that this statement
was redundant because A was never used in the program after this
statement. So i inserted one more statement after the above statement
which is "X = A", where X is a dummy variable and in that case the
problem again disappears. Inserting this new statement has made my
initial statement no more redundant.
I think the optimization tool had detected that A = B is a redundant
statement but failed to do its work. So its a clear bug in the
optimization tool itself.
The gcc -v output of my system is following:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++ ,java,f95,objc, ada,treelang --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-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --enable-checking=releas e i486-linux-gnu
Thread model: posix
gcc version 4.0.2 (Debian 4.0.2-2)
optimization and giving segmentation fault with error code 139 when
compiled with optimization level 2. I searched somewhat but never find
any systematic solution. In my recent attempt, i found the problem with
the optimization tool itself, which iam discussing here.
I found that the problem of segmentation fault was boiled down to a
statement of the form A = B, with no pointer or array usage, so forget
about the illegal memory write problems. When i removed this statement,
the problem disappers, so concluded that the segmentation fault problem
is with this statement. A careful study revealed that this statement
was redundant because A was never used in the program after this
statement. So i inserted one more statement after the above statement
which is "X = A", where X is a dummy variable and in that case the
problem again disappears. Inserting this new statement has made my
initial statement no more redundant.
I think the optimization tool had detected that A = B is a redundant
statement but failed to do its work. So its a clear bug in the
optimization tool itself.
The gcc -v output of my system is following:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++ ,java,f95,objc, ada,treelang --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-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --enable-checking=releas e i486-linux-gnu
Thread model: posix
gcc version 4.0.2 (Debian 4.0.2-2)
Comment