The MASM Forum Archive 2004 to 2012

Specialised Projects => Pelle's Macro Assembler Development => Topic started by: shlomok on April 14, 2012, 02:00:02 PM

Title: Possible bug in poasm when a ret is inside an .IF
Post by: shlomok on April 14, 2012, 02:00:02 PM
Hi,
Please refer to the full post here : http://www.masm32.com/board/index.php?topic=18690.0
but to sum up:
The following code will create an exe that always crashes when using Pelle's c to assemble and link it.
After inspecting the assembly it was clear that the first "ret" e.g. the one inside the .IF is the cause

allocateUsingHeapAlloc PROC  hHeap:DWORD, dwBytes:DWORD
                   
    invoke  HeapAlloc,hHeap, HEAP_ZERO_MEMORY,dwBytes
    .if eax == NULL
        invoke  StdOut,addr generalException
        mov     eax,FALSE
        ret
    .endif
    ret

allocateUsingHeapAlloc endp


The code runs smoothly using masm32.

Thanks,
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: hutch-- on April 14, 2012, 02:44:16 PM
Try a RETN inside the .IF block.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: dedndave on April 14, 2012, 02:45:58 PM
i think that will crash, but for a different reason   :bg
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: shlomok on April 14, 2012, 03:46:32 PM
Quote from: dedndave on April 14, 2012, 02:45:58 PM
i think that will crash, but for a different reason   :bg

You are right, crash , different reason :)  see the screenshot.

What was the assumption behind the suggestion to use RETN?
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: qWord on April 14, 2012, 04:22:47 PM
it is a bug!
The folowing example has the same problem:
.686
.model flat, stdcall
option casemap :none

.code
main proc
    .if eax == 0
        ret
    .endif
    ret
main endp
end main

who will report it to pelle?

qWord
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: dedndave on April 14, 2012, 06:02:32 PM
i elect Erol - lol
Erol may actually be Pelle in disguise (or the other way around)   :P

Quote from: shlomok on April 14, 2012, 03:46:32 PM
Quote from: dedndave on April 14, 2012, 02:45:58 PM
i think that will crash, but for a different reason   :bg

You are right, crash , different reason :)  see the screenshot.

What was the assumption behind the suggestion to use RETN?

when you use the meumonic "RET", the assembler assumes responsibility for typing it
and, if the epilogue is enabled, it also releases the stack frame and cleans up the stack parms, as required
the actual instructions are "RETN" for NEAR PROC's and "RETF" for FAR PROC's
there is also an IRET instruction, but that one must be explicit

you might try
        RETN    8
or whatever the appropriate number is
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: hutch-- on April 15, 2012, 03:38:16 AM
If the RET only misbehaves within an .IF block, it probably has to do with the handling within the .IF block. To isolate what is happening with 2 RET instructions I would remove the block .IF and code it manually CMP/JE etc .... This will tell you if the problem is related to the .IF handling or not.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: shlomok on April 15, 2012, 02:31:14 PM
Quote from: hutch-- on April 15, 2012, 03:38:16 AM
If the RET only misbehaves within an .IF block, it probably has to do with the handling within the .IF block. To isolate what is happening with 2 RET instructions I would remove the block .IF and code it manually CMP/JE etc .... This will tell you if the problem is related to the .IF handling or not.

Is this what you had in mind?

allocateUsingHeapAlloc PROC hHeap:DWORD, dwBytes:DWORD                    
invoke  HeapAlloc,hHeap, HEAP_ZERO_MEMORY,dwBytes
test eax, NULL
jnz   @F
ret
      @@:
invoke StdOut, "xxx"
ret

allocateUsingHeapAlloc endp


this does not crash.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: dedndave on April 15, 2012, 03:08:55 PM
yah - i'd say it's obviously the if/else   :P
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: Vortex on April 18, 2012, 06:36:08 PM
Hi shlomok,

The new Poasm version 7.00.0 has the same problem. I reported it in Pelles forum.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: Vortex on April 22, 2012, 05:58:29 PM
Pelle fixed the bug. You need to download Pelles Macro Assembler, Version 7.00.3 released with PellesC V7.0, Release Candidate #2
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: shlomok on April 23, 2012, 07:31:03 AM
Quote from: Vortex on April 22, 2012, 05:58:29 PM
Pelle fixed the bug. You need to download Pelles Macro Assembler, Version 7.00.3 released with PellesC V7.0, Release Candidate #2

Hi thanks a lot!,
The latest version available on the website is version 7.02 RC1 dated 2012-04-15.

Where did you download version 7.03?

S.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: Vortex on April 23, 2012, 08:12:49 AM
Hi shlomok,

You need to download the latest Pelles C development suit containing Poasm V7.00.3 :

http://www.smorgasbordet.com/pellesc/download.htm

http://www.smorgasbordet.com/pellesc/700/setup.exe

Pelle announced a new release candidate #2
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: shlomok on April 23, 2012, 07:01:37 PM
Quote from: Vortex on April 23, 2012, 08:12:49 AM
Hi shlomok,

You need to download the latest Pelles C development suit containing Poasm V7.00.3 :

http://www.smorgasbordet.com/pellesc/download.htm

http://www.smorgasbordet.com/pellesc/700/setup.exe

Pelle announced a new release candidate #2

Hi Vortex,
I was using: http://www.pellesc.de/index.php?page=download&lang=en

Didn't know about the link you provided. Thanks!

I can confirm that the bug was fixed (only tested the 32 bit version on a VM). So thanks to Pelle too.

Best,

S.
Title: Re: Possible bug in poasm when a ret is inside an .IF
Post by: Vortex on April 23, 2012, 09:06:36 PM
Hi shlomok,

I checked it now, here is the other link :

http://www.pellesc.de/index.php?page=download&lang=en&version=7.00