flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [fasmg] segfault (iteration too high + no enough memory)

Author
Thread Post new topic Reply to topic
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 11 Nov 2019, 13:07
Hello! With this code:
Code:
_sections? := $00
namespace _sections?
end namespace
macro section? name?*
        local present
        present = $00
        irpv it, _sections?._name?
                if (name = it)
                        present = $01
                        break
                end if
        end irpv
        if (~(present))
                namespace _sections?
                        _name? =: name
                end namespace
        end if
end macro
repeat $DEED, i:$00
        section (`i)
end repeat
    

fasmg double free on linux sometime and segfault on UNIX(FreeBSD). I've not tested yet on Window/DOS.
Hope this help Smile.
Post 11 Nov 2019, 13:07
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 11 Nov 2019, 15:07
Thank you for the report! I found a pointer corruption bug in IRPV handler. I minimized your sample to expose it:
Code:
repeat $DEED
        x =: '1'
end repeat

irpv it, x
       db it
end irpv    
Please try version "iqi5k", it fixes this bug in specific.
Post 11 Nov 2019, 15:07
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 11 Nov 2019, 15:17
Back to your original snippet - such linear search is definitely a sub-optimal method of looking for an existing definition.

A trick I could recommend is to convert the string that contains section name into something that can be used as a label name in fasmg, and then you can make fasmg look up whether such name has been declared already. For example, you can simply convert any string to a decimal number and then use this number as a label name:
Code:
_sections? := $00
namespace _sections?
end namespace
macro section? name?*
        local present
        present = $00
        repeat 1, d:name
                if definite _sections.d
                        present = $01
                else
                        _sections.d := name
                end if
        end repeat
end macro
repeat $DEED, i:$00
        section (`i)
end repeat    
Post 11 Nov 2019, 15:17
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 11 Nov 2019, 19:51
You're welcome. I like the idea of ​​contributing to fasmg Smile. Thx for the tips too. In fact my whole code with 100+ sections was very slow (0.5 sec).
The problem is that, I record not only the section name but also the origin, alignement,... So for retreive the original value in a postpone block I do an irpv break for each field.
But I guess now, I can speed up the whole things Smile.
Post 11 Nov 2019, 19:51
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 14 Nov 2019, 16:21
Hi! After some experiment, I think that I found another bug (segfault/abort) on Linux/Unix. This concern the use of "?" in front of an identifier in an irpv and an namespace block.
Code:
Magic? := $00
namespace Magic?
        ?$CAFE? := "JAVA"
end namespace
irpv item, Magic?.?$CAFE?
        display (`item), $0A ; segfault here
end irpv
    

Hope this might help Smile.


Last edited by MaoKo on 15 Nov 2019, 02:13; edited 1 time in total
Post 14 Nov 2019, 16:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 14 Nov 2019, 16:51
The "?" in front of an identifier is a modifier of an entire identifier, it cannot be used in a middle of identifier like you did. The symbol that you defined has a case-insensitive name "$CAFE" and this is how you should access it:
Code:
irpv item, Magic?.$CAFE?    
In addition to that, the value that IRPV gives to "item" parameter is a proxy, because the iterated value is not symbolic, but evaluated. Therefore "`item" is not useful to show this value, as it only sees the name of the proxy.

You can either display the value directly, assuming it is a string:
Code:
Magic? := $00
namespace Magic?
        ?$CAFE? := "JAVA"
end namespace
irpv item, Magic?.$CAFE?
        display item, $0A
end irpv    
Or you can use symbolic assignment:
Code:
Magic? := $00
namespace Magic?
        ?$CAFE? equ "JAVA"
end namespace
irpv item, Magic?.$CAFE?
        display `item, $0A
end irpv    
Post 14 Nov 2019, 16:51
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 14 Nov 2019, 17:29
Thx Tomasz. I fact I knew for the "?", this was originally a typo that I made when writing some code.
However I thought that the proxy name "." only apply to negative value. But the whole code is just a proof of concept for the crash. Not in use in production obviously Smile
Post 14 Nov 2019, 17:29
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 23 Nov 2019, 20:39
Tomasz? What going on with this segfault?
Post 23 Nov 2019, 20:39
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 23 Nov 2019, 21:27
Oh, I'm sorry, I completely forgot about it. Please try the "iqyjc" release.
Post 23 Nov 2019, 21:27
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 100
Location: Paris/French
MaoKo 23 Nov 2019, 21:54
Yes thx. Your are fast x).
Post 23 Nov 2019, 21:54
View user's profile Send private message Visit poster's website 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.