Page 1 of 1

Modules & Grub

Posted: Mon Jan 30, 2006 6:01 pm
by Unlink
Hello,
i've some question regarding modules loading and grub.

i use -R to add my kernel symbols in my modules

fisrt - how should i compile & link my modules ?
second - should i link my modules with the same linker script of the kernel?
third - or there should be another linker script for my modules?

How do u load modules in ur kernel, do it needs a relocation or something ?

Re:Modules & Grub

Posted: Tue Jan 31, 2006 2:31 am
by Pype.Clicker
this is how clicker creates and load modules
i use -R to add my kernel symbols in my modules
that is incremental linking, right ? that's quite a good idea, but it may make typos hard to catch since you couldn't make the difference at first sight between unresolved "kmalloc" (to be linked with the kernel symbol) and "kmallco" (typo, won't be linked with anything) until you load the module, so you may want to take the time to compare the output of "objdump -x <module>" with the table of symbols exported by your kernel
second - should i link my modules with the same linker script of the kernel?
probably not. e.g. the linker script of the kernel may contain hints to load stuff at the expected kernel's place while your module will more likely need to be loaded anywhere. Yet, there are things that you can keep such as the generic guidelines (.rodata* and the like).
Actually, you may even not need a linker script at all for the modules.
How do u load modules in ur kernel, do it needs a relocation or something ?
simply put,
- load stuff in proper place (that is, moving it from where GRUB placed it to where I want it to be)
- process relocations (patch the binary so that it fits the place it received)
- process symbols (retrieve required symbols and patch the binary again ... then add exported symbols to the 'ksyms' table)
- call initialization routine(s).

Other steps (such as automatic loading of depending modules, keeping track of dependencies, etc.) have been added over time, but i don't think you're going to need that immediately.