Loading an SO

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Loading an SO

Post by pcmattman »

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?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

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
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post by bluecode »

JamesM wrote:my ELF world has been turned upside down since I learned that section headers are not actually required...
For linked files the section headers are irrelevant, but for object files they are the relevant part.

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.
Post Reply