[libunwind] Allow restoring SP while unwinding.
authorMarco Vanotti <mvanotti@google.com>
Fri, 23 Jul 2021 00:58:23 +0000 (17:58 -0700)
committerMarco Vanotti <mvanotti@google.com>
Fri, 23 Jul 2021 19:39:49 +0000 (12:39 -0700)
commita085c23aa3c8f91866d7f4588d4f683407dc775d
tree06af73e2ba438c4681d32d6b2da899c56f480b65
parentaee8457b8d4123d087c45aef95d14f24934fed53
[libunwind] Allow restoring SP while unwinding.

This commit modifies stepWithDwarf allowing for CFI directives to
specify the value of the stack pointer.

Previously, the SP would be unconditionally set to the CFA, because it
(wrongly) stated that the CFA is the stack pointer at the call site of a
function, but that is not always true.

One situation in which that is false, is for example if you have
switched stacks. In that case if you set the CFA to the SP before
switching the stack, the CFA would be far away from where the current
call frame is located.

The CFA always points to the current call frame, and that call frame
could have a CFI directive that specifies how to restore the stack
pointer. If not, it is OK to fallback and set the SP = CFA.

This change sets SP = CFA before restoring the registers during
unwinding, allowing the stack frame to be restored with a value
different than the CFA.

Reviewed By: #libunwind, phosek

Differential Revision: https://reviews.llvm.org/D106626
libunwind/src/DwarfInstructions.hpp