flat assembler
Message board for the users of flat assembler.
Index
> Windows > dll in fasm (bug?!) Goto page 1, 2 Next |
Author |
|
james 14 Dec 2005, 09:32
And what happens if you copy the example DLL that comes with FASM ?
|
|||
14 Dec 2005, 09:32 |
|
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 |
|||
14 Dec 2005, 09:46 |
|
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 |
|||
14 Dec 2005, 12:26 |
|
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 ;================================= |
|||
14 Dec 2005, 13:33 |
|
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
|
|||||||||||
14 Dec 2005, 13:47 |
|
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.
|
|||
14 Dec 2005, 17:55 |
|
Aster!x 15 Dec 2005, 05:25
|
|||
15 Dec 2005, 05:25 |
|
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 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 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 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 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... ) 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 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. |
|||
16 Dec 2005, 18:27 |
|
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.
|
|||
19 Dec 2005, 18:01 |
|
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.
|
|||
19 Dec 2005, 18:15 |
|
Tomasz Grysztar 20 Dec 2005, 00:18
Added it to Windows FAQ for now.
|
|||
20 Dec 2005, 00:18 |
|
Aster!x 20 Dec 2005, 14:29
Maybe the correct decision was add the message
about a error in case of compilation such DLL ? |
|||
20 Dec 2005, 14:29 |
|
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.
|
|||
20 Dec 2005, 16:02 |
|
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 |
|||
20 Dec 2005, 16:17 |
|
wildtollwut 21 Dec 2005, 18:30
Aster!x wrote: Tomasz Grysztar 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 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.
|
|||
21 Dec 2005, 22:51 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.