Export Symbol Table (or making libraries)
Export Symbol Table (or making libraries)
Hey,
I've been coding some functions for accessing keyboard... similar to getchar(). I've compiled the C file containing the function along with the rest of my kernel code.
Now I was wondering how can I write an application program that can access the getchar() function.
Is there any way I can find out which address the getchar function is loaded to.
I know I'm being quite unclear, but can any1 who had atleast a slight idea of what I said point me in the right direction on the wiki.... something perhaps related to making libraries for a new os or something..
I've been coding some functions for accessing keyboard... similar to getchar(). I've compiled the C file containing the function along with the rest of my kernel code.
Now I was wondering how can I write an application program that can access the getchar() function.
Is there any way I can find out which address the getchar function is loaded to.
I know I'm being quite unclear, but can any1 who had atleast a slight idea of what I said point me in the right direction on the wiki.... something perhaps related to making libraries for a new os or something..
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Export Symbol Table (or making libraries)
A userspace application or one running with the kernel?
Re: Export Symbol Table (or making libraries)
Actually, any application which is not linked directly into the kernel..
Re: Export Symbol Table (or making libraries)
I believe, although I may be mistaken, that you can link a program against any ELF file - even a fully-compiled executable. So, you could add a header file for "getchar", or a prototype so that your code compiles, and then add your kernel to the end of the link line. The linker should then attempt to resolve any unresolved references in the kernel - which is exactly what you want.instance wrote:Hey,
I've been coding some functions for accessing keyboard... similar to getchar(). I've compiled the C file containing the function along with the rest of my kernel code.
Now I was wondering how can I write an application program that can access the getchar() function.
Is there any way I can find out which address the getchar function is loaded to.
I know I'm being quite unclear, but can any1 who had atleast a slight idea of what I said point me in the right direction on the wiki.... something perhaps related to making libraries for a new os or something..
Please do let me know if it works
Cheers,
James
Re: Export Symbol Table (or making libraries)
Or perhaps it's parsing the ELF file and the symbol table that is what you want? That would get you the possibility to resolve the symbol in runtime (ie dynamic linking). Look for the ELF specification (or whatever binary format you're using).
Re: Export Symbol Table (or making libraries)
Does your getchar() function depend on any kernel functions or services? If this is not the case than you can put the getchar() code in a seperate .c file and compile it with your kernel and non-kernel applications. Otherwise you would have to go with berkus's system call approach, or use kernel modules.
This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though.JamesM wrote:...
I believe, although I may be mistaken, that you can link a program against any ELF file - even a fully-compiled executable. So, you could add a header file for "getchar", or a prototype so that your code compiles, and then add your kernel to the end of the link line. The linker should then attempt to resolve any unresolved references in the kernel - which is exactly what you want.
Re: Export Symbol Table (or making libraries)
Not quite - the linker never copies an object file verbatim into the final executable - it (usually) deletes unreferenced code.Martijn wrote:This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though.JamesM wrote:...
I believe, although I may be mistaken, that you can link a program against any ELF file - even a fully-compiled executable. So, you could add a header file for "getchar", or a prototype so that your code compiles, and then add your kernel to the end of the link line. The linker should then attempt to resolve any unresolved references in the kernel - which is exactly what you want.
Re: Export Symbol Table (or making libraries)
Hi, guys! I have a question too.
See: if I need to call getchar() from any app I need to link my source of app with library. But what about task rings? I mean that code of getch() is ring0 made, and app is ring3. Or I am wrong? (Then how can it be, that I call code from ring3 and this code is ring3 but do the same as kernel's code that is in ring0? )
Sorry, for strange (and some stupid) question...
See: if I need to call getchar() from any app I need to link my source of app with library. But what about task rings? I mean that code of getch() is ring0 made, and app is ring3. Or I am wrong? (Then how can it be, that I call code from ring3 and this code is ring3 but do the same as kernel's code that is in ring0? )
Sorry, for strange (and some stupid) question...
Don't think a ****, but in ukrainian schools English is TOO BAD!
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Export Symbol Table (or making libraries)
At least that's what people like to believe.JamesM wrote:Not quite - the linker never copies an object file verbatim into the final executable - it (usually) deletes unreferenced code.Martijn wrote:This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though.JamesM wrote:...
I believe, although I may be mistaken, that you can link a program against any ELF file - even a fully-compiled executable. So, you could add a header file for "getchar", or a prototype so that your code compiles, and then add your kernel to the end of the link line. The linker should then attempt to resolve any unresolved references in the kernel - which is exactly what you want.
Re: Export Symbol Table (or making libraries)
Normally you can't do that because when linking for producing a executable you'd remove relocation information (other required information might be removed as well). If you don't it's still a question whether the linker/loader accepts a object/executable as executable/object.JamesM wrote: I believe, although I may be mistaken, that you can link a program against any ELF file - even a fully-compiled executable. So, you could add a header file for "getchar", or a prototype so that your code compiles, and then add your kernel to the end of the link line. The linker should then attempt to resolve any unresolved references in the kernel - which is exactly what you want.