[lazarus] Nasty compiler bug ???

Marc Weustink marc at dommelstein.net
Sun Jan 7 19:27:11 EST 2001


While debugging the recent problems I found somthing wierd. The 
Segmentation fouls in Lazarus is generated in the following piece of code:

procedure SelectGDKPenProps(const DC: HDC);
   with PDeviceContext(DC)^, CurrentPen^ do
     gdk_gc_set_foreground(GC, @GDIPenColor);

If you look at the disassembly you notice that about 1.9 GB of stack is 
used for local vars

     0x8074950 <SELECTGDKPENPROPS>:	push   %ebp
     0x8074951 <SELECTGDKPENPROPS+1>:	mov    %esp,%ebp
     0x8074953 <SELECTGDKPENPROPS+3>:	sub    $0x72f7000c,%esp
A bit to much I quess to hold with1 and with2

     0x8074959 <SELECTGDKPENPROPS+9>:	mov    0x8(%ebp),%eax
     0x807495c <SELECTGDKPENPROPS+12>:	mov    %eax,0xfffffffc(%ebp)
     0x807495f <SELECTGDKPENPROPS+15>:	mov    0xfffffffc(%ebp),%eax
     0x8074962 <SELECTGDKPENPROPS+18>:	mov    0x1c(%eax),%eax
     0x8074965 <SELECTGDKPENPROPS+21>:	mov    %eax,0xfffffff8(%ebp)
     0x8074968 <SELECTGDKPENPROPS+24>:	mov    0xfffffff8(%ebp),%eax
     0x807496b <SELECTGDKPENPROPS+27>:	lea    0x4(%eax),%eax
     0x807496e <SELECTGDKPENPROPS+30>:	push   %eax
Causes segfault since stack is invalid.

     0x807496f <SELECTGDKPENPROPS+31>:	mov    0xfffffffc(%ebp),%eax
     0x8074972 <SELECTGDKPENPROPS+34>:	pushl  0x4(%eax)
     0x8074975 <SELECTGDKPENPROPS+37>:	call   0x804e484 <gdk_gc_set_foreground>

To check if this was compiler related I put all needed structs in one 
program, called the same piece of code and this version disassembed to:

     0x80542f0 <SELECTGDKPENPROPS>:	push   %ebp
     0x80542f1 <SELECTGDKPENPROPS+1>:	mov    %esp,%ebp
     0x80542f3 <SELECTGDKPENPROPS+3>:	sub    $0x8,%esp
Seems reasonable hold with1 and with2

     0x80542f6 <SELECTGDKPENPROPS+6>:	mov    0x8(%ebp),%eax
     0x80542f9 <SELECTGDKPENPROPS+9>:	mov    %eax,0xfffffffc(%ebp)
     0x80542fc <SELECTGDKPENPROPS+12>:	mov    0xfffffffc(%ebp),%eax
     0x80542ff <SELECTGDKPENPROPS+15>:	mov    0x1c(%eax),%eax
     0x8054302 <SELECTGDKPENPROPS+18>:	mov    %eax,0xfffffff8(%ebp)
     0x8054305 <SELECTGDKPENPROPS+21>:	mov    0xfffffff8(%ebp),%eax
     0x8054308 <SELECTGDKPENPROPS+24>:	lea    0x4(%eax),%eax
     0x805430b <SELECTGDKPENPROPS+27>:	push   %eax
     0x805430c <SELECTGDKPENPROPS+28>:	mov    0xfffffffc(%ebp),%eax
     0x805430f <SELECTGDKPENPROPS+31>:	pushl  0x4(%eax)
     0x8054312 <SELECTGDKPENPROPS+34>:	call   0x8048af8 <gdk_gc_set_foreground>

And that was something you would expect. So my question... what to do about it.


More information about the Lazarus mailing list