https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77933
Bug ID: 77933 Summary: Stack corruption on ARM when using high registers and __builtin_return_address Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: thopre01 at gcc dot gnu.org Target Milestone: --- Target: arm-none-eabi When compiling the following testcase with -march=armv6-m -mthumb -O1: void* foo() { asm volatile("" : : : "r8", "r9"); return __builtin_return_address(0); } GCC produces the following assembler: mov r3, r9 push {r3, lr} mov r3, r8 push {r3, lr} mov r0, lr pop {r2, r3} mov r8, r2 mov r9, r3 pop {pc} Note how 4 words are pushed on the stack but only 3 are popped, hence the stack gets corrupted