Page 1 of 1

Problems with kernel linking

Posted: Thu Dec 14, 2006 10:04 am
by pianohacker
I'm writing a basic kernel right now. It's written in C++, and is based on the tutorial kernel at http://osdever.net/bkerndev/ , with some minor changes to function names, etc. I've gotten as far as trying to print on the screen, but the linker is messing up. To print something, I'm passing the "Hello, World!" string constant to kernel::screen::write(). Once I link this, though, grub decides to give me an "Unrecognized executable format" error. This is for good reason: when I "less" the compiled kernel, it starts with "Hello, World!" Any idea what's wrong?
I can post linker scripts, compile options, etc. if anyone wants them.

Posted: Thu Dec 14, 2006 10:21 am
by ntfs
You have to be sure the header is included in right manner. Try to run mbchk.exe (multiboot checker) on the file. I got riddiculously the same message when using ELF and compliing to multiboot specs.

Posted: Thu Dec 14, 2006 10:45 am
by pianohacker
No need to do that, actually:

$ od -c -N 13 ceres-kernel.bin
0000000 H e l l o , W o r l d !
0000015

The first 13 bytes of the compiled kernel are actually Hello, World! I'm passing the compiled ASM loader as the first argument to ld, but still that damn string is the first thing in the file...

EDIT: $ mbchk ceres-kernel.bin
ceres-kernel.bin: No Multiboot header.

Posted: Thu Dec 14, 2006 10:56 am
by urxae
You don't have a .rodata section in your linker script. Copy-paste the .data section, and replace data by rodata in the copy. Don't forget to change the appropriate AT() clauses as well.