gdb/ppc64-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Common target-dependent code for ppc64 GDB, the GNU debugger.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "gdbcore.h"
  17. #include "ppc-tdep.h"
  18. #include "ppc64-tdep.h"
  19. #include "elf-bfd.h"

  20. /* Macros for matching instructions.  Note that, since all the
  21.    operands are masked off before they're or-ed into the instruction,
  22.    you can use -1 to make masks.  */

  23. #define insn_d(opcd, rts, ra, d)                \
  24.   ((((opcd) & 0x3f) << 26)                      \
  25.    | (((rts) & 0x1f) << 21)                     \
  26.    | (((ra) & 0x1f) << 16)                      \
  27.    | ((d) & 0xffff))

  28. #define insn_ds(opcd, rts, ra, d, xo)           \
  29.   ((((opcd) & 0x3f) << 26)                      \
  30.    | (((rts) & 0x1f) << 21)                     \
  31.    | (((ra) & 0x1f) << 16)                      \
  32.    | ((d) & 0xfffc)                             \
  33.    | ((xo) & 0x3))

  34. #define insn_xfx(opcd, rts, spr, xo)            \
  35.   ((((opcd) & 0x3f) << 26)                      \
  36.    | (((rts) & 0x1f) << 21)                     \
  37.    | (((spr) & 0x1f) << 16)                     \
  38.    | (((spr) & 0x3e0) << 6)                     \
  39.    | (((xo) & 0x3ff) << 1))

  40. /* If PLT is the address of a 64-bit PowerPC PLT entry,
  41.    return the function's entry point.  */

  42. static CORE_ADDR
  43. ppc64_plt_entry_point (struct gdbarch *gdbarch, CORE_ADDR plt)
  44. {
  45.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  46.   /* The first word of the PLT entry is the function entry point.  */
  47.   return (CORE_ADDR) read_memory_unsigned_integer (plt, 8, byte_order);
  48. }

  49. /* Patterns for the standard linkage functions.  These are built by
  50.    build_plt_stub in bfd/elf64-ppc.c.  */

  51. /* Old ELFv1 PLT call stub.  */

  52. static struct ppc_insn_pattern ppc64_standard_linkage1[] =
  53.   {
  54.     /* addis r12, r2, <any> */
  55.     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },

  56.     /* std r2, 40(r1) */
  57.     { -1, insn_ds (62, 2, 1, 40, 0), 0 },

  58.     /* ld r11, <any>(r12) */
  59.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },

  60.     /* addis r12, r12, 1 <optional> */
  61.     { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },

  62.     /* ld r2, <any>(r12) */
  63.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },

  64.     /* addis r12, r12, 1 <optional> */
  65.     { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 },

  66.     /* mtctr r11 */
  67.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },

  68.     /* ld r11, <any>(r12) <optional> */
  69.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },

  70.     /* bctr */
  71.     { -1, 0x4e800420, 0 },

  72.     { 0, 0, 0 }
  73.   };

  74. /* ELFv1 PLT call stub to access PLT entries more than +/- 32k from r2.
  75.    Also supports older stub with different placement of std 2,40(1),
  76.    a stub that omits the std 2,40(1), and both versions of power7
  77.    thread safety read barriers.  Note that there are actually two more
  78.    instructions following "cmpldi r2, 0", "bnectr+" and "b <glink_i>",
  79.    but there isn't any need to match them.  */

  80. static struct ppc_insn_pattern ppc64_standard_linkage2[] =
  81.   {
  82.     /* std r2, 40(r1) <optional> */
  83.     { -1, insn_ds (62, 2, 1, 40, 0), 1 },

  84.     /* addis r12, r2, <any> */
  85.     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },

  86.     /* std r2, 40(r1) <optional> */
  87.     { -1, insn_ds (62, 2, 1, 40, 0), 1 },

  88.     /* ld r11, <any>(r12) */
  89.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },

  90.     /* addi r12, r12, <any> <optional> */
  91.     { insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 },

  92.     /* mtctr r11 */
  93.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },

  94.     /* xor r11, r11, r11 <optional> */
  95.     { -1, 0x7d6b5a78, 1 },

  96.     /* add r12, r12, r11 <optional> */
  97.     { -1, 0x7d8c5a14, 1 },

  98.     /* ld r2, <any>(r12) */
  99.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },

  100.     /* ld r11, <any>(r12) <optional> */
  101.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },

  102.     /* bctr <optional> */
  103.     { -1, 0x4e800420, 1 },

  104.     /* cmpldi r2, 0 <optional> */
  105.     { -1, 0x28220000, 1 },

  106.     { 0, 0, 0 }
  107.   };

  108. /* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2.  */

  109. static struct ppc_insn_pattern ppc64_standard_linkage3[] =
  110.   {
  111.     /* std r2, 40(r1) <optional> */
  112.     { -1, insn_ds (62, 2, 1, 40, 0), 1 },

  113.     /* ld r11, <any>(r2) */
  114.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },

  115.     /* addi r2, r2, <any> <optional> */
  116.     { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },

  117.     /* mtctr r11 */
  118.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },

  119.     /* xor r11, r11, r11 <optional> */
  120.     { -1, 0x7d6b5a78, 1 },

  121.     /* add r2, r2, r11 <optional> */
  122.     { -1, 0x7c425a14, 1 },

  123.     /* ld r11, <any>(r2) <optional> */
  124.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },

  125.     /* ld r2, <any>(r2) */
  126.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },

  127.     /* bctr <optional> */
  128.     { -1, 0x4e800420, 1 },

  129.     /* cmpldi r2, 0 <optional> */
  130.     { -1, 0x28220000, 1 },

  131.     { 0, 0, 0 }
  132.   };

  133. /* ELFv1 PLT call stub to access PLT entries more than +/- 32k from r2.
  134.    A more modern variant of ppc64_standard_linkage2 differing in
  135.    register usage.  */

  136. static struct ppc_insn_pattern ppc64_standard_linkage4[] =
  137.   {
  138.     /* std r2, 40(r1) <optional> */
  139.     { -1, insn_ds (62, 2, 1, 40, 0), 1 },

  140.     /* addis r11, r2, <any> */
  141.     { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },

  142.     /* ld r12, <any>(r11) */
  143.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 11, 0, 0), 0 },

  144.     /* addi r11, r11, <any> <optional> */
  145.     { insn_d (-1, -1, -1, 0), insn_d (14, 11, 11, 0), 1 },

  146.     /* mtctr r12 */
  147.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },

  148.     /* xor r2, r12, r12 <optional> */
  149.     { -1, 0x7d826278, 1 },

  150.     /* add r11, r11, r2 <optional> */
  151.     { -1, 0x7d6b1214, 1 },

  152.     /* ld r2, <any>(r11) */
  153.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 11, 0, 0), 0 },

  154.     /* ld r11, <any>(r11) <optional> */
  155.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 11, 0, 0), 1 },

  156.     /* bctr <optional> */
  157.     { -1, 0x4e800420, 1 },

  158.     /* cmpldi r2, 0 <optional> */
  159.     { -1, 0x28220000, 1 },

  160.     { 0, 0, 0 }
  161.   };

  162. /* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2.
  163.    A more modern variant of ppc64_standard_linkage3 differing in
  164.    register usage.  */

  165. static struct ppc_insn_pattern ppc64_standard_linkage5[] =
  166.   {
  167.     /* std r2, 40(r1) <optional> */
  168.     { -1, insn_ds (62, 2, 1, 40, 0), 1 },

  169.     /* ld r12, <any>(r2) */
  170.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },

  171.     /* addi r2, r2, <any> <optional> */
  172.     { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 },

  173.     /* mtctr r12 */
  174.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },

  175.     /* xor r11, r12, r12 <optional> */
  176.     { -1, 0x7d8b6278, 1 },

  177.     /* add r2, r2, r11 <optional> */
  178.     { -1, 0x7c425a14, 1 },

  179.     /* ld r11, <any>(r2) <optional> */
  180.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },

  181.     /* ld r2, <any>(r2) */
  182.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },

  183.     /* bctr <optional> */
  184.     { -1, 0x4e800420, 1 },

  185.     /* cmpldi r2, 0 <optional> */
  186.     { -1, 0x28220000, 1 },

  187.     { 0, 0, 0 }
  188.   };

  189. /* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2.  */

  190. static struct ppc_insn_pattern ppc64_standard_linkage6[] =
  191.   {
  192.     /* std r2, 24(r1) <optional> */
  193.     { -1, insn_ds (62, 2, 1, 24, 0), 1 },

  194.     /* addis r11, r2, <any> */
  195.     { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },

  196.     /* ld r12, <any>(r11) */
  197.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 11, 0, 0), 0 },

  198.     /* mtctr r12 */
  199.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },

  200.     /* bctr */
  201.     { -1, 0x4e800420, 0 },

  202.     { 0, 0, 0 }
  203.   };

  204. /* ELFv2 PLT call stub to access PLT entries within +/- 32k of r2.  */

  205. static struct ppc_insn_pattern ppc64_standard_linkage7[] =
  206.   {
  207.     /* std r2, 24(r1) <optional> */
  208.     { -1, insn_ds (62, 2, 1, 24, 0), 1 },

  209.     /* ld r12, <any>(r2) */
  210.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },

  211.     /* mtctr r12 */
  212.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },

  213.     /* bctr */
  214.     { -1, 0x4e800420, 0 },

  215.     { 0, 0, 0 }
  216.   };

  217. /* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2,
  218.    supporting fusion.  */

  219. static struct ppc_insn_pattern ppc64_standard_linkage8[] =
  220.   {
  221.     /* std r2, 24(r1) <optional> */
  222.     { -1, insn_ds (62, 2, 1, 24, 0), 1 },

  223.     /* addis r12, r2, <any> */
  224.     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },

  225.     /* ld r12, <any>(r12) */
  226.     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 12, 0, 0), 0 },

  227.     /* mtctr r12 */
  228.     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },

  229.     /* bctr */
  230.     { -1, 0x4e800420, 0 },

  231.     { 0, 0, 0 }
  232.   };

  233. /* When the dynamic linker is doing lazy symbol resolution, the first
  234.    call to a function in another object will go like this:

  235.    - The user's function calls the linkage function:

  236.         100003d4:   4b ff ff ad     bl      10000380 <nnnn.plt_call.printf>
  237.         100003d8:   e8 41 00 28     ld      r2,40(r1)

  238.    - The linkage function loads the entry point and toc pointer from
  239.      the function descriptor in the PLT, and jumps to it:

  240.      <nnnn.plt_call.printf>:
  241.         10000380:   f8 41 00 28     std     r2,40(r1)
  242.         10000384:   e9 62 80 78     ld      r11,-32648(r2)
  243.         10000388:   7d 69 03 a6     mtctr   r11
  244.         1000038c:   e8 42 80 80     ld      r2,-32640(r2)
  245.         10000390:   28 22 00 00     cmpldi  r2,0
  246.         10000394:   4c e2 04 20     bnectr+
  247.         10000398:   48 00 03 a0     b       10000738 <printf@plt>

  248.    - But since this is the first time that PLT entry has been used, it
  249.      sends control to its glink entry.  That loads the number of the
  250.      PLT entry and jumps to the common glink0 code:

  251.      <printf@plt>:
  252.         10000738:   38 00 00 01     li      r0,1
  253.         1000073c:   4b ff ff bc     b       100006f8 <__glink_PLTresolve>

  254.    - The common glink0 code then transfers control to the dynamic
  255.      linker's fixup code:

  256.         100006f0:   0000000000010440 .quad plt0 - (. + 16)
  257.      <__glink_PLTresolve>:
  258.         100006f8:   7d 88 02 a6     mflr    r12
  259.         100006fc:   42 9f 00 05     bcl     20,4*cr7+so,10000700
  260.         10000700:   7d 68 02 a6     mflr    r11
  261.         10000704:   e8 4b ff f0     ld      r2,-16(r11)
  262.         10000708:   7d 88 03 a6     mtlr    r12
  263.         1000070c:   7d 82 5a 14     add     r12,r2,r11
  264.         10000710:   e9 6c 00 00     ld      r11,0(r12)
  265.         10000714:   e8 4c 00 08     ld      r2,8(r12)
  266.         10000718:   7d 69 03 a6     mtctr   r11
  267.         1000071c:   e9 6c 00 10     ld      r11,16(r12)
  268.         10000720:   4e 80 04 20     bctr

  269.    Eventually, this code will figure out how to skip all of this,
  270.    including the dynamic linker.  At the moment, we just get through
  271.    the linkage function.  */

  272. /* If the current thread is about to execute a series of instructions
  273.    at PC matching the ppc64_standard_linkage pattern, and INSN is the result
  274.    from that pattern match, return the code address to which the
  275.    standard linkage function will send them.  (This doesn't deal with
  276.    dynamic linker lazy symbol resolution stubs.)  */

  277. static CORE_ADDR
  278. ppc64_standard_linkage1_target (struct frame_info *frame,
  279.                                 CORE_ADDR pc, unsigned int *insn)
  280. {
  281.   struct gdbarch *gdbarch = get_frame_arch (frame);
  282.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  283.   /* The address of the PLT entry this linkage function references.  */
  284.   CORE_ADDR plt
  285.     = ((CORE_ADDR) get_frame_register_unsigned (frame,
  286.                                                 tdep->ppc_gp0_regnum + 2)
  287.        + (ppc_insn_d_field (insn[0]) << 16)
  288.        + ppc_insn_ds_field (insn[2]));

  289.   return ppc64_plt_entry_point (gdbarch, plt);
  290. }

  291. static CORE_ADDR
  292. ppc64_standard_linkage2_target (struct frame_info *frame,
  293.                                 CORE_ADDR pc, unsigned int *insn)
  294. {
  295.   struct gdbarch *gdbarch = get_frame_arch (frame);
  296.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  297.   /* The address of the PLT entry this linkage function references.  */
  298.   CORE_ADDR plt
  299.     = ((CORE_ADDR) get_frame_register_unsigned (frame,
  300.                                                 tdep->ppc_gp0_regnum + 2)
  301.        + (ppc_insn_d_field (insn[1]) << 16)
  302.        + ppc_insn_ds_field (insn[3]));

  303.   return ppc64_plt_entry_point (gdbarch, plt);
  304. }

  305. static CORE_ADDR
  306. ppc64_standard_linkage3_target (struct frame_info *frame,
  307.                                 CORE_ADDR pc, unsigned int *insn)
  308. {
  309.   struct gdbarch *gdbarch = get_frame_arch (frame);
  310.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  311.   /* The address of the PLT entry this linkage function references.  */
  312.   CORE_ADDR plt
  313.     = ((CORE_ADDR) get_frame_register_unsigned (frame,
  314.                                                 tdep->ppc_gp0_regnum + 2)
  315.        + ppc_insn_ds_field (insn[1]));

  316.   return ppc64_plt_entry_point (gdbarch, plt);
  317. }

  318. static CORE_ADDR
  319. ppc64_standard_linkage4_target (struct frame_info *frame,
  320.                                 CORE_ADDR pc, unsigned int *insn)
  321. {
  322.   struct gdbarch *gdbarch = get_frame_arch (frame);
  323.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  324.   CORE_ADDR plt
  325.     = ((CORE_ADDR) get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2)
  326.        + (ppc_insn_d_field (insn[1]) << 16)
  327.        + ppc_insn_ds_field (insn[2]));

  328.   return ppc64_plt_entry_point (gdbarch, plt);
  329. }


  330. /* Given that we've begun executing a call trampoline at PC, return
  331.    the entry point of the function the trampoline will go to.  */

  332. CORE_ADDR
  333. ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  334. {
  335. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  336.   unsigned int insns[MAX (MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage1),
  337.                                     ARRAY_SIZE (ppc64_standard_linkage2)),
  338.                                MAX (ARRAY_SIZE (ppc64_standard_linkage3),
  339.                                     ARRAY_SIZE (ppc64_standard_linkage4))),
  340.                           MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage5),
  341.                                     ARRAY_SIZE (ppc64_standard_linkage6)),
  342.                                MAX (ARRAY_SIZE (ppc64_standard_linkage7),
  343.                                     ARRAY_SIZE (ppc64_standard_linkage8))))
  344.                      - 1];
  345.   CORE_ADDR target;

  346.   if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
  347.     pc = ppc64_standard_linkage4_target (frame, pc, insns);
  348.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7, insns))
  349.     pc = ppc64_standard_linkage3_target (frame, pc, insns);
  350.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6, insns))
  351.     pc = ppc64_standard_linkage4_target (frame, pc, insns);
  352.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5, insns)
  353.            && (insns[8] != 0 || insns[9] != 0))
  354.     pc = ppc64_standard_linkage3_target (frame, pc, insns);
  355.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4, insns)
  356.            && (insns[9] != 0 || insns[10] != 0))
  357.     pc = ppc64_standard_linkage4_target (frame, pc, insns);
  358.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3, insns)
  359.            && (insns[8] != 0 || insns[9] != 0))
  360.     pc = ppc64_standard_linkage3_target (frame, pc, insns);
  361.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2, insns)
  362.            && (insns[10] != 0 || insns[11] != 0))
  363.     pc = ppc64_standard_linkage2_target (frame, pc, insns);
  364.   else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1, insns))
  365.     pc = ppc64_standard_linkage1_target (frame, pc, insns);
  366.   else
  367.     return 0;

  368.   /* The PLT descriptor will either point to the already resolved target
  369.      address, or else to a glink stub.  As the latter carry synthetic @plt
  370.      symbols, find_solib_trampoline_target should be able to resolve them.  */
  371.   target = find_solib_trampoline_target (frame, pc);
  372.   return target ? target : pc;
  373. }

  374. /* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
  375.    GNU/Linux.

  376.    Usually a function pointer's representation is simply the address
  377.    of the function.  On GNU/Linux on the PowerPC however, a function
  378.    pointer may be a pointer to a function descriptor.

  379.    For PPC64, a function descriptor is a TOC entry, in a data section,
  380.    which contains three words: the first word is the address of the
  381.    function, the second word is the TOC pointer (r2), and the third word
  382.    is the static chain value.

  383.    Throughout GDB it is currently assumed that a function pointer contains
  384.    the address of the function, which is not easy to fix.  In addition, the
  385.    conversion of a function address to a function pointer would
  386.    require allocation of a TOC entry in the inferior's memory space,
  387.    with all its drawbacks.  To be able to call C++ virtual methods in
  388.    the inferior (which are called via function pointers),
  389.    find_function_addr uses this function to get the function address
  390.    from a function pointer.

  391.    If ADDR points at what is clearly a function descriptor, transform
  392.    it into the address of the corresponding function, if needed.  Be
  393.    conservative, otherwise GDB will do the transformation on any
  394.    random addresses such as occur when there is no symbol table.  */

  395. CORE_ADDR
  396. ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
  397.                                         CORE_ADDR addr,
  398.                                         struct target_ops *targ)
  399. {
  400.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  401.   struct target_section *s = target_section_by_addr (targ, addr);

  402.   /* Check if ADDR points to a function descriptor.  */
  403.   if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
  404.     {
  405.       /* There may be relocations that need to be applied to the .opd
  406.          section.  Unfortunately, this function may be called at a time
  407.          where these relocations have not yet been performed -- this can
  408.          happen for example shortly after a library has been loaded with
  409.          dlopen, but ld.so has not yet applied the relocations.

  410.          To cope with both the case where the relocation has been applied,
  411.          and the case where it has not yet been applied, we do *not* read
  412.          the (maybe) relocated value from target memory, but we instead
  413.          read the non-relocated value from the BFD, and apply the relocation
  414.          offset manually.

  415.          This makes the assumption that all .opd entries are always relocated
  416.          by the same offset the section itself was relocated.  This should
  417.          always be the case for GNU/Linux executables and shared libraries.
  418.          Note that other kind of object files (e.g. those added via
  419.          add-symbol-files) will currently never end up here anyway, as this
  420.          function accesses *target* sections only; only the main exec and
  421.          shared libraries are ever added to the target.  */

  422.       gdb_byte buf[8];
  423.       int res;

  424.       res = bfd_get_section_contents (s->the_bfd_section->owner,
  425.                                       s->the_bfd_section,
  426.                                       &buf, addr - s->addr, 8);
  427.       if (res != 0)
  428.         return extract_unsigned_integer (buf, 8, byte_order)
  429.                 - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr;
  430.    }

  431.   return addr;
  432. }

  433. /* A synthetic 'dot' symbols on ppc64 has the udata.p entry pointing
  434.    back to the original ELF symbol it was derived from.  Get the size
  435.    from that symbol.  */

  436. void
  437. ppc64_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
  438. {
  439.   if ((sym->flags & BSF_SYNTHETIC) != 0 && sym->udata.p != NULL)
  440.     {
  441.       elf_symbol_type *elf_sym = (elf_symbol_type *) sym->udata.p;
  442.       SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size);
  443.     }
  444. }