Page 1 of 1

Bootloader functional; problem linking C kernel

Posted: Mon Mar 10, 2003 8:57 pm
by John Thomas
OK,

I've gotten to the stage where I've loaded my kernel off the floppy drive. When the kernel was in assembler, it worked fine; now I'm trying to get C working. I'm in protected mode and the stack is set up and everything. Protected mode code works in assembly, selectors work. I created the custom linker script as recommended.

The problem is when I try to link my kernel to an assembly stub that will jump into the main kernel
function. It says that it has an unresolved symbol:

_GLOBAL_OFFSET_TABLE_

LD then dies. I'm calling LD like this:

ld -T kernel.lnk stub.o kernel.o -o kernel.bin

in nasm, I'm just creating the image by:

%include 'boot.asm'
incbin 'kernel.bin'

Then dding it out to the floppy

I've tried faking that symbol, to no avail. Can someone tell me what the problem is? Please don't tell me to use a.out or coff, I'm writing the OS in BeOS, in which LD only supports elf. I believe I'm using gcc version 2.9.2

Re:Bootloader functional; problem linking C kernel

Posted: Mon Mar 10, 2003 10:18 pm
by John Thomas
Well, to answer my own question, I put a global in my stub so that I can link properly. I think this is a bug in ld. Oh well. ;)

Re:Bootloader functional; problem linking C kernel

Posted: Mon Mar 10, 2003 11:45 pm
by Chris Giese
The Global Offset Table is used for ELF dynamic linking. If you're making a kernel, the kernel should probably be statically linked. Use "ld -static ..."

Re:Bootloader functional; problem linking C kernel

Posted: Tue Mar 11, 2003 2:06 am
by Pype.Clicker
the global offset table is usually generated when you ask for generation of Position Independent Code (with -fpic). Check your compilation statements.

Re:Bootloader functional; problem linking C kernel

Posted: Tue Mar 11, 2003 1:03 pm
by John
Hmm, I used -Bstatic before, and it still stuck around. I wasn't generating position independent code either. I'll try just -static this time and see if it works.

Thanks for your help