flat assembler
Message board for the users of flat assembler.
Index
> Windows > format PE64 GUI 4.0 DLL needs relocations with FASM 1.70 |
Author |
|
Tomasz Grysztar 09 Aug 2012, 15:22
It was a bugfix. When you don't put fixups into your image, fasm assembles it with absolute (not relocatable) addresses, and thus it cannot know whether this image can be relocatable or not. The IMAGE_FILE_RELOCS_STRIPPED is thus set in such case, to let system know that the image may not be safe to relocate. Because this DLL shares the same address with the program that tries to load it, and the DLL image cannot be relocated, loader fails.
To see that this is the only reason you can change the first line of DLL to this one: Code: format PE64 GUI 4.0 DLL at 1000000h But the proper solution is to put relocations somewhere in the DLL image, like this: Code: data fixups end data |
|||
09 Aug 2012, 15:22 |
|
Tomasz Grysztar 09 Aug 2012, 15:28
PS In case you don't know what does it mean that fasm assembles with absolute addresses, I will show it on a simple example. When fasm uses absolute values for labels (as it does when you don't put fixups into your image) you are allowed to do things like:
Code: mov rax,(DllMain shr 3) xor 0xABCD And this is because of allowing such things that fasm is not able to guarantee that the image will be safely relocatable and thus sets the IMAGE_FILE_RELOCS_STRIPPED flag. |
|||
09 Aug 2012, 15:28 |
|
pzimm 10 Aug 2012, 12:50
Hi Tomasz,
Thanks for your quick response. I have understood the reason setting IMAGE_FILE_RELOCS_STRIPPED if the image does not contain fixups. But how can I assemble and successfully load the following code Code: format PE64 GUI 4.0 DLL at 400000h entry DllMain section '.text' code readable executable align 16 DllMain: mov eax,1 ret align 16 myfun: mov rax, rcx add rax, [rip-.next+.constant] .next: ret align 8 .constant dq 0x7621 section '.edata' export data readable dd 0 ; Export Flags dd %t ; Time/Date Stamp dw 0 ; Major Version dw 0 ; Minor Version dd RVA _DllName ; Name RVA dd 1 ; Ordinal Base dd 1 ; Address Table Entries dd 1 ; Number of Name Pointers dd RVA ExportAddressTable ; Export Address Table RVA dd RVA ExportNamePointerTable ; dd RVA ExportOrdinalTable ; ExportAddressTable: dd RVA myfun ExportNamePointerTable: dd RVA _myfun ExportOrdinalTable: dw 0 _DllName db 'LIBTEST.DLL',0 _myfun db 'myfun',0 The code is completely relocatable, but I cannot assemble it with fixups (-> "Error: Invalid use of symbol."). Without fixups it can't be loaded due to IMAGE_FILE_RELOCS_STRIPPED set and the conflicting base address. If I clear bit IMAGE_FILE_RELOCS_STRIPPED within the image (i.e. change byte 0x2fh to 0x2e at offset 0x96) it will be loaded and executed successfully. Kind regards, Peter |
|||
10 Aug 2012, 12:50 |
|
l_inc 10 Aug 2012, 20:41
pzimm
I actually think, the compiler should resolve this situation, but until then you could replace Code: add rax, [rip-.next+.constant] with Code: add rax, [rip+.constant-.next] |
|||
10 Aug 2012, 20:41 |
|
Tomasz Grysztar 26 Sep 2012, 12:51
l_inc wrote: pzimm |
|||
26 Sep 2012, 12:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.