flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > FASM hangs forever...

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 03 Jun 2014, 21:23
Working on some source and trying to resolve some "code cannot be generated" error, I managed to make FASM to hang instead of generate mentioned error. I leaved it to work for 15 minutes in hope it will end, but it doesn't.
(The normal compilation takes less than 3 seconds, even when the code can't be generated on 128 passes limit.)

Console FASM for Linux and Fresh IDE, both compiler v1.71.21 has been tested with the same result. I believe, the problem can be reproduced in Windows as well.

The OS is Linux Mint. The hangs happens on the assembling stage of the compilation.

Unfortunately, the source that causes this behavior is huge and I actually have no idea where the problem can be. This way I can't reduce it to reasonably small example... Sad

In the attached file is the minimal (it is still huge) set of files I can create.

The file that need to be compiled is "test_code0/TestLib.asm". The commands are executed from inside the "test_code0" directory.

The lines that controls the hang/error/compilation behavior (although IMHO they are not the cause for this hang) are in the file "gui/realobjects.inc", line 143 and 146:
Code:
141:  match any, obj@parent \{
142:  \local ..here
143:;    if ~defined used.\#any | defined ..here
144:      used.\#any = 1
145:      ..here = 1
146:;    end if
147:  \}    


When the lines 143 and 146 are commented, the compilation hangs. When these lines are uncommented, the compilation ends with "code cannot be generated" in one case and no error (binary file generated) in another case.

Here are the command lines I use to test:

1. With lines commented (it hangs for long period and I interrupted it by ctrl+C):

Code:
env lib=.. TargetOS=Win32 fasm -m 65536 TestLib.asm
flat assembler  version 1.71.21  (65536 kilobytes memory)
^C    

Code:
env lib=.. TargetOS=Linux fasm -m 65536 TestLib.asm
flat assembler  version 1.71.21  (65536 kilobytes memory)
^C    


2. With lines uncommented:

Code:
env lib=.. TargetOS=Win32 fasm -m 65536 TestLib.asm
flat assembler  version 1.71.21  (65536 kilobytes memory)
error: code cannot be generated.    

Code:
env lib=.. TargetOS=Linux fasm -m 65536 TestLib.asm
flat assembler  version 1.71.21  (65536 kilobytes memory)
I18n strings placeholders: $4E5D9
17 passes, 1.1 seconds, 23107 bytes.    


Description: The sources
Download
Filename: fasm_bug.zip
Filesize: 426.84 KB
Downloaded: 615 Time(s)


_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9


Last edited by JohnFound on 04 Jun 2014, 06:05; edited 3 times in total
Post 03 Jun 2014, 21:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 04 Jun 2014, 01:47
JohnFound
"Hanging" is definitely not a bug. Just try to compile
Code:
while 1
end while    

On my machine it takes fasm one or two minutes until an overflow happens and it reports too many iterations. Now guess what happens if there's a bit more, than just an empty loop.

The "code cannot be generated" is hard to debug. That is why I already suggested once to display at least some variables, that did not get stable values. However the "hanging" problem is very easy to debug: just add
Code:
if %>10000
    err
end if    

into every loop in your code using a regular expression substitution over your project's files.

Quote:
When the lines 143 and 146 are commented, the compilation hangs

Well, probably it does not make sense to comment those lines, because you'll just trigger another bug in your code. Like one here:
Code:
    if ~defined used.#name ;ALERT! Bad coding habits detected
      virtual at $
    end if
      vtables.#name:
      ..space::
         .parent  dd 0          ; parent vtable
         .count   dd  vsize     ; method count in the virtual table.
...


    if ~defined used.#name ;ALERT! Same here
      end virtual
    end if    

What actually happens here is that at one pass you may have a virtual space, but at another one you won't have any. Now what you do a couple of lines below:
Code:
    if defined used.#name
      match any, parent \{
        load ..psize dword from vtables.\#parent + 4
        repeat ..psize
          load ..num dword from vtables.\#parent + 8 + (%-1)*4
          store dword ..num at ..space: vtables.\#name + 8 + (%-1)*4
        end repeat
      \}
    end if
    

Right. You are loading data from that sometimes-virtual-sometimes-not-thing. But two loads here do not specify the addressing space, which means that the values of ..psize and ..num are at some passes (when there's a virtual space) defined by the moon position. Every time you use such a value as a loop iteration count, you should be ready to experience some really long delays (hours, days and maybe longer).

There are obviously more bugs in your macros because of that "code cannot be generated". But as I said, this one is really hard to debug. But to recap, it does not make sense to comment the lines 143 and 146, because you'll just add more bugs such as redefinition of used.\#any, which in turn will cause undefined references to it at previous code locations.

_________________
Faith is a superposition of knowledge and fallacy
Post 04 Jun 2014, 01:47
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 04 Jun 2014, 04:51
Shame on me! I simply forgot about the long loops... Sad Embarassed
l_inc, thanks for the likbez.

Commenting the mentioned lines, was not an attempt to fix the "code cannot be generated" error. Just an attempt for diagnostics.
Post 04 Jun 2014, 04:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.