Page 1 of 1
ELF
Posted: Sat Mar 23, 2002 6:50 am
by Darkening
Hi,
I'd like to try to load an ELF binary without using GRUB but all docs I've read have about 1 page about program loading - any hints on this??? Most important would be: order of loaded sections and what sections are important to load and which are not. Maybe something on relocation?
Thanks
Darkening
Re: ELF
Posted: Sat Mar 23, 2002 1:27 pm
by Kernel Panic
In ELF, there are sections and "segments". Sections denote logical parts of the executable (as code, data etc.) and segments describe what parts of the executable file are what (and, more importantly, which should be loaded). Basically, to run an ELF file, you have to do the following:
1. Read the ELF header and check that it is really an ELF file (and that it is built for your architecture).
2. Read the program headers (list of "segments"), location of which is specified in the ELF header.
3. Load every segment listed in the program headers that is marked loadable (type PT_LOAD).
4. If you load shared libraries along with the executable, remember the address of the dynamic section (the corresponding segment for which is marked PT_DYNAMIC).
If you use shared libraries, you also have to process all the relocations (I spent about two weeks firuring out everything about relocations, but that's not really difficult). Otherwise, there are no relocations.
BTW, are you loading the ELF kernel? If you want, I can mail you the source of my loader, which can load a kernel along with some modules and relocate everything (it is a bit complex, though).
Re: ELF
Posted: Sat Mar 23, 2002 1:29 pm
by Kernel Panic
BTW, this is the ELF specification. You may want to check it out:
http://www.nondot.org/sabre/os/files/Ex ... es/ELF.pdf
Re: ELF
Posted: Sat Mar 30, 2002 2:15 am
by Darkening
Sorry that I'm replying so late...
@Kernel Panic: Would be great to have a look at your source code! eMail address is
[email protected]
Darkening