Loop unrolling -> stack corruption

Lubos Lunak l.lunak at sh.cvut.cz
Wed May 8 18:35:48 BST 2002


On st 8. květen 2002 18:50, Michael Goffioul wrote:
> Michael Goffioul wrote:
> > Something weird seems to happen with kdeprint code. When compiled with
> > the flag -funroll-loops, crashes happen and it's impossible to debug it
> > with gdb as the stack is corrupted ("Cannot access memory..."). Without
> > that compilation flag, everything is OK.
> > This is tested with gcc-2.95.3.
> >
> > Except valgrinding the code, does anybody have any hint?
>
> More info about this. Here's a complete backtrace when compiling only
> kdelibs/kdeprint/ with -funroll-loops (the rest of KDE is compiled
> without -funroll-loops). It's compiled with (Mandrake) gcc-2.96. The
> backtrace is obtained by attaching gdb to a running process.
>
> Michael.
>
> #0  0x407b678c in malloc () from /opt/kde3/lib/libkdecore.so.4
> #1  0x41021a1b in __builtin_new () from /usr/lib/libstdc++-libc6.2-2.so.3
> #2  0x406c58d8 in KStandardDirs::resourceDirs () from
> /opt/kde3/lib/libkdecore.so.4 #3  0x406c0a5b in
> KStandardDirs::findResourceDir () from /opt/kde3/lib/libkdecore.so.4 #4 
> 0x406bf6e6 in KStandardDirs::findResource () from
[snip]
> () from /opt/qt3/lib/libqt-mt.so.3 #33 0x40a06b61 in
> QApplication::enter_loop () from /opt/qt3/lib/libqt-mt.so.3 #34 0x409ad518
> in QApplication::exec () from /opt/qt3/lib/libqt-mt.so.3 #35 0x40024a0b in
> main () from /opt/kde3/lib/kwrite.so
> #36 0x410855b0 in __libc_start_main () from /lib/libc.so.6

 /me shivers uncomfortably after seeing a backtrace ending in malloc() again

 But this looks like a compiler bug to me. There shouldn't be any (functional) 
difference between code compiled with and without -funroll-loops. I even 
vaguely remember that older gcc versions had this switch buggy, making 
everybody put -fno-unroll-loops everywhere just in case (or was that 
-fno-strength-reduce? I don't remember).
 Moreover I don't understand how broken kdeprint (whatever is wrong there) can 
cause crashes ten functions deeper.
 

-- 
 Lubos Lunak
 llunak at suse.cz ; l.lunak at kde.org
 http://dforce.sh.cvut.cz/~seli





More information about the kde-core-devel mailing list