Page 1 of 1

cannot find entry symbol _start while linking

Posted: Wed Nov 05, 2014 7:55 pm
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

Re: cannot find entry symbol _start while linking

Posted: Wed Nov 05, 2014 9:26 pm
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.

Re: cannot find entry symbol _start while linking

Posted: Thu Nov 06, 2014 12:42 am
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