Bootloader functional; problem linking C kernel

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
John Thomas

Bootloader functional; problem linking C kernel

Post 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
John Thomas

Re:Bootloader functional; problem linking C kernel

Post 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. ;)
Chris Giese

Re:Bootloader functional; problem linking C kernel

Post 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 ..."
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Bootloader functional; problem linking C kernel

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

Re:Bootloader functional; problem linking C kernel

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