[PATCH] D93327: [PowerPC] Restore stack ptr from base ptr when available

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 11:48:14 PST 2020


nemanjai created this revision.
nemanjai added reviewers: PowerPC, hfinkel.
Herald added subscribers: shchenz, kbarton, hiraditya.
nemanjai requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added a subscriber: Sanitizers.

On subtargets that have a red zone, we will copy the stack pointer to the base pointer in the prologue prior to updating the stack pointer. As far as I can tell, there are no other updates to the base pointer after that. This suggests that we should be able to restore the stack pointer from the base pointer rather than loading it from the back chain or adding the frame size back to either the stack pointer or the frame pointer.
This came about because functions that call `setjmp` need to restore the SP from the FP because the back chain might have been clobbered (see https://reviews.llvm.org/D92906). However, if the stack is realigned, the restored SP might be incorrect (which is what caused the failures in the two ASan test cases).
With this patch, there are no failures on any code I have tried nor do I see a problem with using the BP since it is a callee-saved register that does not get updated in the function.

@hfinkel I am really hoping that you can comment on the viability of this patch since you're more familiar with the concept of the base pointer. I haven't really been able to track down much in the way of documentation for it and it is not mentioned in the ABI so it seems to be specific to LLVM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93327

Files:
  compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp
  compiler-rt/test/asan/TestCases/longjmp.cpp
  llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
  llvm/test/CodeGen/PowerPC/aix-base-pointer.ll
  llvm/test/CodeGen/PowerPC/pr46759.ll
  llvm/test/CodeGen/PowerPC/stack-clash-prologue.ll
  llvm/test/CodeGen/PowerPC/stack-realign.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93327.311977.patch
Type: text/x-patch
Size: 6009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201215/c0ccf2c3/attachment.bin>


More information about the llvm-commits mailing list