It's kind of a noob question, but what arguments do I give to gcc and ld to get an executable with a symbol table for dynamic linking? Of course, the executable must be able to use the functions I have defined in my OS and no libc. Do I need to create a .so file from my kernel, somehow, or is having the header files enough?
The reason is that I want to see how I can load and link the executable at run-time. I don't really care what executable format it will be, I just want to see how it looks. But I seem unable to get a simple "Hello world", which uses one of my OS functions, to compile (undefined reference). This is probably because I am not a native C or C++ programmer, having only ever dealed with the functions that I defined myself for my OS, in my own header files.
Any help or pointers in the right direction are greatly appreciated!
Compiling dynamically linkable executable for my OS
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Compiling dynamically linkable executable for my OS
Here's how you do something like it in NASM:
Well, in a real mode OS that puts everything in a single segment, you would set up vectors at the beginning at, say 0x1000, each one jumping to its respective system call. They would be jmp short instructions, each three bytes long (the jmp is one, and the address is two).
Then, your programs would include an include file that does something like this:
Then again, that only works in real mode in a single segment. It's extremely simple, though!
EDIT: The first equ being 0x1003 is because the first three bytes are a jmp short os_main (or whatever the label after the equ's are called), taking up three bytes!
Well, in a real mode OS that puts everything in a single segment, you would set up vectors at the beginning at, say 0x1000, each one jumping to its respective system call. They would be jmp short instructions, each three bytes long (the jmp is one, and the address is two).
Then, your programs would include an include file that does something like this:
Code: Select all
call_printf equ 0x1003
call_getch equ 0x1006
call_gets equ 0x1009
etc, etc...
EDIT: The first equ being 0x1003 is because the first three bytes are a jmp short os_main (or whatever the label after the equ's are called), taking up three bytes!
Re: Compiling dynamically linkable executable for my OS
Hi,Virtlink wrote:It's kind of a noob question, but what arguments do I give to gcc and ld to get an executable with a symbol table for dynamic linking? Of course, the executable must be able to use the functions I have defined in my OS and no libc. Do I need to create a .so file from my kernel, somehow, or is having the header files enough?
The reason is that I want to see how I can load and link the executable at run-time. I don't really care what executable format it will be, I just want to see how it looks. But I seem unable to get a simple "Hello world", which uses one of my OS functions, to compile (undefined reference). This is probably because I am not a native C or C++ programmer, having only ever dealed with the functions that I defined myself for my OS, in my own header files.
Any help or pointers in the right direction are greatly appreciated!
The headers are enough. Compile your program with "-Wl,-shared -Bsymbolic", and you should get a dynamically linkable shared object out.
EDIT: For clarification, those are link time flags, assuming you're linking by calling "gcc". If you're linking by calling "ld" directly, remove the -Wl, bit - "-shared -Bsymbolic".
Cheers,
James