How to link loaded modules against kernel?
Posted: Sat Feb 26, 2011 7:45 pm
Okay, I'm trying to have a core Elf binary, loaded by GRUB, be able to have a dynamic symbol table which loaded modules may link against.
First I tried to simply have LD produce the DYNAMIC section for the executable. '-E' doesn't work. '--force-dynamic' doesn't work. By doesn't work I mean LD doesn't produce any .dynamic sections.
Now if I separate the functionality needed by modules from the core into a shared object and link it against the kernel then the DYNAMIC section is created unnecessarily (because the dynamic symbols are in the shared object now not the executable), weird but that works so far. Then I attempt to have GRUB load my kernel and my shared object. I am able to load and relocate the module and jump to its DT_INIT function. However, I can't figure out how to get the reloc table of my kernel to be able to dynamic link itself to the now loaded module. I can get the .rel.* section headers from GRUB but all I have is the s_offset. Where is it offset from? I can't figure it out.
I think I'm missing something on either the ELF manual or LD. Either how do I get a .dynamic section in an executable (not linked against a shared object) or how do I get the Elf32_Rel entries after GRUB loads my kernel?
Thank you, any help would be much appreciated.
EDIT: Now that I think about it, I suppose I could have my kernel linked against a null (empty) shared object to coerce LD to produce the dynamic symbol table for it. But that seems arse-backwards and it feels like there could be something simpler and less-hackish.
EDIT: I've thought about it some more. And I suppose that I could use a boot kernel to load my core kernel and link it against the system module. So that'd be a boot executable (not really a kernel) that is loaded by GRUB as sort of a 3rd stage boot loader to load my core executable and system module and perform dynamic linking. That'd make the above a non-problem. Anyone else have any better ideas?
First I tried to simply have LD produce the DYNAMIC section for the executable. '-E' doesn't work. '--force-dynamic' doesn't work. By doesn't work I mean LD doesn't produce any .dynamic sections.
Now if I separate the functionality needed by modules from the core into a shared object and link it against the kernel then the DYNAMIC section is created unnecessarily (because the dynamic symbols are in the shared object now not the executable), weird but that works so far. Then I attempt to have GRUB load my kernel and my shared object. I am able to load and relocate the module and jump to its DT_INIT function. However, I can't figure out how to get the reloc table of my kernel to be able to dynamic link itself to the now loaded module. I can get the .rel.* section headers from GRUB but all I have is the s_offset. Where is it offset from? I can't figure it out.
I think I'm missing something on either the ELF manual or LD. Either how do I get a .dynamic section in an executable (not linked against a shared object) or how do I get the Elf32_Rel entries after GRUB loads my kernel?
Thank you, any help would be much appreciated.
EDIT: Now that I think about it, I suppose I could have my kernel linked against a null (empty) shared object to coerce LD to produce the dynamic symbol table for it. But that seems arse-backwards and it feels like there could be something simpler and less-hackish.
EDIT: I've thought about it some more. And I suppose that I could use a boot kernel to load my core kernel and link it against the system module. So that'd be a boot executable (not really a kernel) that is loaded by GRUB as sort of a 3rd stage boot loader to load my core executable and system module and perform dynamic linking. That'd make the above a non-problem. Anyone else have any better ideas?