This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Stack initialisation in GNU ARM toolchain

Checking the startup file provided as an example in the GNU ARM toolchain, I couldnt understand one thing.

Code snippets provided here are taken from examples included in GNU ARM Embedded Toolchain files downloaded from your website. Code compiles and everything seems to be good.

I am wondering why its written this way, why you are using same names for example?

I am wondering why my linker is not complaining about multiple definition error for `__StackTop` and `__StackLimit`. Here is the part of the file `startup_ARMCM0.S`

        .syntax    unified
        .arch    armv6-m
    
        .section .stack
        .align    3
    #ifdef __STACK_SIZE
        .equ    Stack_Size, _*emphasized text*_STACK_SIZE
    #else
        .equ    Stack_Size, 0xc00
    #endif
        .globl    __StackTop
        .globl    __StackLimit
    __StackLimit:
        .space    Stack_Size
        .size    __StackLimit, . - __StackLimit
    __StackTop:
        .size    __StackTop, . - __StackTop


If the linker is defining the same symbols: `__StackTop` and `__StackLimit`.
    .stack_dummy (COPY):
        {
            *(.stack*)
        } > RAM
    
        /* Set stack top to end of RAM, and stack limit move down by
         * size of stack_dummy section */
        __StackTop = ORIGIN(RAM) + LENGTH(RAM);
        __StackLimit = __StackTop - SIZEOF(.stack_dummy);
        PROVIDE(__stack = __StackTop);


While checking linker documentation, it was written that, given the example:

     SECTIONS
     {
     .text :
         {
         *(.text)
         _etext = .;
         PROVIDE(etext = .);
         }
     }

 
 In this example, if the program defines `_etext` (with a leading underscore), the linker will give a multiple definition error.  If, on the other hand, the program defines `etext` (with no  leading  underscore),  the  linker  will  silently  use  the  definition  in the  program.   If  the program references `etext` but does not define it, the linker will use the definition in the linker script.Also, when using `readelf -s` just to check symbols generated from assembly file `startup_ARMCM0.S` without linking, I can see the symbol `__StackTop` and `__StackLimit` with one values. While, after linking they have the values set up by the linker (keeping in mind that the value of the linker is actually stored in address of the symbol).