Re: [AD] problems compiling Allegro CVS with gcc 3.0.2

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Sven Sandberg wrote:

> salvador wrote:
> > Please compile without -fomit-frame-pointer, it generates wrong code
> > for one of the Unicode routines that is called before main and hence
> > nothing works.
>
> Yup, that seems to help. Salvador, do you know exactly which function it
> is? Maybe the error goes away if we reorganize it.

Yes, it could help because the bug looks quite stupid.
The function is ustrzcpy, be careful perhaps isn't the only one that
triggers the bug.
Here is the e-mail I sent to djgpp-workers:

Hi All!

  Again with problems with gcc 3.x and asking for verification. I compiled
Allegro 3.9.38 and all the programs crashed. Debugging the code I found what

I think is a code generation bug. Was hard to find the exact problem because

it appears only when -O2 *and* -fomit-frame-pointer are enabled (making the
debug task quite messy).
  Here is code to reproduce the crash:

<-------- start of test.c
static int utf8_getx(char const **s)
{ int c = *((unsigned char *)((*s)++)); return c; }

static int utf8_cwidth(int c)
{ return 1; }

static int utf8_setc(char *s, int c)
{ *s = c; return 1; }

char *ustrzcpy(char *dest, int size, const char *src)
{
   int pos = 0;
   int c;

   size -= utf8_cwidth(0);

   while ((c = utf8_getx(&src)) != 0) {
      size -= utf8_cwidth(c);
      if (size < 0)
         break;

      pos += utf8_setc(dest+pos, c);
   }

   utf8_setc(dest+pos, 0);

   return dest;
}

int main(int argc, char *argv[])
{
 char b[128];
 ustrzcpy(b,sizeof(b),"allegro.cfg");
 return 0;
}
<-------- end of test.c

Compile with:
gcc -o test.exe -O2 -fomit-frame-pointer test.c

And here is the funny code:

.globl _ustrzcpy
_ustrzcpy:
        pushl   %ebp
        pushl   %edi
        xorl    %edi, %edi
        pushl   %esi
        pushl   %ebx
        subl    $24, %esp
        movl    4(%ebp), %ebp
        movl    8(%ebp), %esi

As you can see EBP is used to hold one of the parameters and then used to
move another parameter to ESI. It should be done in the reverse order. But
things are even worst because the code also uses EBP after it.

SET

--
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: set@xxxxxxxxxx set@xxxxxxxxxx
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/