This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Restore stack ptr from base ptr when available
ClosedPublic

Authored by nemanjai on Dec 15 2020, 11:48 AM.

Details

Summary

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.

Diff Detail

Event Timeline

nemanjai created this revision.Dec 15 2020, 11:48 AM
nemanjai requested review of this revision.Dec 15 2020, 11:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 15 2020, 11:48 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
saugustine accepted this revision.Dec 21 2020, 11:41 AM
saugustine added a subscriber: saugustine.

This patch does fix several problems we noticed at Google that were created by the previous patch. I'm not qualified to judge the technical approach, without this, asan is completely broken on powerpc, so that speaks strongly in its favor.

This revision is now accepted and ready to land.Dec 21 2020, 11:41 AM
This revision was landed with ongoing or failed builds.Dec 22 2020, 3:44 AM
This revision was automatically updated to reflect the committed changes.