[libcxx-commits] [PATCH] D158655: [libunwind][AIX] Fix problem with stepping up from a leaf function when unwinding started in a signal handler
Hubert Tong via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 24 23:20:35 PDT 2023
hubert.reinterpretcast added inline comments.
================
Comment at: libunwind/src/UnwindCursor.hpp:2324
// lastStack points to the stack frame of the next routine up.
pint_t lastStack = *(reinterpret_cast<pint_t *>(registers.getSP()));
----------------
This only covers the case when `stores_bc` is `1` in the traceback table.
================
Comment at: libunwind/src/UnwindCursor.hpp:2398
+ // sigcontext no longer points to the caller of the leaf function.
+ // However, in this case the compiler will buy a stack frame and save
+ // the original LR value in the link area and therefore, the LR from
----------------
The comment should say nothing about buying a stack frame. The link area is usable by a function for saving the return address even when said function does not increment the SP. As @stephenpeckham pointed out "offline", there can be even be non-leaf functions that do not buy a stack frame (e.g., because the functions they call are known to not write to the stack).
================
Comment at: libunwind/src/UnwindCursor.hpp:2404
+ reinterpret_cast<void *>(returnAddress));
+ } else
+ // Otherwise, use the LR value in the stack link area.
----------------
hubert.reinterpretcast wrote:
> https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements now states that braces should be used for each part of an if/else chain when one part needs braces.
Might be good to explicitly set `returnAddress` to `0` if `lastStack` is `0`. That is, make this `else if (lastStack)`.
================
Comment at: libunwind/src/UnwindCursor.hpp:2404-2406
+ } else
+ // Otherwise, use the LR value in the stack link area.
+ returnAddress = reinterpret_cast<pint_t *>(lastStack)[2];
----------------
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements now states that braces should be used for each part of an if/else chain when one part needs braces.
================
Comment at: libunwind/src/UnwindCursor.hpp:2501-2504
+ // Restore the SP and move one frame up if it is non-leaf function,
+ // or the function is '__start', or LR is not set in the current context.
+ if (TBTable->tb.saves_lr || !lastStack || !sigContextLRValue)
+ newRegisters.setSP(lastStack);
----------------
If `lastStack` truly "points to the stack frame of the next routine up" (as claimed where it is declared), then it is fine to restore the SP even given a leaf function.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158655/new/
https://reviews.llvm.org/D158655
More information about the libcxx-commits
mailing list