This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ccs compiler allocate local variable space on stack

Hi,

I have a question about the local variables's space on stack allocated by compiler.

I use CCSv6.1 arm compiler 5.2.7.

When I use one pointer variable, the space is reserved by "sub sp, sp, #8" but in my opinion, it should be "sub sp, sp, #4"

When I use two pointer variables, the space is reserved by "sub sp, sp, #8" same as the first one.

When I use three pointer variables, the space is reserved by "sub sp, sp, #0x10".

can I infer that the compiler will keep the stack's alignment to 8 bytes, right?

  • eric said:
    can I infer that the compiler will keep the stack's alignment to 8 bytes, right?

    Yes, if you are using EABI. Section 6.10.2 Run-Time Stack of the ARM Optimizing C/C++ Compiler v5.2 User's Guide says:

    EABI requires that 64-bit data (type long long and long double) be aligned at 64-bits. This requires that the stack be aligned at a 64-bit boundary at function entry so that local 64-bit variables are allocated in the stack with correct alignment. The boot routine aligns the stack at a 64-bit boundary.