flat assembler
Message board for the users of flat assembler.

flat assembler > Compiler Internals > fasm 1.72: empty relocation section bug

Author
Thread Post new topic Reply to topic
ShabbyBumblebutt



Joined: 02 Jan 2018
Posts: 5
W7 SP1 x64 rejects binary (as non win32 program) with empty relocation section:

Code:
include 'win32ax.inc'

section '.reloc' fixups data readable discardable

.code

  start:
        ret

.end start
    


Code:
Number  Name   VirtSize   RVA    PhysSize  Offset    Flag
    1 .reloc   00000000 00001000 00000000 00000200 42000040
    2 .text    00000001 00001000 00000200 00000200 60000020
    3 .idata   00000014 00002000 00000200 00000400 C0000040
    


Removing '.reloc' section or adding 'lea eax, dword ptr start' to fill that section helps.
Post 02 Jan 2018, 00:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
Actually it is a Windows bug in the loader refusing to accept empty relocs sections.

You can "fix" it by placing a dummy "dq 0" in the relocs section at the end. Or if you are worried about the extra bloat of 8 bytes you can check if the section is empty and only place the dq 0 if there is nothing else there.


Last edited by revolution on 02 Jan 2018, 16:31; edited 1 time in total
Post 02 Jan 2018, 05:10
View user's profile Send private message Visit poster's website Reply with quote
ShabbyBumblebutt



Joined: 02 Jan 2018
Posts: 5
I'm sure that Fasm must show a warning in that case. How i'm supposed to know why my binary not works?
Post 02 Jan 2018, 05:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
There are systems other than Windows that use the PE format. It is unfortunate that Windows has such a bug, but for most programs you can run without a relocs section perfectly fine. And for those non-trivial programs that want to have things like ASLR available then the relocs section would never be empty anyway. The impact is too low for MS to care about fixing it.
Post 02 Jan 2018, 05:32
View user's profile Send private message Visit poster's website Reply with quote
ShabbyBumblebutt



Joined: 02 Jan 2018
Posts: 5
I make some trivial stub and it not even loading - how i'm supposed to know the reason without such warning?
Post 02 Jan 2018, 05:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
I'm not sure what you are suggesting. Are you expecting fasm to tell of problems with Windows? It's actually Windows job to tell you why it fails. But Windows is not very helpful in these cases. It would be possible to make fasm always output a non-empty relocs section but then other systems that aren't Windows might fail. I don't know all the details of it, but empty sections are a problem for Windows, not just the relocs sections. It affects all sections.
Post 02 Jan 2018, 06:29
View user's profile Send private message Visit poster's website Reply with quote
ShabbyBumblebutt



Joined: 02 Jan 2018
Posts: 5
Fasm can check subsystem (gui/console/native) for detecting windows program.
Post 02 Jan 2018, 06:54
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6966
Location: Kraków, Poland
revolution wrote:
I don't know all the details of it, but empty sections are a problem for Windows, not just the relocs sections. It affects all sections.
It was even worse than that. Windows 9x accepted empty sections, but frowned on empty fixups, while NT-based Windows had no problem with empty fixups but did not allow empty sections. There was no consistent Win32 behavior for these cases.
Post 02 Jan 2018, 09:16
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-2018, Tomasz Grysztar.

Powered by rwasa.