flat assembler
Message board for the users of flat assembler.
Index
> Main > Multiple passes vs. relocations |
Author |
|
revolution 15 Sep 2011, 15:48
I use this code under WinXPSP2:
Code: format PE GUI 4.0 entry start section '.code' data readable executable start: ret section '.reloc' data discardable data fixups if ~ $-$$ dd 0,8 ;empty fixups section iff no other fixups end if end data |
|||
15 Sep 2011, 15:48 |
|
l_inc 15 Sep 2011, 16:02
revolution
Well... Thank you. I thought about creating relocations manually. A little bit nasty, but seems to be the only working solution. |
|||
15 Sep 2011, 16:02 |
|
Tomasz Grysztar 15 Sep 2011, 16:19
Wow, this one is complex. I will try to explain why your method failed. First, the default value assumed for variable not yet defined (in the very first pass) is 0, so "relocs_size = 0" is true in first pass and causes "safe_relocs" to be defined. We could try to correct it this way:
Code: if inverse_relocs_size = 0FFFFFFFFh | defined safe_relocs ; ... inverse_relocs_size = dword not ($-$$) So a different approach is needed in this case. We can, for example, exploit the fact that section with just one fixup is 10 bytes in length: Code: if relocs_size = 0 | (defined safe_relocs & relocs_size = 10) safe_relocs dd $ end if revolution's solution is much nicer though. I definitely recommend to do it revolution's way. |
|||
15 Sep 2011, 16:19 |
|
l_inc 15 Sep 2011, 17:39
Tomasz Grysztar
Quote:
Thank you! That's exactly, what I was trying to do, but failed to achieve because of some knowledge lack. E.g. undefined variable value defaulting to zero is not documented anywhere, is it? Quote: revolution's solution is much nicer though. I definitely recommend to do it revolution's way Why not making an empty relocations table to be compiled to dd 0,8? As revolution mentioned, zero-sized sections are not accepted by windows loader and thus make no sense. |
|||
15 Sep 2011, 17:39 |
|
Tomasz Grysztar 15 Sep 2011, 17:53
Well, it was discussed before: http://board.flatassembler.net/topic.php?p=33127#33127 (note the Win9x vs WinNT difference, too).
|
|||
15 Sep 2011, 17:53 |
|
l_inc 15 Sep 2011, 18:15
Tomasz Grysztar
I meant the relocation table, not the relocation section. And dd 0,8 does not mean creation of a dummy block, it really means an empty relocations table with no blocks. Thus padding of any section to achieve non-zero-sized-section is quite normal, because it's the programmer's responsibility to create or to omit section creation. But padding of a relocation table makes no-relocations-case to some special case, whereas making this code: Code: data fixups end data to be compiled as dd 0,8 makes no-relocations-case as regular as any other case. |
|||
15 Sep 2011, 18:15 |
|
Tomasz Grysztar 15 Sep 2011, 18:20
Please read the whole thread I linked to.
|
|||
15 Sep 2011, 18:20 |
|
l_inc 15 Sep 2011, 18:41
Tomasz Grysztar
Sorry. What I wrote before: Quote: And dd 0,8 does not mean creation of a dummy block, it really means an empty relocations table with no blocks. is not true. My mistake. |
|||
15 Sep 2011, 18:41 |
|
revolution 16 Sep 2011, 03:19
l_inc wrote: But padding of a relocation table makes no-relocations-case to some special case, whereas making this code: |
|||
16 Sep 2011, 03:19 |
|
Tomasz Grysztar 16 Sep 2011, 07:36
Not true that it does nothing - it creates an empty relocation table which you can fill out yourself if you need (just like any other case of "data" directive, in fact).
Also, as mentioned in that other thread, empty relocations directory is not something wrong by itself - though some Windows versions did have problems with it, others don't. Code: BASE = 1000000h format PE at BASE org BASE ; ... data fixups ; DIY fixups end data |
|||
16 Sep 2011, 07:36 |
|
revolution 16 Sep 2011, 08:35
Tomasz Grysztar wrote:
Code: data fixups_without_auto_generation ;My fixus go here end data Code: format PE GUI 4.0 DLL entry start section '' data readable executable start: ret data fixups end data |
|||
16 Sep 2011, 08:35 |
|
Tomasz Grysztar 16 Sep 2011, 08:53
revolution wrote: If there were some way to stop fasm from automatically inserting the fixups then it would be a true DIY: That's what the "org BASE" line in my example is for. ...but I made a mistake, it really should have been: Code: org BASE + rva $ Because you've got non-zero RVA right from the start. The trick lies in the fact that "BASE + rva $" is an absolute value equivalent to unrelocated "$". So starting from that point you define absolute addresses, and fasm has no relocations to make. |
|||
16 Sep 2011, 08:53 |
|
revolution 16 Sep 2011, 09:24
Tomasz Grysztar wrote: That's what the "org BASE" line in my example is for. |
|||
16 Sep 2011, 09:24 |
|
DOS386 18 Sep 2011, 08:53
Tomasz Grysztar wrote: Well, it was discussed before: http://board.flatassembler.net/topic.php?p=33127#33127 (note the Win9x vs WinNT difference, too). And here http://board.flatassembler.net/topic.php?t=11170 |
|||
18 Sep 2011, 08:53 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.