cannot find entry symbol _start while linking

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
MarkZar
Posts: 13
Joined: Thu Feb 07, 2013 11:53 pm

cannot find entry symbol _start while linking

Post by MarkZar »

There is a warning while linking: CrossGcc/lib/gcc/i686-elf/4.9.2/../../../../i686-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000007c00. I don't know why the linker cannot find _start, I've looked into the boot.o file using readelf, and found the following line:

Code: Select all

Symbol table '.symtab' contains 10 entries:
...
     8: 00000000     0 FUNC    GLOBAL DEFAULT    1 _start
There is a global func called _start, so the linker should find it, but it didn't. what's wrong with it?

boot.s:

Code: Select all

.section .bootstrap_stack, "w", @nobits
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .text
.global _start
.type _start, @function
_start:
	movl $stack_top, %esp
	call kernel_main  #kernel_main is in the kernel.c file
.loop:
	jmp .loop
boot.ld:

Code: Select all

ENTRY(_start);
SECTIONS
{
    . = 0x7C00;
    .text : {*(.text)}
    
    .signature : AT(0x7DFE)
    {
        SHORT(0xAA55);
    }
    /DISCARD/ : {*(.eh_frame)}
}
Relevant code in makefile:

Code: Select all

$(RELEASE)/kernel.o: $(SOURCE)/kernel.c
	i686-elf-gcc -c -ffreestanding $< -o $@ -Wall -Wextra
$(RELEASE)/boot.o: $(SOURCE)/boot.s
	i686-elf-as $< -o $@
$(RELEASE)/kernel.bin: $(RELEASE)/kernel.o $(RELEASE)/boot.o
	i686-elf-gcc -T boot.ld -o $@ -ffreestanding -nostdlib $< -lgcc
Regards,
mycityofsky
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: cannot find entry symbol _start while linking

Post by sortie »

$< only contains the first prerequisite, so you are not linking in boot.o in the first place. Remember to carefully read the outputted commands make prints. This use of $< is unportable btw, as it is not a suffix or wildcard rule.
MarkZar
Posts: 13
Joined: Thu Feb 07, 2013 11:53 pm

Re: cannot find entry symbol _start while linking

Post by MarkZar »

sortie wrote:$< only contains the first prerequisite, so you are not linking in boot.o in the first place. Remember to carefully read the outputted commands make prints. This use of $< is unportable btw, as it is not a suffix or wildcard rule.
Thank you, What you said is right, I should look into the outputs first.

Regards,
mycityofsky
Post Reply