flat assembler
Message board for the users of flat assembler.
Index
> Main > Offset for relocation table |
Author |
|
Tomasz Grysztar 16 Jan 2023, 16:07
This is something that was requested several times for fasm 1, but I never found a satisfying way of implementing it there, so it became one of the things that led to the design of fasm g. The auxiliary documentation for fasmg has examples of collecting relocation information in the How are the labels processed? section. There is also a chapter about generating relocations from scratch in my fasmg-based PE tutorial. And for more advanced examples you may look at how various fasm-compatible output formatters are constructed.
|
|||
16 Jan 2023, 16:07 |
|
Coldy 17 Jan 2023, 08:10
Thanks for the quick response! Yes, the question was how to do it in fasm. fasm g is a new tool for me, I don't know how compatible it is with the fasm codebase.
|
|||
17 Jan 2023, 08:10 |
|
Tomasz Grysztar 17 Jan 2023, 10:05
The example of adapting to assemble HeavyThing should give a rough idea about the level of compatibility. And a project like FASMW can be assembled by fasmg with literally no changes to source, just set up include variable to point to the compatibility headers. If your code does not use complex macro features etc. then generally fasmg should be able to handle it easily.
|
|||
17 Jan 2023, 10:05 |
|
Tomasz Grysztar 17 Jan 2023, 10:23
A very simple example of generating relocation information for x86 code with fasmg:
Code: include 'cpu/p6.inc' use32 format binary as 'bin' element RELOCATABLE_BASE org RELOCATABLE_BASE + $ virtual as 'rel' ; save relocations into separate file Relocations:: end virtual macro dd? data& iterate unit, data match ?, unit dd ? else if unit relativeto RELOCATABLE_BASE virtual Relocations dd $% ; record raw offset end virtual dd unit-RELOCATABLE_BASE else dd unit end if end iterate end macro start: mov eax,start mov edx,[start] If you need ALIGN, you can take the universal implementation and set it up by telling it what is the guaranteed alignment of your relocatable base: Code: include 'align.inc' align.assume RELOCATABLE_BASE, 16 |
|||
17 Jan 2023, 10:23 |
|
Coldy 18 Jan 2023, 12:53
Tomasz Grysztar wrote: ... I see that in fasm can add a new rule for relocaton block (for example) like this Code: relocation relocation_offsets_table ; User defined relocation table here end relocation relocation_offsets_table is an array of dword as offsets in the code where relocation need to be applied Such a table is probably generates for the PE format, but no access to it in birary format That would be enough |
|||
18 Jan 2023, 12:53 |
|
Tomasz Grysztar 18 Jan 2023, 13:21
Since fasm also handles formats like COFF and ELF, I needed a design that would be able to handle all the options, including generation of all kinds of relocations relative to various bases. I was thinking about it a lot back in the day and these designs laid foundation for fasmg's linear polynomials, with ELEMENT directive and operators like ELEMENTOF/METADATAOF. But this is something that cannot be back-ported into fasm 1 in a usable way.
In short: fasmg was my answer to requests for this and several other features (like namespaces). I did deliver it all and more, and I did even back-port some of the easier features into fasm 1, but for many others it's not possible. You could try tweaking fasm 1 to allow for some very narrow solution, like what you suggested, but I'm unlikely to work on anything like that - what I already designed and implemented is ways ahead. |
|||
18 Jan 2023, 13:21 |
|
sylware 19 Jan 2023, 12:54
BTW, did you hear about the new ELF relocation for PIE programs?
I wonder if this new relocation is more planned obsolescence than anything else. |
|||
19 Jan 2023, 12:54 |
|
bitRAKE 19 Jan 2023, 21:27
I did patch fasm to allow custom relocation table generation. Although it's not a long term solution, but rather a hack to show how one might do it with minimal effort.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
19 Jan 2023, 21:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.