PR22576, ppc64_skip_trampoline_code uses wrong r2 for EXEC_REVERSE
The TOC pointer register, r2, on powerpc64 is generally not mentioned
in debug info. It is saved and restored by call linkage code, and
set to the callee value either by call stub code (ELFv1) or in the
callee global entry point code (ELFv2). A call stub uses the caller
TOC pointer to access the PLT. So for gdb to read the correct PLT
entry in order to determine the destination of the trampoline, gdb
needs to know the caller r2. When skipping over trampolines in the
normal forward direction, the caller r2 is simply the current value of
r2 (at the start of the trampoline). However, when reversing over
trampolines the current value of r2 is that for the callee. Using
that value results in wild reads of memory rather than the correct PLT
entry.
This patch corrects the value of r2 by using the value saved on the
stack for reverse execution. Note that in reverse execution mode it
isn't really necessary for skip_trampoline_code to return the actual
destination, so we're doing a little more work than needed here. Any
non-zero return value would do (and it would be nicer if the interface
was changed to return the start of the stub).
PR tdep/22576
* ppc64-tdep.c (ppc64_plt_entry_point): Rewrite to take TOC-relative
PLT offset, and retrieve r2 from stack when executing in reverse.
(ppc64_standard_linkage1_target): Drop pc param. Calculate offset
rather than PLT address.
(ppc64_standard_linkage2_target): Likewise.
(ppc64_standard_linkage3_target): Likewise.
(ppc64_standard_linkage4_target): Likewise.
(ppc64_skip_trampoline_code_1): Adjust to suit.