Linking a userland program to the kernel
Posted: Sat Aug 11, 2007 5:28 am
Hi,
I'm trying to get my userland programs to link nicely with my kernel. Essentially I'm using remote procedure calls, so userland programs actually have to call kernel functions directly. However, I don't want to compile any of the kernel code statically in to these programs (for obvious reasons). So, what I want to do, is have all references to kernel symbols (functions etc) to automatically resolve to the correct address in kernel code. I don't think I explained that all too well, so here's an example:
Userland program:
So, I need all kernel symbols to be defined, when linking a userland program.
So, I thought about several ways to do this. The first was to create a .so for my kernel, then bind the symbols dynamically when the program is loaded. This seems like an elegant solution to me, but I get the following error when linking with this .so (and before you ask I've tried every damn combination of ld flags both when linking the .so and linking the userland program ):
I get this error when I compile the library with "-shared". If I compile with "-r" (relocatable), it links but it links statically
OK, so any help on that would be grand, but I tried another method - that is manually defining all kernel symbols at link-time.
I can do this with
and I'm sure I can hack up a script to read the output from nm and dump it into a command file, but it doesn't seem like an elegant solution, and I'm pretty damn certain it won't scale up well (for thousands of symbols).
Any help would be MUCH appreciated
And I have tried google. of course. But that link error pulled up 3 results, all 3 of which being the source code from ld that prints that error!
JamesM
I'm trying to get my userland programs to link nicely with my kernel. Essentially I'm using remote procedure calls, so userland programs actually have to call kernel functions directly. However, I don't want to compile any of the kernel code statically in to these programs (for obvious reasons). So, what I want to do, is have all references to kernel symbols (functions etc) to automatically resolve to the correct address in kernel code. I don't think I explained that all too well, so here's an example:
Userland program:
Code: Select all
push eax
call 0x100010 <readStackPointer>
So, I thought about several ways to do this. The first was to create a .so for my kernel, then bind the symbols dynamically when the program is loaded. This seems like an elegant solution to me, but I get the following error when linking with this .so (and before you ask I've tried every damn combination of ld flags both when linking the .so and linking the userland program ):
Code: Select all
james@james-desktop:~/Code/C/Linux/jimix2/jimix2/trunk/initrd/udev$ ld -o udev -Bsymbolic ../../src/lib/crt0.o main.o ../../src/lib/libjimix.a -L ../../src/ -lkernel
ld: warning: type and size of dynamic symbol `readStackPointer' are not defined
ld: dynamic variable `readStackPointer' is zero size
ld: main.o(.text+0x2c): unresolvable R_386_PC32 relocation against symbol `readStackPointer'
ld: final link failed: Nonrepresentable section on output
OK, so any help on that would be grand, but I tried another method - that is manually defining all kernel symbols at link-time.
I can do this with
Code: Select all
--defsym readStackPointer=0x666
Any help would be MUCH appreciated
And I have tried google. of course. But that link error pulled up 3 results, all 3 of which being the source code from ld that prints that error!
JamesM