Hi everyone,
I've been looking into loading SO binaries as my OS's drivers lately. So far I've been perusing the ELF specification, the NewOS source code, and numerous other websites (courtesy of Google).
But now, after almost a week of searching, I'm still hardly anywhere nearer to getting it working.
All I need is to load an SO binary to a specific location in memory (assume I already have the binary loaded and in RAM) and to link any external references in that binary to the kernel (ie, dprintf). That's all I need - nothing fancy.
Can anybody help me out here?
Loading an SO
Possibly
You have to parse the ELF file, pull out the relevant section/program headers (my ELF world has been turned upside down since I learned that section headers are not actually required...). The vaddr of those program headers should start at an offset 0, instead of some crazy absolute value like 0x800024 (in linux).
Load them all in. Then, find the section called .got, for Global Offset Table. Read about it in the ELF manual, along with the PLT (procedule linkage table). Essentially you put a pointer to a 'patching function' in the GOT. All dynamic calls are made such that the first time they are called they call that 'patching function' to retrieve their jump target. Once they have that they modify the PLT so the next time that function is called the jump target is cached.
Cheers,
James
You have to parse the ELF file, pull out the relevant section/program headers (my ELF world has been turned upside down since I learned that section headers are not actually required...). The vaddr of those program headers should start at an offset 0, instead of some crazy absolute value like 0x800024 (in linux).
Load them all in. Then, find the section called .got, for Global Offset Table. Read about it in the ELF manual, along with the PLT (procedule linkage table). Essentially you put a pointer to a 'patching function' in the GOT. All dynamic calls are made such that the first time they are called they call that 'patching function' to retrieve their jump target. Once they have that they modify the PLT so the next time that function is called the jump target is cached.
Cheers,
James
For linked files the section headers are irrelevant, but for object files they are the relevant part.JamesM wrote:my ELF world has been turned upside down since I learned that section headers are not actually required...
Wouldn't it be better to use unlinked object files for drivers? I mean than you don't need a PLT/GOT. You just link the object file into the kernel at load time.