|
|
8f6b9e |
commit db9077b7275e86637218a7a7d165cb85a4de116f
|
|
|
8f6b9e |
Author: Alan Modra <amodra@gmail.com>
|
|
|
8f6b9e |
Date: Mon Dec 11 17:31:11 2017 +1030
|
|
|
8f6b9e |
|
|
|
8f6b9e |
PR22576, ppc64_skip_trampoline_code uses wrong r2 for EXEC_REVERSE
|
|
|
8f6b9e |
|
|
|
8f6b9e |
The TOC pointer register, r2, on powerpc64 is generally not mentioned
|
|
|
8f6b9e |
in debug info. It is saved and restored by call linkage code, and
|
|
|
8f6b9e |
set to the callee value either by call stub code (ELFv1) or in the
|
|
|
8f6b9e |
callee global entry point code (ELFv2). A call stub uses the caller
|
|
|
8f6b9e |
TOC pointer to access the PLT. So for gdb to read the correct PLT
|
|
|
8f6b9e |
entry in order to determine the destination of the trampoline, gdb
|
|
|
8f6b9e |
needs to know the caller r2. When skipping over trampolines in the
|
|
|
8f6b9e |
normal forward direction, the caller r2 is simply the current value of
|
|
|
8f6b9e |
r2 (at the start of the trampoline). However, when reversing over
|
|
|
8f6b9e |
trampolines the current value of r2 is that for the callee. Using
|
|
|
8f6b9e |
that value results in wild reads of memory rather than the correct PLT
|
|
|
8f6b9e |
entry.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
This patch corrects the value of r2 by using the value saved on the
|
|
|
8f6b9e |
stack for reverse execution. Note that in reverse execution mode it
|
|
|
8f6b9e |
isn't really necessary for skip_trampoline_code to return the actual
|
|
|
8f6b9e |
destination, so we're doing a little more work than needed here. Any
|
|
|
8f6b9e |
non-zero return value would do (and it would be nicer if the interface
|
|
|
8f6b9e |
was changed to return the start of the stub).
|
|
|
8f6b9e |
|
|
|
8f6b9e |
PR tdep/22576
|
|
|
8f6b9e |
* ppc64-tdep.c (ppc64_plt_entry_point): Rewrite to take TOC-relative
|
|
|
8f6b9e |
PLT offset, and retrieve r2 from stack when executing in reverse.
|
|
|
8f6b9e |
(ppc64_standard_linkage1_target): Drop pc param. Calculate offset
|
|
|
8f6b9e |
rather than PLT address.
|
|
|
8f6b9e |
(ppc64_standard_linkage2_target): Likewise.
|
|
|
8f6b9e |
(ppc64_standard_linkage3_target): Likewise.
|
|
|
8f6b9e |
(ppc64_standard_linkage4_target): Likewise.
|
|
|
8f6b9e |
(ppc64_skip_trampoline_code_1): Adjust to suit.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
### a/gdb/ChangeLog
|
|
|
8f6b9e |
### b/gdb/ChangeLog
|
|
|
8f6b9e |
## -1,3 +1,15 @@
|
|
|
8f6b9e |
+2017-12-12 Alan Modra <amodra@gmail.com>
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ PR tdep/22576
|
|
|
8f6b9e |
+ * ppc64-tdep.c (ppc64_plt_entry_point): Rewrite to take TOC-relative
|
|
|
8f6b9e |
+ PLT offset, and retrieve r2 from stack when executing in reverse.
|
|
|
8f6b9e |
+ (ppc64_standard_linkage1_target): Drop pc param. Calculate offset
|
|
|
8f6b9e |
+ rather than PLT address.
|
|
|
8f6b9e |
+ (ppc64_standard_linkage2_target): Likewise.
|
|
|
8f6b9e |
+ (ppc64_standard_linkage3_target): Likewise.
|
|
|
8f6b9e |
+ (ppc64_standard_linkage4_target): Likewise.
|
|
|
8f6b9e |
+ (ppc64_skip_trampoline_code_1): Adjust to suit.
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
2017-12-11 Simon Marchi <simon.marchi@ericsson.com>
|
|
|
8f6b9e |
|
|
|
8f6b9e |
PR gdb/22556
|
|
|
8f6b9e |
--- a/gdb/ppc64-tdep.c
|
|
|
8f6b9e |
+++ b/gdb/ppc64-tdep.c
|
|
|
8f6b9e |
@@ -49,15 +49,30 @@
|
|
|
8f6b9e |
| (((spr) & 0x3e0) << 6) \
|
|
|
8f6b9e |
| (((xo) & 0x3ff) << 1))
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-/* If PLT is the address of a 64-bit PowerPC PLT entry,
|
|
|
8f6b9e |
- return the function's entry point. */
|
|
|
8f6b9e |
+/* PLT_OFF is the TOC-relative offset of a 64-bit PowerPC PLT entry.
|
|
|
8f6b9e |
+ Return the function's entry point. */
|
|
|
8f6b9e |
|
|
|
8f6b9e |
static CORE_ADDR
|
|
|
8f6b9e |
-ppc64_plt_entry_point (struct gdbarch *gdbarch, CORE_ADDR plt)
|
|
|
8f6b9e |
+ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
+ struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
8f6b9e |
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
|
8f6b9e |
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
8f6b9e |
+ CORE_ADDR tocp;
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ if (execution_direction == EXEC_REVERSE)
|
|
|
8f6b9e |
+ {
|
|
|
8f6b9e |
+ /* If executing in reverse, r2 will have been stored to the stack. */
|
|
|
8f6b9e |
+ CORE_ADDR sp = get_frame_register_unsigned (frame,
|
|
|
8f6b9e |
+ tdep->ppc_gp0_regnum + 1);
|
|
|
8f6b9e |
+ unsigned int sp_off = tdep->elf_abi == POWERPC_ELF_V1 ? 40 : 24;
|
|
|
8f6b9e |
+ tocp = read_memory_unsigned_integer (sp + sp_off, 8, byte_order);
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+ else
|
|
|
8f6b9e |
+ tocp = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2);
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
/* The first word of the PLT entry is the function entry point. */
|
|
|
8f6b9e |
- return (CORE_ADDR) read_memory_unsigned_integer (plt, 8, byte_order);
|
|
|
8f6b9e |
+ return read_memory_unsigned_integer (tocp + plt_off, 8, byte_order);
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
/* Patterns for the standard linkage functions. These are built by
|
|
|
8f6b9e |
@@ -377,74 +392,44 @@ static struct ppc_insn_pattern ppc64_standard_linkage8[] =
|
|
|
8f6b9e |
the linkage function. */
|
|
|
8f6b9e |
|
|
|
8f6b9e |
/* If the current thread is about to execute a series of instructions
|
|
|
8f6b9e |
- at PC matching the ppc64_standard_linkage pattern, and INSN is the result
|
|
|
8f6b9e |
+ matching the ppc64_standard_linkage pattern, and INSN is the result
|
|
|
8f6b9e |
from that pattern match, return the code address to which the
|
|
|
8f6b9e |
standard linkage function will send them. (This doesn't deal with
|
|
|
8f6b9e |
dynamic linker lazy symbol resolution stubs.) */
|
|
|
8f6b9e |
|
|
|
8f6b9e |
static CORE_ADDR
|
|
|
8f6b9e |
-ppc64_standard_linkage1_target (struct frame_info *frame,
|
|
|
8f6b9e |
- CORE_ADDR pc, unsigned int *insn)
|
|
|
8f6b9e |
+ppc64_standard_linkage1_target (struct frame_info *frame, unsigned int *insn)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
- struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
8f6b9e |
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
- /* The address of the PLT entry this linkage function references. */
|
|
|
8f6b9e |
- CORE_ADDR plt
|
|
|
8f6b9e |
- = ((CORE_ADDR) get_frame_register_unsigned (frame,
|
|
|
8f6b9e |
- tdep->ppc_gp0_regnum + 2)
|
|
|
8f6b9e |
- + (ppc_insn_d_field (insn[0]) << 16)
|
|
|
8f6b9e |
- + ppc_insn_ds_field (insn[2]));
|
|
|
8f6b9e |
+ CORE_ADDR plt_off = ((ppc_insn_d_field (insn[0]) << 16)
|
|
|
8f6b9e |
+ + ppc_insn_ds_field (insn[2]));
|
|
|
8f6b9e |
|
|
|
8f6b9e |
- return ppc64_plt_entry_point (gdbarch, plt);
|
|
|
8f6b9e |
+ return ppc64_plt_entry_point (frame, plt_off);
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
static CORE_ADDR
|
|
|
8f6b9e |
-ppc64_standard_linkage2_target (struct frame_info *frame,
|
|
|
8f6b9e |
- CORE_ADDR pc, unsigned int *insn)
|
|
|
8f6b9e |
+ppc64_standard_linkage2_target (struct frame_info *frame, unsigned int *insn)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
- struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
8f6b9e |
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
- /* The address of the PLT entry this linkage function references. */
|
|
|
8f6b9e |
- CORE_ADDR plt
|
|
|
8f6b9e |
- = ((CORE_ADDR) get_frame_register_unsigned (frame,
|
|
|
8f6b9e |
- tdep->ppc_gp0_regnum + 2)
|
|
|
8f6b9e |
- + (ppc_insn_d_field (insn[1]) << 16)
|
|
|
8f6b9e |
- + ppc_insn_ds_field (insn[3]));
|
|
|
8f6b9e |
+ CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
|
|
|
8f6b9e |
+ + ppc_insn_ds_field (insn[3]));
|
|
|
8f6b9e |
|
|
|
8f6b9e |
- return ppc64_plt_entry_point (gdbarch, plt);
|
|
|
8f6b9e |
+ return ppc64_plt_entry_point (frame, plt_off);
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
static CORE_ADDR
|
|
|
8f6b9e |
-ppc64_standard_linkage3_target (struct frame_info *frame,
|
|
|
8f6b9e |
- CORE_ADDR pc, unsigned int *insn)
|
|
|
8f6b9e |
+ppc64_standard_linkage3_target (struct frame_info *frame, unsigned int *insn)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
- struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
8f6b9e |
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
8f6b9e |
+ CORE_ADDR plt_off = ppc_insn_ds_field (insn[1]);
|
|
|
8f6b9e |
|
|
|
8f6b9e |
- /* The address of the PLT entry this linkage function references. */
|
|
|
8f6b9e |
- CORE_ADDR plt
|
|
|
8f6b9e |
- = ((CORE_ADDR) get_frame_register_unsigned (frame,
|
|
|
8f6b9e |
- tdep->ppc_gp0_regnum + 2)
|
|
|
8f6b9e |
- + ppc_insn_ds_field (insn[1]));
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
- return ppc64_plt_entry_point (gdbarch, plt);
|
|
|
8f6b9e |
+ return ppc64_plt_entry_point (frame, plt_off);
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
static CORE_ADDR
|
|
|
8f6b9e |
-ppc64_standard_linkage4_target (struct frame_info *frame,
|
|
|
8f6b9e |
- CORE_ADDR pc, unsigned int *insn)
|
|
|
8f6b9e |
+ppc64_standard_linkage4_target (struct frame_info *frame, unsigned int *insn)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
- struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
8f6b9e |
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
- CORE_ADDR plt
|
|
|
8f6b9e |
- = ((CORE_ADDR) get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2)
|
|
|
8f6b9e |
- + (ppc_insn_d_field (insn[1]) << 16)
|
|
|
8f6b9e |
- + ppc_insn_ds_field (insn[2]));
|
|
|
8f6b9e |
+ CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
|
|
|
8f6b9e |
+ + ppc_insn_ds_field (insn[2]));
|
|
|
8f6b9e |
|
|
|
8f6b9e |
- return ppc64_plt_entry_point (gdbarch, plt);
|
|
|
8f6b9e |
+ return ppc64_plt_entry_point (frame, plt_off);
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
|
|
|
8f6b9e |
@@ -480,39 +465,39 @@ ppc64_skip_trampoline_code_1 (struct frame_info *frame, CORE_ADDR pc)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
if (i < ARRAY_SIZE (ppc64_standard_linkage8) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage4_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage4_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage7) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7,
|
|
|
8f6b9e |
insns))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage3_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage3_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage6) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6,
|
|
|
8f6b9e |
insns))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage4_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage4_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage5) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5,
|
|
|
8f6b9e |
insns)
|
|
|
8f6b9e |
&& (insns[8] != 0 || insns[9] != 0))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage3_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage3_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage4) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4,
|
|
|
8f6b9e |
insns)
|
|
|
8f6b9e |
&& (insns[9] != 0 || insns[10] != 0))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage4_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage4_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage3) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3,
|
|
|
8f6b9e |
insns)
|
|
|
8f6b9e |
&& (insns[8] != 0 || insns[9] != 0))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage3_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage3_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage2) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2,
|
|
|
8f6b9e |
insns)
|
|
|
8f6b9e |
&& (insns[10] != 0 || insns[11] != 0))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage2_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage2_target (frame, insns);
|
|
|
8f6b9e |
else if (i < ARRAY_SIZE (ppc64_standard_linkage1) - 1
|
|
|
8f6b9e |
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1,
|
|
|
8f6b9e |
insns))
|
|
|
8f6b9e |
- pc = ppc64_standard_linkage1_target (frame, pc, insns);
|
|
|
8f6b9e |
+ pc = ppc64_standard_linkage1_target (frame, insns);
|
|
|
8f6b9e |
else
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
/* Scan backward one more instructions if doesn't match. */
|