[fpc-devel] Bug with R+ and assembler functionsHi,

Markus Kämmerer mk at happyarts.de
Thu Nov 3 11:53:37 CET 2005


Hi,

as you know we use FreePascal with our OpenXP Project
(www.openxp.de/.com). We found, that after compiling our release
version, an important function doesn't work anymore. After long search,
I found, that compiling with R- instead of R+ is the reason. There is a
bug in fpc. See the following code:

compiled with R+

# [904] zlen:=FindUmbruch(cont[offset],zlen);    { in EDITOR.ASM }
	movl	-20(%ebp),%edx
	movl	%ebx,%eax
	movzwl	-8(%ebp),%esi
> >	movl	%esi,%ecx
	cmpl	$65500,%ecx
	jbe	.Lj1668
	call	FPC_RANGEERROR
.Lj1668:
	leal	16(%eax,%esi,1),%eax
	call	EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT

compiled with R-

# [904] zlen:=FindUmbruch(cont[offset],zlen);    { in EDITOR.ASM }
	movl	-20(%ebp),%edx
	movl	%ebx,%eax
	movzwl	-8(%ebp),%ecx
	leal	16(%eax,%ecx,1),%eax
	call	EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT

start of FindUmbruch:

DITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT:
	.stabs "FINDUMBRUCH:f6",36,0,254,EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT
	.stabs "DATA:rv35",64,0,254,0
	.stabs "ZLEN:rp6",64,0,254,2
# Temps allocated between ebp-4 and ebp-4
	.stabs "editor.pas",132,0,0,.Lf2
.Lf2:
	.stabn 68,0,306,.Ll48 - EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT
.Ll48:
	pushl	%ebp
	movl	%esp,%ebp
	subl	$4,%esp
# Var data located in register
# Var zlen located in register
# Var $result located at ebp-4
	.stabn 68,0,257,.Ll49 - EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT
.Ll49:
# [257] mov   esi,data
	movl	%eax,%esi
	.stabn 68,0,258,.Ll50 - EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT
.Ll50:
# [258] mov   ebx,zlen
	movl	%edx,%ebx
	.stabn 68,0,259,.Ll51 - EDITOR_FINDUMBRUCH$formal$LONGINT$$LONGINT

Findumbruch awaits the "data" in esi. With the R+ version, the value is
loaded to esi before range check. In the R- version the value is located
in ecx and not been copied to esi, which is the bug.

You may test this bug with the openxp source
(ftp://www.openxp.de/openxp/openxp-4.0.7144.src.tar.bz2), file is
editor.pas. R- can be changed in xpdefine.pas. Source compiled with -O1

If you need more information, I'll do as much as I can.

P.S. Pascal snippet of FindUmbruch

unction FindUmbruch(var data; zlen:integer):integer; assembler; {&uses
ebx, esi}
  { r?ckw"rts von data[zlen] bis data[0] nach erster Umbruchstelle suchen }
asm
            mov   esi,data
            mov   ebx,zlen
            test  ebx, ebx
            jz    @ufound
  @floop:
            mov   al,[esi+ebx]
            cmp   al,' '               { ' ' -> unbedingter Umbruch }
            jz    @ufound

            cmp   al,'-'               { '-' -> Umbruch, falls alphanum. }
            jnz   @testslash           {        Zeichen folgt: }
            mov   al,[esi+ebx+1]
            cmp   al,'0'               { '0'..'9' }
            jb    @fnext
            cmp   al,'9'
            jbe   @ufound
            cmp   al,'A'               { 'A'..'Z' }
            jb    @fnext
            cmp   al,'Z'
            jbe   @ufound
            cmp   al,'a'               { 'a'..'z' }
            jb    @fnext
            cmp   al,'z'
            jbe   @ufound
            cmp   al,'€'               { '€'..'¥' }
            jb    @fnext
            cmp   al,'¥'
            jbe   @ufound
            jmp   @fnext

  @testslash:
            cmp   ebx,1
            ja    @testslash2
            mov   ebx,0
            jmp   @ufound
  @testslash2:
            cmp   al,'/'               { '/' -> Umbruch, falls kein }
            jnz   @fnext               {        Trennzeichen vorausgeht }
            cmp   byte ptr [esi+ebx-1],' '
            jz    @fnext
            cmp   byte ptr [esi+ebx-1],'-'
            jnz   @ufound

  @fnext:
            dec   ebx
            jnz   @floop
  @ufound:
            mov   eax,ebx
{$IFDEF FPC }
end ['EAX', 'EBX', 'ESI'];
{$ELSE }
end;
{$ENDIF }



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20051103/d8b41b69/attachment.sig>


More information about the fpc-devel mailing list