Relocations and executable format
Posted: Tue May 12, 2009 8:08 am
Hey all,
I've started working on my image loader and investigating exe formats etc.
Obviously the industry standards like ELF64, PE+ exist.. what I'm trying to weigh up is whether it would be most advantageous to just stick with one of these or write a new one from scratch.
Pro's of going with an existing one is that I can use existing dev tools to create executables.. the biggest con is I had in mind a very different way of approaching dynamic libraries, executables and machine services which these formats wouldn't support. Perhaps it would be best to support both... a standard at first to get going, then look at a newer model afterwards.
That being said .. I considered what would be required to say for example use FASM to create a flat image, then be able to relocate that image.. it seems like it would extremely difficult, possibly full of potential problems without having relocation information generated at compile/asm time.. for example:
mov rdi,0
mov eax,[rdi]
The 0 could refer to a fixed memory address, or something which requires fixup.. and it would be difficult to tell in all circumstances.. perhaps I'm missing something? In any event it seems like this would a bad idea.
So that would leave only one option, use an existing exec format that FASM can output with fixup/relocation information... Which seems like a good route for now, so considering that my os is 64bit only, would ELF64 or PE+ be the better option?
(I realise i sort of answered my own question while writing this post.. but it serves as a sanity check and if anyone can find fault with my logic great
I've started working on my image loader and investigating exe formats etc.
Obviously the industry standards like ELF64, PE+ exist.. what I'm trying to weigh up is whether it would be most advantageous to just stick with one of these or write a new one from scratch.
Pro's of going with an existing one is that I can use existing dev tools to create executables.. the biggest con is I had in mind a very different way of approaching dynamic libraries, executables and machine services which these formats wouldn't support. Perhaps it would be best to support both... a standard at first to get going, then look at a newer model afterwards.
That being said .. I considered what would be required to say for example use FASM to create a flat image, then be able to relocate that image.. it seems like it would extremely difficult, possibly full of potential problems without having relocation information generated at compile/asm time.. for example:
mov rdi,0
mov eax,[rdi]
The 0 could refer to a fixed memory address, or something which requires fixup.. and it would be difficult to tell in all circumstances.. perhaps I'm missing something? In any event it seems like this would a bad idea.
So that would leave only one option, use an existing exec format that FASM can output with fixup/relocation information... Which seems like a good route for now, so considering that my os is 64bit only, would ELF64 or PE+ be the better option?
(I realise i sort of answered my own question while writing this post.. but it serves as a sanity check and if anyone can find fault with my logic great