flat assembler
Message board for the users of flat assembler.

 Index > Windows > dll in fasm (bug?!) Goto page 1, 2  Next
Author
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
Code:
```format PE GUI 4.0 DLL at 10000000h
entry DllEntryPoint

include '%fasminc%\win32a.inc'

;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
14 Dec 2005, 00:27
james

Joined: 07 Sep 2005
Posts: 45
Location: Australia
james
And what happens if you copy the example DLL that comes with FASM ?
14 Dec 2005, 09:32
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
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    ```
14 Dec 2005, 09:46
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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
14 Dec 2005, 12:26
bogrus

Joined: 31 Jul 2004
Posts: 1
Location: Ukraine
bogrus
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
;=================================    ```
14 Dec 2005, 13:33
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
Tomasz Grysztar

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

14 Dec 2005, 13:47
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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.
14 Dec 2005, 17:55
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
15 Dec 2005, 05:25
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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.
15 Dec 2005, 09:56
leo

Joined: 16 Dec 2005
Posts: 2
Location: Russia
leo
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
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
16 Dec 2005, 18:02
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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... ) 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
16 Dec 2005, 18:18
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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.
16 Dec 2005, 18:27
halyavin

Joined: 21 Aug 2004
Posts: 42
halyavin
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.
19 Dec 2005, 18:01
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
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.
19 Dec 2005, 18:15
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
Added it to Windows FAQ for now.
20 Dec 2005, 00:18
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
Maybe the correct decision was add the message
about a error in case of compilation such DLL ?
20 Dec 2005, 14:29
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7845
Location: Kraków, Poland
Tomasz Grysztar
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.
20 Dec 2005, 16:02
Aster!x

Joined: 16 Jul 2004
Posts: 26
Aster!x
Tomasz Grysztar

But for example masm in many cases all the same warns the user - it is good practice
20 Dec 2005, 16:17
wildtollwut

Joined: 10 Jul 2003
Posts: 4
Location: Germany
wildtollwut
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

_________________
when i want to jump in counter-strike, i simply enter "+jump" in the console
21 Dec 2005, 18:30
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
warning: You shouldn't create PE file with empty sections because Microsoft Windows has bug with such sections will causing process to crash.
21 Dec 2005, 22:51
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area
Goto page 1, 2  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum