Incorrect epilogue code in __attribute__((cmse_nonsecure_entry)) function

Asked by CCLi

Pertinent bug report info:

- GCC version: 9-2020-q2
- CPU: Arm Cortex-M23
- Optimization level: Os


Checking the following non-secure callable (NSC) function with Os,

int __attribute__((cmse_nonsecure_entry))
foo(int a)
    return a + 1;

Compiled assembly code:

0x000004E8 3001 ADDS r0,#1
0x000004EA 0001 MOVS r1,r0
0x000004EC 0002 MOVS r2,r0
0x000004EE 0003 MOVS r3,r0
0x000004F0 4680 MOV r8,r0
0x000004F2 4681 MOV r9,r0
0x000004F4 4682 MOV r10,r0
0x000004F6 4683 MOV r11,r0
0x000004F8 4684 MOV r12,r0
0x000004FA F38E8800 MSR APSR_nzcvq,lr ; formerly CPSR_f
0x000004FE 4774 BXNS lr

According to Arm's "ARMv8-M Security Extensions: Requirements on Development Tools", on return from an entry function, restore all callee-saved registers (here r8~r12) as mandated by [AAPCS], rather than clear them.

Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Last query:
Last reply:

Can you help with this problem?

Provide an answer of your own, or ask CCLi for more information if necessary.

To post a message you must log in.