flat assembler
Message board for the users of flat assembler.

Index > Windows > dll in fasm (bug?!)

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 14 Dec 2005, 00:27
Code:
format PE GUI 4.0 DLL at 10000000h
entry DllEntryPoint


include '%fasminc%\win32a.inc'



section '.code' code readable executable


;BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

DllEntryPoint:
    mov eax, 1
    retn (4*3)


section '.reloc' fixups data discardable    


This dll not work after compiling in fasm, but similar dll work fine if it compiling in masm
I think this reloc macro problem
Post 14 Dec 2005, 00:27
View user's profile Send private message Reply with quote
james



Joined: 07 Sep 2005
Posts: 45
Location: Australia
james 14 Dec 2005, 09:32
And what happens if you copy the example DLL that comes with FASM ?
Post 14 Dec 2005, 09:32
View user's profile Send private message MSN Messenger Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 14 Dec 2005, 09:46
if it compiling in masm dll work fine

Code:
.486
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc


.CODE

; DllEntry proc hInst:DWORD, reason:DWORD, reserved1:DWORD
DllEntry:
    xor eax, eax
    inc eax
    retn 4*3

End DllEntry    
Post 14 Dec 2005, 09:46
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 14 Dec 2005, 12:26
You've got an empty .reloc section here, because you don't have any relocations. Windows doesn't accept PE files with empty sectinos - see http://board.flatassembler.net/topic.php?t=2330
Thus you should remove the .reloc section here, or use "data fixups" instead.


Last edited by Tomasz Grysztar on 14 Dec 2005, 17:59; edited 1 time in total
Post 14 Dec 2005, 12:26
View user's profile Send private message Visit poster's website Reply with quote
bogrus



Joined: 31 Jul 2004
Posts: 1
Location: Ukraine
bogrus 14 Dec 2005, 13:33
This sample normal work(with LoadLibrary) if default dll imagebase (0x00400000) not used in process (no need reloc), but LoadLibrary error if 0x00400000 used by main module (exe), uncomment dd 0,8 and this work ...
Code:
;=================================
format      pe gui dll
entry       start
include     '%fasminc%\win32a.inc'
;=================================
start:      xor     eax,eax
            inc     eax
            ret     0x0c
;=================================
data        fixups
;           dd 0,8
end         data
;=================================    
Post 14 Dec 2005, 13:33
View user's profile Send private message Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 14 Dec 2005, 13:47
Tomasz Grysztar

it's masm compiled DLL with empty reloc section, but it
work, because reloc directory should be present


Description:
Download
Filename: dll.zip
Filesize: 316 Bytes
Downloaded: 950 Time(s)

Post 14 Dec 2005, 13:47
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 14 Dec 2005, 17:55
There's no reloc directory there, since it's not needed (the "relocs stripped" flag in characteristics set to 0 is enough in this case), however the ".reloc" section (as a section, not directory - remember those are two different things) is not empty as made with MASM. You can put some own padding to the ".reloc" section to make it be not empty with fasm too, or remove it at all.
Post 14 Dec 2005, 17:55
View user's profile Send private message Visit poster's website Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 15 Dec 2005, 05:25
Post 15 Dec 2005, 05:25
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 15 Dec 2005, 09:56
I will try explain once more, maybe I will succeed to be more clear this time: the main problem here is what was discussed in the other thread (I linked to), not the relocations itself. When you write:
Code:
section '.reloc' fixups data discardable
 ; ...    

it's just the shortcut for writing the:
Code:
section '.reloc' data discardable
 data fixups
 ; ...
 end data
    
instead (the three dots mean any additional data you'd like to put inside the fixups directory). The "data fixups" itself generates the relocations directory inside the current section (directory always lies inside some section, but doesn't necessarily need to span the whole section), and when there are no relocations needed at all, it does nothing. In such case (as in your program, where there is no code that would need to be relocated), the above becomes to be just like:
Code:
section '.reloc' data discardable    

which just generates empty section and... see the other thread. Note: the fact that the section is called '.reloc' has nothing to do with the fact it does contain the fixups directory or not; you can call the section any name you want. You can replace '.reloc' with '.data' in all the above code samples if it misleads you.
Post 15 Dec 2005, 09:56
View user's profile Send private message Visit poster's website Reply with quote
leo



Joined: 16 Dec 2005
Posts: 2
Location: Russia
leo 16 Dec 2005, 18:02
Tomasz Grysztar
Quote:
There's no reloc directory there, since it's not needed (the "relocs stripped" flag in characteristics set to 0 is enough in this case)


I think, you are not quite right Wink
It's enough for NT, but Win 9x requires reloc directory to be present anyway and its size cannot be zero. If it is zero 9x regards it as relocs are stripped and cannot load dll on different image base. So for compatibility with 9x, masm uses this trick: via dd 0,8 it creates valid reloc directory with no real relocs
Post 16 Dec 2005, 18:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 16 Dec 2005, 18:18
You're right, it puts there a dummy block with no actual fixups (haven't noticed that earlier). If you need such fix, you can just add this dummy entry "dd 0,8" to the fixups data yourself. Really 9x has such bug? (Can't check it now, I might have known about it back when I was using W95, but forgot now... Wink) It's the flag in characteristics that should tell you whether the relocations were stripped or not, not the directory size. BTW, with the x64 empty reloc directories will come more often, as fixups are really rarely necessary there.


Last edited by Tomasz Grysztar on 16 Dec 2005, 18:30; edited 1 time in total
Post 16 Dec 2005, 18:18
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 16 Dec 2005, 18:27
PS. That's kind of funny - on Win9x the empty sections are accepted, but empty relocation directory for DLLs is not. Now on XP the empty sections are rejected, but empty relocs are OK.
Well, the safest would be to put the "dummy" entries everywhere just to ensure no zero-size things that would threat the Win PE loader. But it seems some people wouldn't like it - well, you can always put the "dummies" there yourself. fasm's rules to try making as small executable as possible prevails here.
Post 16 Dec 2005, 18:27
View user's profile Send private message Visit poster's website Reply with quote
halyavin



Joined: 21 Aug 2004
Posts: 42
halyavin 19 Dec 2005, 18:01
But can you add some directive to assembler (or macro library) for those people who prefer reliability? Dummies for relocations isn't obvious. Without this forum I will never create correct dll without relocations.
Post 19 Dec 2005, 18:01
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Dec 2005, 18:15
i don't think it is good to add some bloat to FASM just because of M$ bug. Just add it to FAQ, everyone should read FAQ first.
Post 19 Dec 2005, 18:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 20 Dec 2005, 00:18
Added it to Windows FAQ for now.
Post 20 Dec 2005, 00:18
View user's profile Send private message Visit poster's website Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 20 Dec 2005, 14:29
Maybe the correct decision was add the message
about a error in case of compilation such DLL ?
Post 20 Dec 2005, 14:29
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 20 Dec 2005, 16:02
But this is not an error, since this doesn't violate the PE specification, and thus you might really want to generate such executable - note that some people use PE format for their own OSes etc. Thus this is rather problem of the target OS you want to use your PE executable on and thus you should correct your sources accordingly - fasm itself just generates the PE file as you tell it to.
Post 20 Dec 2005, 16:02
View user's profile Send private message Visit poster's website Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
Aster!x 20 Dec 2005, 16:17
Tomasz Grysztar

But for example masm in many cases all the same warns the user - it is good practice
Post 20 Dec 2005, 16:17
View user's profile Send private message Reply with quote
wildtollwut



Joined: 10 Jul 2003
Posts: 4
Location: Germany
wildtollwut 21 Dec 2005, 18:30
Aster!x wrote:
Tomasz Grysztar

But for example masm in many cases all the same warns the user - it is good practice


windows also warns you 5 times before disabling the firewall, or some other fancy feature - it's a well known microsoft affliction Wink

_________________
when i want to jump in counter-strike, i simply enter "+jump" in the console
Post 21 Dec 2005, 18:30
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 21 Dec 2005, 22:51
warning: You shouldn't create PE file with empty sections because Microsoft Windows has bug with such sections will causing process to crash.
Post 21 Dec 2005, 22:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.