[PATCH] D125649: [ARM SEH 7] [WIP] [ARM] Adjust the frame pointer when it's needed for SEH unwinding
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 15 14:40:12 PDT 2022
mstorsjo created this revision.
mstorsjo added reviewers: efriedma, rnk, zzheng.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: LLVM.
For functions that require restoring SP from FP (e.g. that need to
align the stack, or that have variable sized allocations), the prologue
and epilogue previously used to look like this:
push {r4-r5, r11, lr}
add r11, sp, #8
...
sub r4, r11, #8
mov sp, r4
pop {r4-r5, r11, pc}
This is problematic, because this unwinding operation (restoring sp
from r11 + offset) can't be expressed with the SEH unwind opcodes
(probably because this unwind procedure doesn't map exactly to
individual instructions; note the detour via r4 in the epilogue too).
To make unwinding work, the frame lowering is adjusted to store
r11 pointing at the bottom of the GPR save area instead, like this:
push {r4-r5, r11, lr}
mov r11, sp
...
mov sp, r11
pop {r4-r5, r11, pc}
This does break FP chaining (for fast stack walking) though, as r11
doesn't point at a {r11,lr} pair any longer.
For the same setup, MSVC generates code that uses two registers;
r11 still pointing at the {r11,lr} pair, but a separate register
used for restoring the stack at the end:
push {r4-r5, r7, r11, lr}
add r11, sp, #12
mov r7, sp
...
mov sp, r7
pop {r4-r5, r7, r11, pc}
This seems wasteful, to use two registers for essentially the same
purpose, but probably is the only way to retain unwind both via
fast stack walking and via the SEH opcodes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125649
Files:
llvm/lib/Target/ARM/ARMFrameLowering.cpp
llvm/test/CodeGen/ARM/Windows/wineh-framepointer.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125649.429567.patch
Type: text/x-patch
Size: 5296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220515/2f4ec877/attachment.bin>
More information about the llvm-commits
mailing list