This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Restore stack ptr from frame ptr with setjmp
ClosedPublic

Authored by nemanjai on Dec 8 2020, 7:42 PM.

Details

Summary

If a function happens to:

  • call setjmp
  • do a 16-byte stack allocation
  • call a function that sets up a stack frame and longjmp's back

The stack pointer that is restores by setjmp will no longer point to a valid back chain. According to the ABI, stack accesses in such a function are to be frame pointer based - so it is an error (quite obviously) to restore the stack from the back chain.
We already restore the stack from the frame pointer when there are calls to fast_cc functions. We just need to also do that when there are calls to setjmp. This patch simply does that.

This was pointed out by the Julia team.

Diff Detail

Event Timeline

nemanjai created this revision.Dec 8 2020, 7:42 PM
nemanjai requested review of this revision.Dec 8 2020, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2020, 7:42 PM
vchuravy added a subscriber: Restricted Project.Dec 9 2020, 5:00 AM
vchuravy accepted this revision.Dec 9 2020, 10:35 AM

Looks good from the Julia side, this does indeed fix the upstream bug. Thanks @nemanjai!

This revision is now accepted and ready to land.Dec 9 2020, 10:35 AM
This revision was landed with ongoing or failed builds.Dec 14 2020, 9:35 AM
This revision was automatically updated to reflect the committed changes.

This fixed a whole set of bugs for us but it also seems to have caused a regression.
https://github.com/JuliaLang/julia/issues/38859

The details are in the upstream issue with a pure llvm IR reproducer. I could reproduce on ToT and reverting this PR made me unable to reproduce it.
The reproducer is a bit flaky and needs to be run several times.