Why doesn't arm

I am compiling the below code with " -nostdlib ". My understanding was that arm-none-eabi-gcc will not use the _start in "crt0.o" but it will use the user defined _start . For this I was expecting to create a start.S file and put the _start symbol.

But if I compile the below shown code without the _start symbol defined from my side, I am not getting any warning. I was expecting "warning: cannot find entry symbol _start;"

Questions:

1) Why am I not getting the warning ? From where did GCC get the _start symbol ?

2) If gcc got the _start symbol from a file from somewhere, could you let me know how to ask GCC to use the _start from my start.S file ?

$ cat test.c

int main()
{
    volatile int i=0;
    i = i+1;

    return 0;
}

$ cat linker.ld

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 20K
}

SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}

$ arm-none-eabi-gcc -Wall -Werror -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostdlib -T linker.ld test.c -o test.o

$ arm-none-eabi-gcc --version

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 >(release) [ARM/embedded-4_9-branch revision 224288]


Compile and link with arm-none-eabi-gcc -v -Wall -Werror -O2 .... to understand what the compiler is doing (and which crt0 it is using; that crt0 probably has a _start calling your main , also _start might be the default entry point for your linker)

Notice that -nostdlib is related to the (lack of) C standard library; perhaps you want to compile in a freestanding environment (see this), then use -ffreestanding (and in that case main has no particular meaning, you need to define your starting function[s], and no standard C functions like malloc or printf are available except perhaps setjmp ).

Read the C99 standard n1256 draft. It explains what freestanding means in §5.1.2.1

链接地址: http://www.djcxy.com/p/86926.html

上一篇: 交叉编译为ARM:错误没有找到这样的文件或目录/命令

下一篇: 为什么不胳膊