Page 1 of 1

Linker error under Linux

Posted: Sun Jul 04, 2004 2:27 pm
by Mike
I'm just trying to compile a simple kernel under Linux. I'm getting a linker error:

Code: Select all

[mike@pc-00065 kernel3]$ gcc -c kernel.c -o kernel.o
[mike@pc-00065 kernel3]$ nasm -f aout k_entry.asm -o k_entry.o
[mike@pc-00065 kernel3]$ ld -T kernel.ld  k_entry.o kernel.o
k_entry.o(.text+0x16):k_entry.o: undefined reference to `_k_main'
I'm sure it's something silly. Any help appreciated.

Thanks

Part of the kernel entry asm is:

Code: Select all

[BITS 32]

[global start]
[extern _k_main] ; this is in the c file

start:
  ; stop using bootloader GDT, and load new GDT
  lgdt [gdt_ptr]

  mov ax,LINEAR_DATA_SEL
  mov ds,ax
  mov es,ax
  mov ss,ax
  mov fs,ax
  mov gs,ax

  call _k_main

  jmp $ ; crash
And part of the kernel.c file sis:

Code: Select all


void k_main(void) // like main
{
   k_clear_screen();

   k_printf("Welcome to Simplified OS.", 0);
   update_cursor(1, 0);
   k_printf("Right now the kernel is loaded at 1MB physical,/nbut mapped at FF800000 hex.", 3);
   update_cursor(5, 0);

   k_printf("Remapping the PIC...", 6);
   update_cursor(7,0);
   remap_pics(0x20, 0x28);   // irq 0 20h irq 8 28h

   k_printf("PIC remapped starting at 20 hex.", 7);
   update_cursor(8,0);
};

Re:Linker error under Linux

Posted: Sun Jul 04, 2004 2:39 pm
by Mike
Argh, solved it. I was compiling a C file, so the C compiler doesn't add an _ to the beginning of exported symbols. D'oh!!! ;D

Re:Linker error under Linux

Posted: Sun Jul 04, 2004 6:24 pm
by Mike
Ok, another problem. This is my build script:

Code: Select all

#! /bin/bash

gcc -c kernel.c -o kernel.o
nasm -f elf k_entry.asm -o k_entry.o
ld -T kernel.ld k_entry.o kernel.o
mv a.out kernel.bin
The ld command gives the error: File size limit exceeded

I only get this if I use -f elf. -f a,out works fine. However, grub then gives error 13 - unsupported file format, I think.

Thanks

Re:Linker error under Linux

Posted: Sun Jul 04, 2004 11:53 pm
by Solar
Without seeing your linker script, and the kernel.asm you gave rather obviously being only a quick rip-off what's really in there, it's hard to tell why your file size limit should be exceeded.

I'd point you to "the a.out kludge" in the GRUB documentation which would show you how to make GRUB boot an a.out image, but the ld error message points to an error somewhere in your setup, and the a.out kludge would merely cover that one up...