Page 1 of 1

Linker probleme ...

Posted: Sat Aug 18, 2007 11:11 am
by iscalibar
Hy devs, I'm trying to create my own OS, i've created a very small kernel but i have a problem. Every time i use the linker's command i get this msg, help pls
the msg:"ld: warning: cannot find entry symbol system; defaulting to 0000000000000000"
given that:
the kernel file "system.c" is :
int main(){

char hatem[20]="hatemStein";

char *vidmem=(char *)0xb8000;

char a=0x7;

*(vidmem+2)='A';

*(vidmem+3)=a;

for(;;);

return 3;

}

the linker file "link.ld" is:
OUTPUT_FORMAT("binary")

ENTRY(system)

phys = 0x000009c0;

SECTIONS

{

.text phys : AT(phys) {

code = .;

*(.text)

}

.data : AT(phys + (data - code))

{

data = .;

*(.data)

. = ALIGN(4096);

}

.bss : AT(phys + (bss - code))

{

bss = .;

*(.bss)

. = ALIGN(4096);

}

end = .;

}
the commands are:
>gcc -o system.c
>ld -T link.ld -o kernel.bin system.o
the message error is:
>ld: warning: cannot find entry symbol system; defaulting to 00000000000009c0
help pleas

Posted: Sat Aug 18, 2007 4:20 pm
by os64dev
well, duh. try using main instead of system in the linker script. The entry section in the linker script specifies the 'function' it should call when started. as you only specified main and not system it should be clear what to do. Read before you post.. If this seems a little roughly spoken, im sorry. its late, i've just finished a bottle of really good wine and this is a rather trivial thing. He Dex i finally understand ya ;-).
No seriously welcome to os devving.

Posted: Sat Aug 18, 2007 4:55 pm
by jnc100
To be honest, specifying the entry point makes little to no difference when you're targeting a flat binary format, other than stopping that warning message. If you want to make sure that the first byte of your executable is the first byte of your first function, the best way is to create an assembly stub, which you probably already have anyway (to set up gdt and stuff), have that call you C kernel_main or something function, and then pass your asm stub as the first object file on your linker command line and you should be okay.

Regards,
John.

Posted: Sat Aug 18, 2007 6:43 pm
by iscalibar
thanks, it works :D

Posted: Sun Aug 19, 2007 11:38 am
by Candy
jnc100 wrote:To be honest, specifying the entry point makes little to no difference when you're targeting a flat binary format, other than stopping that warning message. If you want to make sure that the first byte of your executable is the first byte of your first function, the best way is to create an assembly stub, which you probably already have anyway (to set up gdt and stuff), have that call you C kernel_main or something function, and then pass your asm stub as the first object file on your linker command line and you should be okay.
Or use a linker file and use that as a robust solution.