flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [BUG] Some docs and formatter bug's with MZ and PE

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
MZ :

Quote:
"heap" directive should be followed by a 16-bit value defining maximum size of additional heap in paragraphs (this is heap in addition to stack and undefined data).


Strange ... Confused

Quote:
Use "heap 0" to always allocate only memory program really needs. Default size of heap is 65535.


Not really.

Fix proposal:

Quote:
"heap" directive should be followed by a 16-bit value defining maximum size of additional heap in paragraphs (this is memory allocated additionally to the program size and the stack space). Use "heap 0" to always allocate only memory program really needs. Default value here is 65535, the effect is completely filling the biggest free continuous memory block.


PE :

Quote:
Among with flags also one of the special PE data identifiers can be specified to mark the whole section as a special data, possible identifiers are "export", "import", "resource" and "fixups". If the section is marked to
contain fixups, they are generated automatically and no more data needs to be defined in this section.


Problem: When placing multiple aforementioned things into one section, FASM is happy and brews the PE, but it is garbage and doesn't run.

1. Formatter bug - reject such code
2. Docs bug - mention this fact

Quote:
Also resource data can be generated automatically from the resource file, it can be achieved by writing the "from" operator and quoted file name after the "resource" identifier. Below are the examples of sections containing some special PE data:

section '.reloc' data discardable fixups


Should be:

section '.reloc' data readable discardable fixups

Some Win32 examples are also affected by this bug.
Post 30 Nov 2009, 06:26
View user's profile Send private message Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
Location: Severodvinsk, Russia
SFeLi
Are you sure about section '.reloc' data readable discardable fixups? AFAIK, Windows loader sets protection attributes after fixup stage. Am I wrong?
Post 30 Nov 2009, 06:31
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
It apparently works (in most version of Windows) without "readable" ... but still seems to be a BUG.
Post 30 Nov 2009, 06:46
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7709
Location: Kraków, Poland
Tomasz Grysztar
DOS386 wrote:
Quote:
"heap" directive should be followed by a 16-bit value defining maximum size of additional heap in paragraphs (this is heap in addition to stack and undefined data).


Strange ... Confused

The MZ executable can have larger size in memory than in file, if you put undefined data at the end of source, the header will tell DOS to allocate more memory than just what is needed to load the pages from file. Also, if you don't define stack yourself, fasm defines stack automatically, using the same mechanism to ensure that required memory is allocated.

DOS386 wrote:
Quote:
Use "heap 0" to always allocate only memory program really needs. Default size of heap is 65535.


Not really.

Right, it's a bit unfortunate phrase. I'd go for "Default value of this setting is 65535" instead. Or even just insert word "maximum" before the "size".

DOS386 wrote:
Problem: When placing multiple aforementioned things into one section, FASM is happy and brews the PE, but it is garbage and doesn't run.

There is a lot of methods how to make executable that's will not work properly by abusing various settings. However you can still (if you're clever enough) utilize them in such a way, that even with combined (supposedly contradictory) settings you may get something correct. fasm should not limit your options unless it's something impossible to implement according to format limitations. But this is not the case.

DOS386 wrote:
Quote:
Also resource data can be generated automatically from the resource file, it can be achieved by writing the "from" operator and quoted file name after the "resource" identifier. Below are the examples of sections containing some special PE data:

section '.reloc' data discardable fixups


Should be:

section '.reloc' data readable discardable fixups

Some Win32 examples are also affected by this bug.

This is questionable - the "readable" flag applies to the run-time settings of the section, that is it refers to the ability of your own code to read this section. However it should not affect the loader, which has to be able to read all the sections anyway. Personally, I think that combining "readable" with "discardable" is not a very useful combination, since the section that can be discarded is not safe for you to read anyway, so if you wanted to be able to read it from your code, you shouldn't put "discardable" there in the first place.
Post 01 Dec 2009, 13:34
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Tomasz Grysztar wrote:
The MZ executable can have larger size in memory than in file, if you put undefined data at the end of source, the header will tell DOS to allocate more memory than just what is needed to load the pages from file.


So "undefined data" is the difference between size promised in the header and actual file size ???

Quote:
There is a lot of methods how to make executable that's will not work properly by abusing various settings. However you can still (if you're clever enough) utilize them in such a way, that even with combined (supposedly contradictory) settings you may get something correct. fasm should not limit your options unless it's something impossible to implement according to format limitations. But this is not the case.


I can put all into one section when using format binary as "DLL" Smile

Quote:
This is questionable - the "readable" flag applies to the run-time settings of the section, that is it refers to the ability of your own code to read this section. However it should not affect the loader, which has to be able to read all the sections anyway. Personally, I think that combining "readable" with "discardable" is not a very useful combination, since the section that can be discarded is not safe for you to read anyway, so if you wanted to be able to read it from your code, you shouldn't put "discardable" there in the first place.


OK, interesting point. Then all linkers are faulty Laughing
Post 01 Dec 2009, 14:03
View user's profile Send private message 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-2020, Tomasz Grysztar.

Powered by rwasa.