Export Symbol Table (or making libraries)

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
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Export Symbol Table (or making libraries)

Post by instance »

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..
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Export Symbol Table (or making libraries)

Post by Craze Frog »

A userspace application or one running with the kernel?
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Re: Export Symbol Table (or making libraries)

Post by instance »

Actually, any application which is not linked directly into the kernel..
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Export Symbol Table (or making libraries)

Post by JamesM »

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

Please do let me know if it works :-)

Cheers,

James
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Export Symbol Table (or making libraries)

Post by skyking »

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).
Martijn
Posts: 22
Joined: Tue Feb 26, 2008 3:43 am
Location: The Netherlands

Re: Export Symbol Table (or making libraries)

Post by Martijn »

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. ;)
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.
This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though. ;)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Export Symbol Table (or making libraries)

Post by JamesM »

Martijn wrote:
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.
This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though. ;)
Not quite - the linker never copies an object file verbatim into the final executable - it (usually) deletes unreferenced code.
User avatar
djsilence
Member
Member
Posts: 70
Joined: Wed Oct 01, 2008 11:18 am
Location: Ukraine, Kiev
Contact:

Re: Export Symbol Table (or making libraries)

Post by djsilence »

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? :shock: )

Sorry, for strange (and some stupid) question... :)
Don't think a ****, but in ukrainian schools English is TOO BAD!
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Export Symbol Table (or making libraries)

Post by Craze Frog »

JamesM wrote:
Martijn wrote:
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.
This will link the entire kernel executable into the target file. Not really a lightweight solution, but it should work though. ;)
Not quite - the linker never copies an object file verbatim into the final executable - it (usually) deletes unreferenced code.
At least that's what people like to believe.
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Export Symbol Table (or making libraries)

Post by skyking »

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