Elf loading

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Elf loading

Post by itisiuk »

well, ive started my move away from flat binary executables to elf.

so far ive followed the specs and ive just finished.
however i realised do i have to write elf loading to a specific linker script or not.

so far i havent found the answer to this and thought id better ask before i start writing
more code.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Elf loading

Post by AJ »

How do you mean?

For a linked program, follow program headers, relocate and zero as appropriate, then jump to the entry point.

For a shared object, do the same with section headers, but there's no entry point.

The process should be the same whether or not you compiled with a linker script. Just be careful that if you use aligned sections, the size in the file will be less that the size in memory - you need to relocate information by "filesz" and then zero any additional memory specified by "memsz - filesz" (these variables have prefixes in the ELF specification depending on whether they are from program or section headers). Also beware of any sections which take up 0 bytes in the final memory image (avoid these by checking the program header type - should be PT_LOAD IIRC).

Cheers,
Adam
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Elf loading

Post by itisiuk »

soz i was been a bit thick posting this question. :oops:
ive worked it out now.

cheers
Post Reply