linker.ld:
Code: Select all
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}
start.s
Code: Select all
.globl _start
_start:
ldr sp,=0x8000
bl main
b .
main.c
Makefile
Code: Select all
one:
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -c main.c -o main.o
arm-none-eabi-as start.s -o start.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -T linker.ld start.o main.o -o main.elf
arm-none-eabi-objdump -D main.elf > main.list
two:
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -c main.c -o main.o
arm-none-eabi-as start.s -o start.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -T linker.ld main.o start.o -o main.elf
arm-none-eabi-objdump -D main.elf > main.list
three:
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -c main.c -o main.o
arm-none-eabi-as start.s -o start.o
arm-none-eabi-ld -T linker.ld start.o main.o -o main.elf
arm-none-eabi-objdump -D main.elf > main.list
four:
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -c main.c -o main.o
arm-none-eabi-as start.s -o start.o
arm-none-eabi-ld -T linker.ld main.o start.o -o main.elf
arm-none-eabi-objdump -D main.elf > main.list
one output
Code: Select all
00008000 <_start>:
8000: e3a0d902 mov sp, #32768 ; 0x8000
8004: eb000000 bl 800c <main>
8008: eafffffe b 8008 <_start+0x8>
0000800c <main>:
800c: e3a00007 mov r0, #7
8010: e12fff1e bx lr
two output that might be your problem right there
Code: Select all
00008000 <main>:
8000: e3a00007 mov r0, #7
8004: e12fff1e bx lr
00008008 <_start>:
8008: e3a0d902 mov sp, #32768 ; 0x8000
800c: ebfffffb bl 8000 <main>
8010: eafffffe b 8010 <_start+0x8>
emphasized by these two
three output
Code: Select all
00008000 <_start>:
8000: e3a0d902 mov sp, #32768 ; 0x8000
8004: eb000000 bl 800c <main>
8008: eafffffe b 8008 <_start+0x8>
0000800c <main>:
800c: e3a00007 mov r0, #7
8010: e12fff1e bx lr
four output
Code: Select all
00008000 <main>:
8000: e3a00007 mov r0, #7
8004: e12fff1e bx lr
00008008 <_start>:
8008: e3a0d902 mov sp, #32768 ; 0x8000
800c: ebfffffb bl 8000 <main>
8010: eafffffe b 8010 <_start+0x8>
the no stdlib does/perhaps gets rid of crt0.o but also understand the linker places objects in the order they are found on the command line (unless overridden by the linker script itself)
Because you are ultimately making a binary image (objcopy -O binary) the entry point is that which is defined by whatever is using that binary image in this case the first word in the binary image. so you dont need to set an entry point in the elf file it does you no good. If you were to have start not be the first thing (as with having main before start on the linker command line) and the user of this binary can deal with elf or other formats that support an entry point, then you would care to set the entry point if it is not the first word in .text (or might have to set the entry point no matter what).
thanks for this opportunity for me to learn this but _start is not important as a name in this situation (as I think was already mentioned by the other answer)
Code: Select all
.globl notstart
notstart:
ldr sp,=0x8000
bl main
b .
make one and nobody complains that there is a lack of a _start symbol and the code works out fine
Code: Select all
00008000 <notstart>:
8000: e3a0d902 mov sp, #32768 ; 0x8000
8004: eb000000 bl 800c <main>
8008: eafffffe b 8008 <notstart+0x8>
0000800c <main>:
800c: e3a00007 mov r0, #7
8010: e12fff1e bx lr
David