0

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]

robomon
  • 269
  • 2
  • 16

1 Answers1

3

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

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • -v option in GCC didn't give me any information about which crt0 is used. I searched for crt0, crt1, *.S files and also for _start. Also with -ffreestanding, I am not getting the warning. – robomon Oct 22 '15 at 09:43
  • Did you *link* with `arm-none-eabi-gcc -v -Wall -Werror -O2` ? – Basile Starynkevitch Oct 22 '15 at 09:45
  • Yes I link. Because at the end I have the linker file defined and also test.o is my final output. In freestanding mode, which is then the "starting function" ? – robomon Oct 22 '15 at 09:47
  • You should read the standard. Freestanding C has no *standard* notion of *starting function*, it is *implementation specific* (and could be *user* specific) – Basile Starynkevitch Oct 22 '15 at 09:53
  • Ok. But if I don't want the freestanding mode, do you know from where the compiler get _start ? I am not able to find any info from -v – robomon Oct 22 '15 at 10:01