Keil Logo

ARMCC: Option --use_frame_pointer May Generate Wrong Code


Information in this knowledgebase article applies to:

  • Keil MDK
  • Arm Compiler 5 all versions up to 5.06u6

SYMPTOM

Using the Arm compiler version 5 with option --use_frame_pointer, wrong code might be generated under certain circumstances for Cortex-M microcontroller. This wrong code might cause sporadic run-time crashes or hardfaults. Here is an example:

int foo(void)
{
    int w = 4;
    int x = 5;
    int y = 6;
    int z = 7;
    return w + x + y + z;
}

This generates the following code:

foo
        0x00000000:    e92d4810    -..H    PUSH     {r4,r11,lr}
        0x00000004:    f10d0b08    ....    ADD      r11,sp,#8
        0x00000008:    2404        .$      MOVS     r4,#4
        0x0000000a:    2105        .!      MOVS     r1,#5
        0x0000000c:    2206        ."      MOVS     r2,#6
        0x0000000e:    2307        .#      MOVS     r3,#7
        0x00000010:    1860        '.      ADDS     r0,r4,r1
        0x00000012:    4410        .D      ADD      r0,r0,r2
        0x00000014:    4418        .D      ADD      r0,r0,r3
        0x00000016:    46dd        .F      MOV      sp,r11
        0x00000018:    b082        ..      SUB      sp,sp,#8
        0x0000001a:    e8bd8810    ....    POP      {r4,r11,pc}

If an interrupt occurs between the MOV instruction at address 0x00000016 and the SUB instruction at address 0x00000018, the interrupt stacking can corrupt values that will be loaded to r4 and r11 by the POP instruction at address 0x0000001a. That is because they lie below the address that is in the SP register when the interrupt occurs.

This compiler option cannot be selected with a checkbox in µVision. It must be specified manually in the dialog Options for Target - C/C++ under Misc Controls.

CAUSE

This is an error in the code generation of the Arm compiler version 5.06u6 and below (armcc.exe).

RESOLUTION

It is not recommended to use the option --use_frame_pointer for Cortex-M controller. This option does not provide benefits for execution time or code density. The µVision debugger also does not need this option to display the Call Stack of the application correctly.

STATUS

This was a known problem up to version 5.06u6. Arm compiler 5.06u7 fixes this issue, and you can download this version here. The compiler release notes explain how to integrate this compiler version into MDK. MDK version 5.32 and higher will also contain this compiler version.

MORE INFORMATION

Last Reviewed: Tuesday, February 23, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.