2013-02-02 04:59:08 +08:00
|
|
|
/* Common target-dependent code for ppc64 GDB, the GNU debugger.
|
|
|
|
|
2019-01-01 14:01:51 +08:00
|
|
|
Copyright (C) 1986-2019 Free Software Foundation, Inc.
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "frame.h"
|
|
|
|
#include "gdbcore.h"
|
2015-01-17 14:30:59 +08:00
|
|
|
#include "infrun.h"
|
2013-02-02 04:59:08 +08:00
|
|
|
#include "ppc-tdep.h"
|
|
|
|
#include "ppc64-tdep.h"
|
2013-02-23 07:24:24 +08:00
|
|
|
#include "elf-bfd.h"
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
/* Macros for matching instructions. Note that, since all the
|
|
|
|
operands are masked off before they're or-ed into the instruction,
|
|
|
|
you can use -1 to make masks. */
|
|
|
|
|
|
|
|
#define insn_d(opcd, rts, ra, d) \
|
2018-08-08 03:13:58 +08:00
|
|
|
((((unsigned (opcd)) & 0x3f) << 26) \
|
|
|
|
| (((unsigned (rts)) & 0x1f) << 21) \
|
|
|
|
| (((unsigned (ra)) & 0x1f) << 16) \
|
|
|
|
| ((unsigned (d)) & 0xffff))
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
#define insn_ds(opcd, rts, ra, d, xo) \
|
2018-08-08 03:13:58 +08:00
|
|
|
((((unsigned (opcd)) & 0x3f) << 26) \
|
|
|
|
| (((unsigned (rts)) & 0x1f) << 21) \
|
|
|
|
| (((unsigned (ra)) & 0x1f) << 16) \
|
|
|
|
| ((unsigned (d)) & 0xfffc) \
|
|
|
|
| ((unsigned (xo)) & 0x3))
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
#define insn_xfx(opcd, rts, spr, xo) \
|
2018-08-08 03:13:58 +08:00
|
|
|
((((unsigned (opcd)) & 0x3f) << 26) \
|
|
|
|
| (((unsigned (rts)) & 0x1f) << 21) \
|
|
|
|
| (((unsigned (spr)) & 0x1f) << 16) \
|
|
|
|
| (((unsigned (spr)) & 0x3e0) << 6) \
|
|
|
|
| (((unsigned (xo)) & 0x3ff) << 1))
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2017-12-11 15:01:11 +08:00
|
|
|
/* PLT_OFF is the TOC-relative offset of a 64-bit PowerPC PLT entry.
|
|
|
|
Return the function's entry point. */
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
static CORE_ADDR
|
2017-12-11 15:01:11 +08:00
|
|
|
ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2017-12-11 15:01:11 +08:00
|
|
|
struct gdbarch *gdbarch = get_frame_arch (frame);
|
2013-02-02 04:59:08 +08:00
|
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
2017-12-11 15:01:11 +08:00
|
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
|
CORE_ADDR tocp;
|
|
|
|
|
|
|
|
if (execution_direction == EXEC_REVERSE)
|
|
|
|
{
|
|
|
|
/* If executing in reverse, r2 will have been stored to the stack. */
|
|
|
|
CORE_ADDR sp = get_frame_register_unsigned (frame,
|
|
|
|
tdep->ppc_gp0_regnum + 1);
|
|
|
|
unsigned int sp_off = tdep->elf_abi == POWERPC_ELF_V1 ? 40 : 24;
|
|
|
|
tocp = read_memory_unsigned_integer (sp + sp_off, 8, byte_order);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tocp = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2);
|
|
|
|
|
2013-11-11 11:44:40 +08:00
|
|
|
/* The first word of the PLT entry is the function entry point. */
|
2017-12-11 15:01:11 +08:00
|
|
|
return read_memory_unsigned_integer (tocp + plt_off, 8, byte_order);
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* Patterns for the standard linkage functions. These are built by
|
|
|
|
build_plt_stub in bfd/elf64-ppc.c. */
|
|
|
|
|
2013-11-11 11:44:40 +08:00
|
|
|
/* Old ELFv1 PLT call stub. */
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage1[] =
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
|
|
|
/* addis r12, r2, <any> */
|
|
|
|
{ insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
|
|
|
|
|
|
|
|
/* std r2, 40(r1) */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 0 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
/* ld r11, <any>(r12) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* addis r12, r12, 1 <optional> */
|
|
|
|
{ insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
|
|
|
|
|
|
|
|
/* ld r2, <any>(r12) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* addis r12, r12, 1 <optional> */
|
|
|
|
{ insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },
|
|
|
|
|
|
|
|
/* mtctr r11 */
|
|
|
|
{ insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
|
|
|
|
|
|
|
|
/* ld r11, <any>(r12) <optional> */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
|
|
|
|
|
|
|
|
/* bctr */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 0 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-11-11 11:44:40 +08:00
|
|
|
/* ELFv1 PLT call stub to access PLT entries more than +/- 32k from r2.
|
2013-06-04 10:44:35 +08:00
|
|
|
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
|
|
|
|
instructions following "cmpldi r2, 0", "bnectr+" and "b <glink_i>",
|
|
|
|
but there isn't any need to match them. */
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage2[] =
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2013-06-04 10:44:35 +08:00
|
|
|
/* std r2, 40(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
2013-02-02 04:59:08 +08:00
|
|
|
/* addis r12, r2, <any> */
|
|
|
|
{ insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* std r2, 40(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
/* ld r11, <any>(r12) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* addi r12, r12, <any> <optional> */
|
|
|
|
{ insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 },
|
|
|
|
|
|
|
|
/* mtctr r11 */
|
|
|
|
{ insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* xor r11, r11, r11 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d6b5a78, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
|
|
|
/* add r12, r12, r11 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d8c5a14, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
2013-02-02 04:59:08 +08:00
|
|
|
/* ld r2, <any>(r12) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* ld r11, <any>(r12) <optional> */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* bctr <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
|
|
|
/* cmpldi r2, 0 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x28220000, 1 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-11-11 11:44:40 +08:00
|
|
|
/* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2. */
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage3[] =
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2013-06-04 10:44:35 +08:00
|
|
|
/* std r2, 40(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
/* ld r11, <any>(r2) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* addi r2, r2, <any> <optional> */
|
|
|
|
{ insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },
|
|
|
|
|
|
|
|
/* mtctr r11 */
|
|
|
|
{ insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* xor r11, r11, r11 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d6b5a78, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
|
|
|
/* add r2, r2, r11 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7c425a14, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
2013-02-02 04:59:08 +08:00
|
|
|
/* 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 },
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
/* bctr <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 1 },
|
2013-06-04 10:44:35 +08:00
|
|
|
|
|
|
|
/* cmpldi r2, 0 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x28220000, 1 },
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-11-11 11:44:40 +08:00
|
|
|
/* 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. */
|
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage4[] =
|
2013-11-11 11:44:40 +08:00
|
|
|
{
|
|
|
|
/* std r2, 40(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d826278, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* add r11, r11, r2 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d6b1214, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* cmpldi r2, 0 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x28220000, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
{ 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. */
|
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage5[] =
|
2013-11-11 11:44:40 +08:00
|
|
|
{
|
|
|
|
/* std r2, 40(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7d8b6278, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* add r2, r2, r11 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x7c425a14, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* cmpldi r2, 0 <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x28220000, 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2. */
|
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage6[] =
|
2013-11-11 11:44:40 +08:00
|
|
|
{
|
|
|
|
/* std r2, 24(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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 */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 0 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ELFv2 PLT call stub to access PLT entries within +/- 32k of r2. */
|
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage7[] =
|
2013-11-11 11:44:40 +08:00
|
|
|
{
|
|
|
|
/* std r2, 24(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
/* 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 */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 0 },
|
2013-11-11 11:44:40 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
Support fusion for ELFv2 stubs
Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld. Thus
addis r12,r2,xxx@ha
addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
addis r11,r2,xxx@ha
addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.
bfd/
* elf64-ppc.c (ADDIS_R12_R2): Define.
(build_plt_stub): Support fusion on ELFv2 stub.
(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
* powerpc.cc (addis_12_2): Define.
(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
gdb/
* ppc64-tdep.c (ppc64_standard_linkage8): New.
(ppc64_skip_trampoline_code): Recognise ELFv2 stub supporting fusion.
2014-06-03 09:25:29 +08:00
|
|
|
/* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2,
|
|
|
|
supporting fusion. */
|
|
|
|
|
2018-01-24 12:52:17 +08:00
|
|
|
static const struct ppc_insn_pattern ppc64_standard_linkage8[] =
|
Support fusion for ELFv2 stubs
Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld. Thus
addis r12,r2,xxx@ha
addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
addis r11,r2,xxx@ha
addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.
bfd/
* elf64-ppc.c (ADDIS_R12_R2): Define.
(build_plt_stub): Support fusion on ELFv2 stub.
(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
* powerpc.cc (addis_12_2): Define.
(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
gdb/
* ppc64-tdep.c (ppc64_standard_linkage8): New.
(ppc64_skip_trampoline_code): Recognise ELFv2 stub supporting fusion.
2014-06-03 09:25:29 +08:00
|
|
|
{
|
|
|
|
/* std r2, 24(r1) <optional> */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
|
Support fusion for ELFv2 stubs
Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld. Thus
addis r12,r2,xxx@ha
addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
addis r11,r2,xxx@ha
addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.
bfd/
* elf64-ppc.c (ADDIS_R12_R2): Define.
(build_plt_stub): Support fusion on ELFv2 stub.
(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
* powerpc.cc (addis_12_2): Define.
(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
gdb/
* ppc64-tdep.c (ppc64_standard_linkage8): New.
(ppc64_skip_trampoline_code): Recognise ELFv2 stub supporting fusion.
2014-06-03 09:25:29 +08:00
|
|
|
|
|
|
|
/* addis r12, r2, <any> */
|
|
|
|
{ insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
|
|
|
|
|
|
|
|
/* ld r12, <any>(r12) */
|
|
|
|
{ insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 12, 0, 0), 0 },
|
|
|
|
|
|
|
|
/* mtctr r12 */
|
|
|
|
{ insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
|
|
|
|
|
|
|
|
/* bctr */
|
2018-08-08 03:13:58 +08:00
|
|
|
{ (unsigned) -1, 0x4e800420, 0 },
|
Support fusion for ELFv2 stubs
Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld. Thus
addis r12,r2,xxx@ha
addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
addis r11,r2,xxx@ha
addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.
bfd/
* elf64-ppc.c (ADDIS_R12_R2): Define.
(build_plt_stub): Support fusion on ELFv2 stub.
(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
* powerpc.cc (addis_12_2): Define.
(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
gdb/
* ppc64-tdep.c (ppc64_standard_linkage8): New.
(ppc64_skip_trampoline_code): Recognise ELFv2 stub supporting fusion.
2014-06-03 09:25:29 +08:00
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-02-02 04:59:08 +08:00
|
|
|
/* When the dynamic linker is doing lazy symbol resolution, the first
|
|
|
|
call to a function in another object will go like this:
|
|
|
|
|
|
|
|
- The user's function calls the linkage function:
|
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
100003d4: 4b ff ff ad bl 10000380 <nnnn.plt_call.printf>
|
|
|
|
100003d8: e8 41 00 28 ld r2,40(r1)
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
- The linkage function loads the entry point and toc pointer from
|
|
|
|
the function descriptor in the PLT, and jumps to it:
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
<nnnn.plt_call.printf>:
|
|
|
|
10000380: f8 41 00 28 std r2,40(r1)
|
|
|
|
10000384: e9 62 80 78 ld r11,-32648(r2)
|
|
|
|
10000388: 7d 69 03 a6 mtctr r11
|
|
|
|
1000038c: e8 42 80 80 ld r2,-32640(r2)
|
|
|
|
10000390: 28 22 00 00 cmpldi r2,0
|
|
|
|
10000394: 4c e2 04 20 bnectr+
|
|
|
|
10000398: 48 00 03 a0 b 10000738 <printf@plt>
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
- But since this is the first time that PLT entry has been used, it
|
2013-06-04 10:44:35 +08:00
|
|
|
sends control to its glink entry. That loads the number of the
|
|
|
|
PLT entry and jumps to the common glink0 code:
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2013-06-04 10:44:35 +08:00
|
|
|
<printf@plt>:
|
|
|
|
10000738: 38 00 00 01 li r0,1
|
|
|
|
1000073c: 4b ff ff bc b 100006f8 <__glink_PLTresolve>
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
- The common glink0 code then transfers control to the dynamic
|
2013-06-04 10:44:35 +08:00
|
|
|
linker's fixup code:
|
|
|
|
|
|
|
|
100006f0: 0000000000010440 .quad plt0 - (. + 16)
|
|
|
|
<__glink_PLTresolve>:
|
|
|
|
100006f8: 7d 88 02 a6 mflr r12
|
|
|
|
100006fc: 42 9f 00 05 bcl 20,4*cr7+so,10000700
|
|
|
|
10000700: 7d 68 02 a6 mflr r11
|
|
|
|
10000704: e8 4b ff f0 ld r2,-16(r11)
|
|
|
|
10000708: 7d 88 03 a6 mtlr r12
|
|
|
|
1000070c: 7d 82 5a 14 add r12,r2,r11
|
|
|
|
10000710: e9 6c 00 00 ld r11,0(r12)
|
|
|
|
10000714: e8 4c 00 08 ld r2,8(r12)
|
|
|
|
10000718: 7d 69 03 a6 mtctr r11
|
|
|
|
1000071c: e9 6c 00 10 ld r11,16(r12)
|
|
|
|
10000720: 4e 80 04 20 bctr
|
2013-02-02 04:59:08 +08:00
|
|
|
|
|
|
|
Eventually, this code will figure out how to skip all of this,
|
|
|
|
including the dynamic linker. At the moment, we just get through
|
|
|
|
the linkage function. */
|
|
|
|
|
|
|
|
/* If the current thread is about to execute a series of instructions
|
2017-12-11 15:01:11 +08:00
|
|
|
matching the ppc64_standard_linkage pattern, and INSN is the result
|
2013-02-02 04:59:08 +08:00
|
|
|
from that pattern match, return the code address to which the
|
|
|
|
standard linkage function will send them. (This doesn't deal with
|
|
|
|
dynamic linker lazy symbol resolution stubs.) */
|
|
|
|
|
|
|
|
static CORE_ADDR
|
2017-12-11 15:01:11 +08:00
|
|
|
ppc64_standard_linkage1_target (struct frame_info *frame, unsigned int *insn)
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2017-12-11 15:01:11 +08:00
|
|
|
CORE_ADDR plt_off = ((ppc_insn_d_field (insn[0]) << 16)
|
|
|
|
+ ppc_insn_ds_field (insn[2]));
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2017-12-11 15:01:11 +08:00
|
|
|
return ppc64_plt_entry_point (frame, plt_off);
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CORE_ADDR
|
2017-12-11 15:01:11 +08:00
|
|
|
ppc64_standard_linkage2_target (struct frame_info *frame, unsigned int *insn)
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2017-12-11 15:01:11 +08:00
|
|
|
CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
|
|
|
|
+ ppc_insn_ds_field (insn[3]));
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2017-12-11 15:01:11 +08:00
|
|
|
return ppc64_plt_entry_point (frame, plt_off);
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CORE_ADDR
|
2017-12-11 15:01:11 +08:00
|
|
|
ppc64_standard_linkage3_target (struct frame_info *frame, unsigned int *insn)
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2017-12-11 15:01:11 +08:00
|
|
|
CORE_ADDR plt_off = ppc_insn_ds_field (insn[1]);
|
2013-02-02 04:59:08 +08:00
|
|
|
|
2017-12-11 15:01:11 +08:00
|
|
|
return ppc64_plt_entry_point (frame, plt_off);
|
2013-11-11 11:44:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CORE_ADDR
|
2017-12-11 15:01:11 +08:00
|
|
|
ppc64_standard_linkage4_target (struct frame_info *frame, unsigned int *insn)
|
2013-11-11 11:44:40 +08:00
|
|
|
{
|
2017-12-11 15:01:11 +08:00
|
|
|
CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
|
|
|
|
+ ppc_insn_ds_field (insn[2]));
|
2013-11-11 11:44:40 +08:00
|
|
|
|
2017-12-11 15:01:11 +08:00
|
|
|
return ppc64_plt_entry_point (frame, plt_off);
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Given that we've begun executing a call trampoline at PC, return
|
Add missing comments in rs6000-tdep.c, ppc64-tdep.c and ppc-linux-tdep.c.
gdb/ChangeLog:
* ppc-linux-tdep.c (ppc_skip_trampoline_code,
ppc_canonicalize_syscall, ppc_linux_syscall_record,
ppc_linux_record_signal, ppc_init_linux_record_tdep): Add comments.
* ppc64-tdep.c (ppc64_skip_trampoline_code): Likewise.
* rs6000-tdep.c (rs6000_epilogue_frame_cache,
rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
rs6000_epilogue_frame_sniffer, ppc_record_vsr, ppc_process_record_op4,
ppc_process_record_op19, ppc_process_record_op31,
ppc_process_record_op59, ppc_process_record_op60,
ppc_process_record_op63): Likewise.
2015-01-19 23:34:07 +08:00
|
|
|
the entry point of the function the trampoline will go to.
|
|
|
|
|
|
|
|
When the execution direction is EXEC_REVERSE, scan backward to
|
|
|
|
check whether we are in the middle of a PLT stub. */
|
2013-02-02 04:59:08 +08:00
|
|
|
|
[ppc64le] Use skip_entrypoint for skip_trampoline_code
ppc64le loses control when stepping between two PLT-called functions inside
a shared library:
29 shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
^M
Program received signal SIGABRT, Aborted.^M
0x00003fffb7cbe578 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56^M
56 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);^M
(gdb) FAIL: gdb.base/solib-intra-step.exp: second-hit
->
29 shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
shlib_second () at ./gdb.base/solib-intra-step-lib.c:23^M
23 abort (); /* second-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: second-hit
This is because gdbarch_skip_trampoline_code() will resolve the final function
as shlib_second+0 and place there the breakpoint, but ld.so will jump after
the breakpoint - at shlib_second+8 - as it is ELFv2 local symbol optimization:
Dump of assembler code for function shlib_second:
0x0000000000000804 <+0>: addis r2,r12,2
0x0000000000000808 <+4>: addi r2,r2,30668
0x000000000000080c <+8>: mflr r0
Currently gdbarch_skip_entrypoint() has been called in skip_prologue_sal() and
fill_in_stop_func() but that is not enough. I believe
gdbarch_skip_entrypoint() should be called after every
gdbarch_skip_trampoline_code().
gdb/ChangeLog
2015-09-15 Jan Kratochvil <jan.kratochvil@redhat.com>
* linespec.c (minsym_found): Call gdbarch_skip_entrypoint.
* ppc64-tdep.c (ppc64_skip_trampoline_code): Rename to ...
(ppc64_skip_trampoline_code_1): ... here.
(ppc64_skip_trampoline_code): New wrapper function.
* symtab.c (find_function_start_sal): Call gdbarch_skip_entrypoint.
gdb/testsuite/ChangeLog
2015-09-15 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.opt/solib-intra-step-lib.c: New file.
* gdb.opt/solib-intra-step-main.c: New file.
* gdb.opt/solib-intra-step.exp: New file.
2015-09-16 01:08:04 +08:00
|
|
|
static CORE_ADDR
|
|
|
|
ppc64_skip_trampoline_code_1 (struct frame_info *frame, CORE_ADDR pc)
|
2013-02-02 04:59:08 +08:00
|
|
|
{
|
2013-06-04 10:44:35 +08:00
|
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
2013-11-11 11:44:40 +08:00
|
|
|
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)),
|
Support fusion for ELFv2 stubs
Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld. Thus
addis r12,r2,xxx@ha
addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
addis r11,r2,xxx@ha
addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.
bfd/
* elf64-ppc.c (ADDIS_R12_R2): Define.
(build_plt_stub): Support fusion on ELFv2 stub.
(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
* powerpc.cc (addis_12_2): Define.
(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
gdb/
* ppc64-tdep.c (ppc64_standard_linkage8): New.
(ppc64_skip_trampoline_code): Recognise ELFv2 stub supporting fusion.
2014-06-03 09:25:29 +08:00
|
|
|
MAX (ARRAY_SIZE (ppc64_standard_linkage7),
|
|
|
|
ARRAY_SIZE (ppc64_standard_linkage8))))
|
|
|
|
- 1];
|
2013-02-02 04:59:08 +08:00
|
|
|
CORE_ADDR target;
|
2015-01-17 14:30:59 +08:00
|
|
|
int scan_limit, i;
|
|
|
|
|
|
|
|
scan_limit = 1;
|
|
|
|
/* When reverse-debugging, scan backward to check whether we are
|
|
|
|
in the middle of trampoline code. */
|
|
|
|
if (execution_direction == EXEC_REVERSE)
|
|
|
|
scan_limit = ARRAY_SIZE (insns) - 1;
|
|
|
|
|
|
|
|
for (i = 0; i < scan_limit; i++)
|
|
|
|
{
|
|
|
|
if (i < ARRAY_SIZE (ppc64_standard_linkage8) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage4_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage7) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7,
|
|
|
|
insns))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage3_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage6) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6,
|
|
|
|
insns))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage4_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage5) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5,
|
|
|
|
insns)
|
|
|
|
&& (insns[8] != 0 || insns[9] != 0))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage3_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage4) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4,
|
|
|
|
insns)
|
|
|
|
&& (insns[9] != 0 || insns[10] != 0))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage4_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage3) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3,
|
|
|
|
insns)
|
|
|
|
&& (insns[8] != 0 || insns[9] != 0))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage3_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage2) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2,
|
|
|
|
insns)
|
|
|
|
&& (insns[10] != 0 || insns[11] != 0))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage2_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else if (i < ARRAY_SIZE (ppc64_standard_linkage1) - 1
|
|
|
|
&& ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1,
|
|
|
|
insns))
|
2017-12-11 15:01:11 +08:00
|
|
|
pc = ppc64_standard_linkage1_target (frame, insns);
|
2015-01-17 14:30:59 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Scan backward one more instructions if doesn't match. */
|
|
|
|
pc -= 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The PLT descriptor will either point to the already resolved target
|
|
|
|
address, or else to a glink stub. As the latter carry synthetic @plt
|
|
|
|
symbols, find_solib_trampoline_target should be able to resolve them. */
|
|
|
|
target = find_solib_trampoline_target (frame, pc);
|
|
|
|
return target ? target : pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
[ppc64le] Use skip_entrypoint for skip_trampoline_code
ppc64le loses control when stepping between two PLT-called functions inside
a shared library:
29 shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
^M
Program received signal SIGABRT, Aborted.^M
0x00003fffb7cbe578 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56^M
56 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);^M
(gdb) FAIL: gdb.base/solib-intra-step.exp: second-hit
->
29 shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
shlib_second () at ./gdb.base/solib-intra-step-lib.c:23^M
23 abort (); /* second-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: second-hit
This is because gdbarch_skip_trampoline_code() will resolve the final function
as shlib_second+0 and place there the breakpoint, but ld.so will jump after
the breakpoint - at shlib_second+8 - as it is ELFv2 local symbol optimization:
Dump of assembler code for function shlib_second:
0x0000000000000804 <+0>: addis r2,r12,2
0x0000000000000808 <+4>: addi r2,r2,30668
0x000000000000080c <+8>: mflr r0
Currently gdbarch_skip_entrypoint() has been called in skip_prologue_sal() and
fill_in_stop_func() but that is not enough. I believe
gdbarch_skip_entrypoint() should be called after every
gdbarch_skip_trampoline_code().
gdb/ChangeLog
2015-09-15 Jan Kratochvil <jan.kratochvil@redhat.com>
* linespec.c (minsym_found): Call gdbarch_skip_entrypoint.
* ppc64-tdep.c (ppc64_skip_trampoline_code): Rename to ...
(ppc64_skip_trampoline_code_1): ... here.
(ppc64_skip_trampoline_code): New wrapper function.
* symtab.c (find_function_start_sal): Call gdbarch_skip_entrypoint.
gdb/testsuite/ChangeLog
2015-09-15 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.opt/solib-intra-step-lib.c: New file.
* gdb.opt/solib-intra-step-main.c: New file.
* gdb.opt/solib-intra-step.exp: New file.
2015-09-16 01:08:04 +08:00
|
|
|
/* Wrapper of ppc64_skip_trampoline_code_1 checking also
|
|
|
|
ppc_elfv2_skip_entrypoint. */
|
|
|
|
|
|
|
|
CORE_ADDR
|
|
|
|
ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
|
|
|
|
{
|
|
|
|
struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
|
|
|
|
|
|
pc = ppc64_skip_trampoline_code_1 (frame, pc);
|
|
|
|
if (pc != 0 && gdbarch_skip_entrypoint_p (gdbarch))
|
|
|
|
pc = gdbarch_skip_entrypoint (gdbarch, pc);
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
2013-02-02 04:59:08 +08:00
|
|
|
/* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
|
|
|
|
GNU/Linux.
|
|
|
|
|
|
|
|
Usually a function pointer's representation is simply the address
|
|
|
|
of the function. On GNU/Linux on the PowerPC however, a function
|
|
|
|
pointer may be a pointer to a function descriptor.
|
|
|
|
|
|
|
|
For PPC64, a function descriptor is a TOC entry, in a data section,
|
|
|
|
which contains three words: the first word is the address of the
|
|
|
|
function, the second word is the TOC pointer (r2), and the third word
|
|
|
|
is the static chain value.
|
|
|
|
|
|
|
|
Throughout GDB it is currently assumed that a function pointer contains
|
|
|
|
the address of the function, which is not easy to fix. In addition, the
|
|
|
|
conversion of a function address to a function pointer would
|
|
|
|
require allocation of a TOC entry in the inferior's memory space,
|
|
|
|
with all its drawbacks. To be able to call C++ virtual methods in
|
|
|
|
the inferior (which are called via function pointers),
|
|
|
|
find_function_addr uses this function to get the function address
|
|
|
|
from a function pointer.
|
|
|
|
|
|
|
|
If ADDR points at what is clearly a function descriptor, transform
|
|
|
|
it into the address of the corresponding function, if needed. Be
|
|
|
|
conservative, otherwise GDB will do the transformation on any
|
|
|
|
random addresses such as occur when there is no symbol table. */
|
|
|
|
|
|
|
|
CORE_ADDR
|
|
|
|
ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
|
|
|
|
CORE_ADDR addr,
|
|
|
|
struct target_ops *targ)
|
|
|
|
{
|
|
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
|
|
struct target_section *s = target_section_by_addr (targ, addr);
|
|
|
|
|
|
|
|
/* Check if ADDR points to a function descriptor. */
|
|
|
|
if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
|
|
|
|
{
|
|
|
|
/* There may be relocations that need to be applied to the .opd
|
|
|
|
section. Unfortunately, this function may be called at a time
|
|
|
|
where these relocations have not yet been performed -- this can
|
|
|
|
happen for example shortly after a library has been loaded with
|
|
|
|
dlopen, but ld.so has not yet applied the relocations.
|
|
|
|
|
|
|
|
To cope with both the case where the relocation has been applied,
|
|
|
|
and the case where it has not yet been applied, we do *not* read
|
|
|
|
the (maybe) relocated value from target memory, but we instead
|
|
|
|
read the non-relocated value from the BFD, and apply the relocation
|
|
|
|
offset manually.
|
|
|
|
|
|
|
|
This makes the assumption that all .opd entries are always relocated
|
|
|
|
by the same offset the section itself was relocated. This should
|
|
|
|
always be the case for GNU/Linux executables and shared libraries.
|
|
|
|
Note that other kind of object files (e.g. those added via
|
|
|
|
add-symbol-files) will currently never end up here anyway, as this
|
|
|
|
function accesses *target* sections only; only the main exec and
|
|
|
|
shared libraries are ever added to the target. */
|
|
|
|
|
|
|
|
gdb_byte buf[8];
|
|
|
|
int res;
|
|
|
|
|
2013-07-17 13:28:04 +08:00
|
|
|
res = bfd_get_section_contents (s->the_bfd_section->owner,
|
|
|
|
s->the_bfd_section,
|
2013-02-02 04:59:08 +08:00
|
|
|
&buf, addr - s->addr, 8);
|
|
|
|
if (res != 0)
|
bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions. The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections. Those sections shouldn't be modified
anyway.
The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma. I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section. This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.
bfd/
* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
(bfd_get_section_lma, bfd_get_section_alignment),
(bfd_get_section_size, bfd_get_section_flags),
(bfd_get_section_userdata): Delete.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
(bfd_section_flags, bfd_section_userdata): New.
(bfd_is_com_section): Rename parameter.
* section.c (bfd_set_section_userdata, bfd_set_section_vma),
(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
(bfd_set_section_size): Delete bfd parameter, rename section parameter.
(bfd_set_section_lma): New.
* bfd-in2.h: Regenerate.
* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
update callers.
* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
* xcofflink.c: Update throughout for bfd section macro and function
changes.
binutils/
* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
throughout for bfd section macro and function changes.
gas/
* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
bfd section macro and function changes.
* write.c (compress_debug): Use bfd_rename_section.
gdb/
* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
* solib-spu.c, * solib-svr4.c, * solib-target.c,
* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
* mi/mi-interp.c: Update throughout for bfd section macro and
function changes.
* gcore (gcore_create_callback): Use bfd_set_section_lma.
* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
* corefile.c, * symtab.c: Update throughout for bfd section
macro and function changes.
ld/
* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
* emultempl/aarch64elf.em, * emultempl/aix.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/cr16elf.em, * emultempl/cskyelf.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
throughout for bfd section macro and function changes.
libctf/
* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
* arc-ext.c: Update throughout for bfd section macro changes.
sim/
* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-16 18:55:17 +08:00
|
|
|
return (extract_unsigned_integer (buf, 8, byte_order)
|
|
|
|
- bfd_section_vma (s->the_bfd_section) + s->addr);
|
2013-02-02 04:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
2013-02-23 07:24:24 +08:00
|
|
|
|
|
|
|
/* A synthetic 'dot' symbols on ppc64 has the udata.p entry pointing
|
|
|
|
back to the original ELF symbol it was derived from. Get the size
|
|
|
|
from that symbol. */
|
|
|
|
|
|
|
|
void
|
|
|
|
ppc64_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
|
|
|
|
{
|
|
|
|
if ((sym->flags & BSF_SYNTHETIC) != 0 && sym->udata.p != NULL)
|
|
|
|
{
|
|
|
|
elf_symbol_type *elf_sym = (elf_symbol_type *) sym->udata.p;
|
|
|
|
SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size);
|
|
|
|
}
|
|
|
|
}
|