aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2013-11-11 14:14:40 +1030
committerAlan Modra <amodra@gmail.com>2013-11-15 10:32:06 +1030
commitef1bc9e72fd2f0310ac3113acc41e1c115e3ac79 (patch)
tree305ca622a59672db9f1bf12d59eda6b5dca974da
parent993a449f1714480593eb0a2a6bd6e21d8f029168 (diff)
downloadfsf-binutils-gdb-ef1bc9e72fd2f0310ac3113acc41e1c115e3ac79.zip
fsf-binutils-gdb-ef1bc9e72fd2f0310ac3113acc41e1c115e3ac79.tar.gz
fsf-binutils-gdb-ef1bc9e72fd2f0310ac3113acc41e1c115e3ac79.tar.bz2
PowerPC64 ELFv2 trampoline match
ELFv2 needs different plt call stubs to ELFv1, register usage differs too. When I added these to ld I changed register usage in the ELFv1 stubs as well, simplifying the linker code and (perhaps) future maintenance. All well and good, but this means gdb needs to cope with more stub variants. This patch also handles skipping over addis/addi setting up r2 in ELFv2 global entry code. We want breakpoints to be set past this point to catch calls via the local entry point. * ppc64-tdep.c (ppc64_plt_entry_point): Renamed from.. (ppc64_desc_entry_point): ..this. Update comments here and at call points. (ppc64_standard_linkage1, ppc64_standard_linkage2, ppc64_standard_linkage3): Update comments. (ppc64_standard_linkage4, ppc64_standard_linkage5, (ppc64_standard_linkage6, ppc64_standard_linkage7): New insn patterns. (ppc64_standard_linkage4_target): New function. (ppc64_skip_trampoline_code): Skip ELFv2 patterns too. * rs6000-tdep.c (skip_prologue): Skip ELFv2 r2 setup. Correct nop match. Fix comment wrap.
-rw-r--r--gdb/ChangeLog25
-rw-r--r--gdb/ppc64-tdep.c201
-rw-r--r--gdb/rs6000-tdep.c20
3 files changed, 208 insertions, 38 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index de15879..5ff75fe 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,18 @@
+2013-11-15 Alan Modra <amodra@gmail.com>
+
+ * ppc64-tdep.c (ppc64_plt_entry_point): Renamed from..
+ (ppc64_desc_entry_point): ..this. Update comments here and at
+ call points.
+ (ppc64_standard_linkage1, ppc64_standard_linkage2,
+ ppc64_standard_linkage3): Update comments.
+ (ppc64_standard_linkage4, ppc64_standard_linkage5,
+ (ppc64_standard_linkage6, ppc64_standard_linkage7): New insn
+ patterns.
+ (ppc64_standard_linkage4_target): New function.
+ (ppc64_skip_trampoline_code): Skip ELFv2 patterns too.
+ * rs6000-tdep.c (skip_prologue): Skip ELFv2 r2 setup. Correct
+ nop match. Fix comment wrap.
+
2013-11-14 Pedro Alves <palves@redhat.com>
* infrun.c (handle_signal_stop): Move STOP_QUIETLY,
@@ -314,8 +329,8 @@
2013-11-07 Phil Muldoon <pmuldoon@redhat.com>
- PR python/15747
- * python/py-cmd.c: Add COMPLETE_EXPRESSION constant.
+ PR python/15747
+ * python/py-cmd.c: Add COMPLETE_EXPRESSION constant.
2013-11-07 Phil Muldoon <pmuldoon@redhat.com>
@@ -1227,7 +1242,7 @@
(discard_pending_stop_replies): Return early if notif_state is
NULL. Adjust. Don't check INF is NULL.
(remote_notif_get_pending_events): Adjust.
- (discard_pending_stop_replies_in_queue): New function.
+ (discard_pending_stop_replies_in_queue): New function.
(remote_wait_ns): Likewise.
2013-10-04 Yao Qi <yao@codesourcery.com>
@@ -2400,8 +2415,8 @@
Pedro Alves <palves@redhat.com>
* symfile.c (add_symbol_file_command): Error out on unknown
- option. Handle EXPECTING_SEC_ADDR/EXPECTING_SEC_NAME before '-'
- options and collapse into single conditional branch.
+ option. Handle EXPECTING_SEC_ADDR/EXPECTING_SEC_NAME before '-'
+ options and collapse into single conditional branch.
2013-09-03 Luis Machado <lgustavo@codesourcery.com>
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index a2098fe..174ab7c 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -48,21 +48,21 @@
| (((spr) & 0x3e0) << 6) \
| (((xo) & 0x3ff) << 1))
-/* If DESC is the address of a 64-bit PowerPC FreeBSD function
- descriptor, return the descriptor's entry point. */
+/* If PLT is the address of a 64-bit PowerPC PLT entry,
+ return the function's entry point. */
static CORE_ADDR
-ppc64_desc_entry_point (struct gdbarch *gdbarch, CORE_ADDR desc)
+ppc64_plt_entry_point (struct gdbarch *gdbarch, CORE_ADDR plt)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- /* The first word of the descriptor is the entry point. */
- return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order);
+ /* The first word of the PLT entry is the function entry point. */
+ return (CORE_ADDR) read_memory_unsigned_integer (plt, 8, byte_order);
}
/* Patterns for the standard linkage functions. These are built by
build_plt_stub in bfd/elf64-ppc.c. */
-/* Old PLT call stub. */
+/* Old ELFv1 PLT call stub. */
static struct ppc_insn_pattern ppc64_standard_linkage1[] =
{
@@ -96,7 +96,7 @@ static struct ppc_insn_pattern ppc64_standard_linkage1[] =
{ 0, 0, 0 }
};
-/* Current PLT call stub to access PLT entries more than +/- 32k from r2.
+/* ELFv1 PLT call stub to access PLT entries more than +/- 32k from r2.
Also supports older stub with different placement of std 2,40(1),
a stub that omits the std 2,40(1), and both versions of power7
thread safety read barriers. Note that there are actually two more
@@ -144,7 +144,7 @@ static struct ppc_insn_pattern ppc64_standard_linkage2[] =
{ 0, 0, 0 }
};
-/* Current PLT call stub to access PLT entries within +/- 32k of r2. */
+/* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2. */
static struct ppc_insn_pattern ppc64_standard_linkage3[] =
{
@@ -181,6 +181,128 @@ static struct ppc_insn_pattern ppc64_standard_linkage3[] =
{ 0, 0, 0 }
};
+/* ELFv1 PLT call stub to access PLT entries more than +/- 32k from r2.
+ A more modern variant of ppc64_standard_linkage2 differing in
+ register usage. */
+
+static struct ppc_insn_pattern ppc64_standard_linkage4[] =
+ {
+ /* std r2, 40(r1) <optional> */
+ { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+
+ /* addis r11, r2, <any> */
+ { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },
+
+ /* ld r12, <any>(r11) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 11, 0, 0), 0 },
+
+ /* addi r11, r11, <any> <optional> */
+ { insn_d (-1, -1, -1, 0), insn_d (14, 11, 11, 0), 1 },
+
+ /* mtctr r12 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
+
+ /* xor r2, r12, r12 <optional> */
+ { -1, 0x7d826278, 1 },
+
+ /* add r11, r11, r2 <optional> */
+ { -1, 0x7d6b1214, 1 },
+
+ /* ld r2, <any>(r11) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 11, 0, 0), 0 },
+
+ /* ld r11, <any>(r11) <optional> */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 11, 0, 0), 1 },
+
+ /* bctr <optional> */
+ { -1, 0x4e800420, 1 },
+
+ /* cmpldi r2, 0 <optional> */
+ { -1, 0x28220000, 1 },
+
+ { 0, 0, 0 }
+ };
+
+/* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2.
+ A more modern variant of ppc64_standard_linkage3 differing in
+ register usage. */
+
+static struct ppc_insn_pattern ppc64_standard_linkage5[] =
+ {
+ /* std r2, 40(r1) <optional> */
+ { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+
+ /* ld r12, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },
+
+ /* addi r2, r2, <any> <optional> */
+ { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },
+
+ /* mtctr r12 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
+
+ /* xor r11, r12, r12 <optional> */
+ { -1, 0x7d8b6278, 1 },
+
+ /* add r2, r2, r11 <optional> */
+ { -1, 0x7c425a14, 1 },
+
+ /* ld r11, <any>(r2) <optional> */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },
+
+ /* ld r2, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
+
+ /* bctr <optional> */
+ { -1, 0x4e800420, 1 },
+
+ /* cmpldi r2, 0 <optional> */
+ { -1, 0x28220000, 1 },
+
+ { 0, 0, 0 }
+ };
+
+/* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2. */
+
+static struct ppc_insn_pattern ppc64_standard_linkage6[] =
+ {
+ /* std r2, 24(r1) <optional> */
+ { -1, insn_ds (62, 2, 1, 24, 0), 1 },
+
+ /* addis r11, r2, <any> */
+ { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },
+
+ /* ld r12, <any>(r11) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 11, 0, 0), 0 },
+
+ /* mtctr r12 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
+
+ /* bctr */
+ { -1, 0x4e800420, 0 },
+
+ { 0, 0, 0 }
+ };
+
+/* ELFv2 PLT call stub to access PLT entries within +/- 32k of r2. */
+
+static struct ppc_insn_pattern ppc64_standard_linkage7[] =
+ {
+ /* std r2, 24(r1) <optional> */
+ { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+
+ /* ld r12, <any>(r2) */
+ { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },
+
+ /* mtctr r12 */
+ { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
+
+ /* bctr */
+ { -1, 0x4e800420, 0 },
+
+ { 0, 0, 0 }
+ };
+
/* When the dynamic linker is doing lazy symbol resolution, the first
call to a function in another object will go like this:
@@ -243,16 +365,14 @@ ppc64_standard_linkage1_target (struct frame_info *frame,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
- /* The address of the function descriptor this linkage function
- references. */
- CORE_ADDR desc
+ /* The address of the PLT entry this linkage function references. */
+ CORE_ADDR plt
= ((CORE_ADDR) get_frame_register_unsigned (frame,
tdep->ppc_gp0_regnum + 2)
+ (ppc_insn_d_field (insn[0]) << 16)
+ ppc_insn_ds_field (insn[2]));
- /* The first word of the descriptor is the entry point. Return that. */
- return ppc64_desc_entry_point (gdbarch, desc);
+ return ppc64_plt_entry_point (gdbarch, plt);
}
static CORE_ADDR
@@ -262,16 +382,14 @@ ppc64_standard_linkage2_target (struct frame_info *frame,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
- /* The address of the function descriptor this linkage function
- references. */
- CORE_ADDR desc
+ /* The address of the PLT entry this linkage function references. */
+ CORE_ADDR plt
= ((CORE_ADDR) get_frame_register_unsigned (frame,
tdep->ppc_gp0_regnum + 2)
+ (ppc_insn_d_field (insn[1]) << 16)
+ ppc_insn_ds_field (insn[3]));
- /* The first word of the descriptor is the entry point. Return that. */
- return ppc64_desc_entry_point (gdbarch, desc);
+ return ppc64_plt_entry_point (gdbarch, plt);
}
static CORE_ADDR
@@ -281,15 +399,28 @@ ppc64_standard_linkage3_target (struct frame_info *frame,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
- /* The address of the function descriptor this linkage function
- references. */
- CORE_ADDR desc
+ /* The address of the PLT entry this linkage function references. */
+ CORE_ADDR plt
= ((CORE_ADDR) get_frame_register_unsigned (frame,
tdep->ppc_gp0_regnum + 2)
+ ppc_insn_ds_field (insn[1]));
- /* The first word of the descriptor is the entry point. Return that. */
- return ppc64_desc_entry_point (gdbarch, desc);
+ return ppc64_plt_entry_point (gdbarch, plt);
+}
+
+static CORE_ADDR
+ppc64_standard_linkage4_target (struct frame_info *frame,
+ CORE_ADDR pc, unsigned int *insn)
+{
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ CORE_ADDR plt
+ = ((CORE_ADDR) get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2)
+ + (ppc_insn_d_field (insn[1]) << 16)
+ + ppc_insn_ds_field (insn[2]));
+
+ return ppc64_plt_entry_point (gdbarch, plt);
}
@@ -300,13 +431,27 @@ CORE_ADDR
ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
{
#define MAX(a,b) ((a) > (b) ? (a) : (b))
- unsigned int insns[MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage1),
- ARRAY_SIZE (ppc64_standard_linkage2)),
- ARRAY_SIZE (ppc64_standard_linkage3)) - 1];
+ unsigned int insns[MAX (MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage1),
+ ARRAY_SIZE (ppc64_standard_linkage2)),
+ MAX (ARRAY_SIZE (ppc64_standard_linkage3),
+ ARRAY_SIZE (ppc64_standard_linkage4))),
+ MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage5),
+ ARRAY_SIZE (ppc64_standard_linkage6)),
+ ARRAY_SIZE (ppc64_standard_linkage7))) - 1];
CORE_ADDR target;
- if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3, insns)
- && (insns[8] != 0 || insns[9] != 0))
+ if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7, insns))
+ pc = ppc64_standard_linkage3_target (frame, pc, insns);
+ else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6, insns))
+ pc = ppc64_standard_linkage4_target (frame, pc, insns);
+ else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5, insns)
+ && (insns[8] != 0 || insns[9] != 0))
+ pc = ppc64_standard_linkage3_target (frame, pc, insns);
+ else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4, insns)
+ && (insns[9] != 0 || insns[10] != 0))
+ pc = ppc64_standard_linkage4_target (frame, pc, insns);
+ else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3, insns)
+ && (insns[8] != 0 || insns[9] != 0))
pc = ppc64_standard_linkage3_target (frame, pc, insns);
else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2, insns)
&& (insns[10] != 0 || insns[11] != 0))
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index c561bc8..477e29e 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -1616,7 +1616,19 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
continue;
}
- else if ((op & 0xffff0000) == 0x60000000)
+ else if ((op & 0xffff0000) == 0x3c4c0000
+ || (op & 0xffff0000) == 0x3c400000
+ || (op & 0xffff0000) == 0x38420000)
+ {
+ /* . 0: addis 2,12,.TOC.-0b@ha
+ . addi 2,2,.TOC.-0b@l
+ or
+ . lis 2,.TOC.@ha
+ . addi 2,2,.TOC.@l
+ used by ELFv2 global entry points to set up r2. */
+ continue;
+ }
+ else if (op == 0x60000000)
{
/* nop */
/* Allow nops in the prologue, but do not consider them to
@@ -1627,8 +1639,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
}
else if ((op & 0xffff0000) == 0x3c000000)
- { /* addis 0,0,NUM, used
- for >= 32k frames */
+ { /* addis 0,0,NUM, used for >= 32k frames */
fdata->offset = (op & 0x0000ffff) << 16;
fdata->frameless = 0;
r0_contains_arg = 0;
@@ -1636,8 +1647,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
}
else if ((op & 0xffff0000) == 0x60000000)
- { /* ori 0,0,NUM, 2nd ha
- lf of >= 32k frames */
+ { /* ori 0,0,NUM, 2nd half of >= 32k frames */
fdata->offset |= (op & 0x0000ffff);
fdata->frameless = 0;
r0_contains_arg = 0;