Linker probleme ...

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
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

Linker probleme ...

Post 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
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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.
Author of COBOS
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post 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.
iscalibar
Posts: 7
Joined: Sat Aug 18, 2007 10:58 am

Post by iscalibar »

thanks, it works :D
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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