Blame SOURCES/gdb-rhbz1125820-ppc64le-enablement-04of37.patch

7ab123
commit 845d47080b7d7e068e4ec3d11fe6e27b403ac6e3
7ab123
Author: Alan Modra <amodra@gmail.com>
7ab123
Date:   Tue Jun 4 02:44:35 2013 +0000
7ab123
7ab123
    	* ppc-tdep.h (ppc_insns_match_pattern): Update prototype.
7ab123
    	* rs6000-tdep.c (read_insn): Add frame param, don't assume big-endian.
7ab123
    	(ppc_insns_match_pattern): Add frame param.  Avoid multiple
7ab123
    	target mem reads on optional insns.
7ab123
    	* ppc-linux-tdep.c (ppc_skip_trampoline_code): Update
7ab123
    	ppc_insns_match_pattern calls.
7ab123
    	* ppc64-tdep.c (ppc64_standard_linkage2, ppc64_standard_linkage3):
7ab123
    	Add match for power7 thread safety insns, and new order of
7ab123
    	std 2,40(1) insn.  Correct code shown for _dl_runtime_resolve
7ab123
    	invocation in comment, and update rest of comment.
7ab123
    	(PPC64_STANDARD_LINKAGE1_LEN, PPC64_STANDARD_LINKAGE2_LEN,
7ab123
    	PPC64_STANDARD_LINKAGE3_LEN): Delete.
7ab123
    	(ppc64_standard_linkage2_target): Update insn offsets.
7ab123
    	(ppc64_skip_trampoline_code): Use a single insn buffer.  Match newer
7ab123
    	stubs first.  Update calls.
7ab123
7ab123
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c
7ab123
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c
7ab123
@@ -360,7 +360,7 @@ ppc_skip_trampoline_code (struct frame_i
7ab123
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
7ab123
   CORE_ADDR target = 0;
7ab123
 
7ab123
-  if (ppc_insns_match_pattern (pc, powerpc32_plt_stub, insnbuf))
7ab123
+  if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
7ab123
     {
7ab123
       /* Insn pattern is
7ab123
 		lis   r11, xxxx
7ab123
@@ -372,7 +372,7 @@ ppc_skip_trampoline_code (struct frame_i
7ab123
       target = read_memory_unsigned_integer (target, 4, byte_order);
7ab123
     }
7ab123
 
7ab123
-  if (ppc_insns_match_pattern (pc, powerpc32_plt_stub_so, insnbuf))
7ab123
+  if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
7ab123
     {
7ab123
       /* Insn pattern is
7ab123
 		lwz   r11, xxxx(r30)
7ab123
Index: gdb-7.6.1/gdb/ppc-tdep.h
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/gdb/ppc-tdep.h
7ab123
+++ gdb-7.6.1/gdb/ppc-tdep.h
7ab123
@@ -300,9 +300,9 @@ struct ppc_insn_pattern
7ab123
   int optional;                 /* If non-zero, this insn may be absent.  */
7ab123
 };
7ab123
 
7ab123
-extern int ppc_insns_match_pattern (CORE_ADDR pc,
7ab123
+extern int ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
7ab123
 				    struct ppc_insn_pattern *pattern,
7ab123
-				    unsigned int *insn);
7ab123
+				    unsigned int *insns);
7ab123
 extern CORE_ADDR ppc_insn_d_field (unsigned int insn);
7ab123
 
7ab123
 extern CORE_ADDR ppc_insn_ds_field (unsigned int insn);
7ab123
Index: gdb-7.6.1/gdb/ppc64-tdep.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/gdb/ppc64-tdep.c
7ab123
+++ gdb-7.6.1/gdb/ppc64-tdep.c
7ab123
@@ -59,9 +59,10 @@ ppc64_desc_entry_point (struct gdbarch *
7ab123
   return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order);
7ab123
 }
7ab123
 
7ab123
-/* Pattern for the standard linkage function.  These are built by
7ab123
-   build_plt_stub in elf64-ppc.c, whose GLINK argument is always
7ab123
-   zero.  */
7ab123
+/* Patterns for the standard linkage functions.  These are built by
7ab123
+   build_plt_stub in bfd/elf64-ppc.c.  */
7ab123
+
7ab123
+/* Old PLT call stub.  */
7ab123
 
7ab123
 static struct ppc_insn_pattern ppc64_standard_linkage1[] =
7ab123
   {
7ab123
@@ -95,15 +96,23 @@ static struct ppc_insn_pattern ppc64_sta
7ab123
     { 0, 0, 0 }
7ab123
   };
7ab123
 
7ab123
-#define PPC64_STANDARD_LINKAGE1_LEN ARRAY_SIZE (ppc64_standard_linkage1)
7ab123
+/* Current PLT call stub to access PLT entries more than +/- 32k from r2.
7ab123
+   Also supports older stub with different placement of std 2,40(1),
7ab123
+   a stub that omits the std 2,40(1), and both versions of power7
7ab123
+   thread safety read barriers.  Note that there are actually two more
7ab123
+   instructions following "cmpldi r2, 0", "bnectr+" and "b <glink_i>",
7ab123
+   but there isn't any need to match them.  */
7ab123
 
7ab123
 static struct ppc_insn_pattern ppc64_standard_linkage2[] =
7ab123
   {
7ab123
+    /* std r2, 40(r1) <optional> */
7ab123
+    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
7ab123
+
7ab123
     /* addis r12, r2, <any> */
7ab123
     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
7ab123
 
7ab123
-    /* std r2, 40(r1) */
7ab123
-    { -1, insn_ds (62, 2, 1, 40, 0), 0 },
7ab123
+    /* std r2, 40(r1) <optional> */
7ab123
+    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
7ab123
 
7ab123
     /* ld r11, <any>(r12) */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
7ab123
@@ -114,24 +123,33 @@ static struct ppc_insn_pattern ppc64_sta
7ab123
     /* mtctr r11 */
7ab123
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
7ab123
 
7ab123
+    /* xor r11, r11, r11 <optional> */
7ab123
+    { -1, 0x7d6b5a78, 1 },
7ab123
+
7ab123
+    /* add r12, r12, r11 <optional> */
7ab123
+    { -1, 0x7d8c5a14, 1 },
7ab123
+
7ab123
     /* ld r2, <any>(r12) */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
7ab123
 
7ab123
     /* ld r11, <any>(r12) <optional> */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
7ab123
 
7ab123
-    /* bctr */
7ab123
-    { -1, 0x4e800420, 0 },
7ab123
+    /* bctr <optional> */
7ab123
+    { -1, 0x4e800420, 1 },
7ab123
+
7ab123
+    /* cmpldi r2, 0 <optional> */
7ab123
+    { -1, 0x28220000, 1 },
7ab123
 
7ab123
     { 0, 0, 0 }
7ab123
   };
7ab123
 
7ab123
-#define PPC64_STANDARD_LINKAGE2_LEN ARRAY_SIZE (ppc64_standard_linkage2)
7ab123
+/* Current PLT call stub to access PLT entries within +/- 32k of r2.  */
7ab123
 
7ab123
 static struct ppc_insn_pattern ppc64_standard_linkage3[] =
7ab123
   {
7ab123
-    /* std r2, 40(r1) */
7ab123
-    { -1, insn_ds (62, 2, 1, 40, 0), 0 },
7ab123
+    /* std r2, 40(r1) <optional> */
7ab123
+    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
7ab123
 
7ab123
     /* ld r11, <any>(r2) */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
7ab123
@@ -142,56 +160,71 @@ static struct ppc_insn_pattern ppc64_sta
7ab123
     /* mtctr r11 */
7ab123
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
7ab123
 
7ab123
+    /* xor r11, r11, r11 <optional> */
7ab123
+    { -1, 0x7d6b5a78, 1 },
7ab123
+
7ab123
+    /* add r2, r2, r11 <optional> */
7ab123
+    { -1, 0x7c425a14, 1 },
7ab123
+
7ab123
     /* ld r11, <any>(r2) <optional> */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },
7ab123
 
7ab123
     /* ld r2, <any>(r2) */
7ab123
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
7ab123
 
7ab123
-    /* bctr */
7ab123
-    { -1, 0x4e800420, 0 },
7ab123
+    /* bctr <optional> */
7ab123
+    { -1, 0x4e800420, 1 },
7ab123
+
7ab123
+    /* cmpldi r2, 0 <optional> */
7ab123
+    { -1, 0x28220000, 1 },
7ab123
 
7ab123
     { 0, 0, 0 }
7ab123
   };
7ab123
 
7ab123
-#define PPC64_STANDARD_LINKAGE3_LEN ARRAY_SIZE (ppc64_standard_linkage3)
7ab123
-
7ab123
 /* When the dynamic linker is doing lazy symbol resolution, the first
7ab123
    call to a function in another object will go like this:
7ab123
 
7ab123
    - The user's function calls the linkage function:
7ab123
 
7ab123
-	 100007c4:	4b ff fc d5		bl	10000498
7ab123
-	 100007c8:	e8 41 00 28		ld	r2,40(r1)
7ab123
+	100003d4:   4b ff ff ad     bl      10000380 <nnnn.plt_call.printf>
7ab123
+	100003d8:   e8 41 00 28     ld      r2,40(r1)
7ab123
 
7ab123
-   - The linkage function loads the entry point (and other stuff) from
7ab123
-	 the function descriptor in the PLT, and jumps to it:
7ab123
+   - The linkage function loads the entry point and toc pointer from
7ab123
+     the function descriptor in the PLT, and jumps to it:
7ab123
 
7ab123
-	 10000498:	3d 82 00 00		addis	r12,r2,0
7ab123
-	 1000049c:	f8 41 00 28		std	r2,40(r1)
7ab123
-	 100004a0:	e9 6c 80 98		ld	r11,-32616(r12)
7ab123
-	 100004a4:	e8 4c 80 a0		ld	r2,-32608(r12)
7ab123
-	 100004a8:	7d 69 03 a6		mtctr	r11
7ab123
-	 100004ac:	e9 6c 80 a8		ld	r11,-32600(r12)
7ab123
-	 100004b0:	4e 80 04 20		bctr
7ab123
+     <nnnn.plt_call.printf>:
7ab123
+	10000380:   f8 41 00 28     std     r2,40(r1)
7ab123
+	10000384:   e9 62 80 78     ld      r11,-32648(r2)
7ab123
+	10000388:   7d 69 03 a6     mtctr   r11
7ab123
+	1000038c:   e8 42 80 80     ld      r2,-32640(r2)
7ab123
+	10000390:   28 22 00 00     cmpldi  r2,0
7ab123
+	10000394:   4c e2 04 20     bnectr+ 
7ab123
+	10000398:   48 00 03 a0     b       10000738 <printf@plt>
7ab123
 
7ab123
    - But since this is the first time that PLT entry has been used, it
7ab123
-	 sends control to its glink entry.  That loads the number of the
7ab123
-	 PLT entry and jumps to the common glink0 code:
7ab123
+     sends control to its glink entry.  That loads the number of the
7ab123
+     PLT entry and jumps to the common glink0 code:
7ab123
 
7ab123
-	 10000c98:	38 00 00 00		li	r0,0
7ab123
-	 10000c9c:	4b ff ff dc		b	10000c78
7ab123
+     <printf@plt>:
7ab123
+	10000738:   38 00 00 01     li      r0,1
7ab123
+	1000073c:   4b ff ff bc     b       100006f8 <__glink_PLTresolve>
7ab123
 
7ab123
    - The common glink0 code then transfers control to the dynamic
7ab123
-	 linker's fixup code:
7ab123
+     linker's fixup code:
7ab123
 
7ab123
-	 10000c78:	e8 41 00 28		ld	r2,40(r1)
7ab123
-	 10000c7c:	3d 82 00 00		addis	r12,r2,0
7ab123
-	 10000c80:	e9 6c 80 80		ld	r11,-32640(r12)
7ab123
-	 10000c84:	e8 4c 80 88		ld	r2,-32632(r12)
7ab123
-	 10000c88:	7d 69 03 a6		mtctr	r11
7ab123
-	 10000c8c:	e9 6c 80 90		ld	r11,-32624(r12)
7ab123
-	 10000c90:	4e 80 04 20		bctr
7ab123
+	100006f0:   0000000000010440 .quad plt0 - (. + 16)
7ab123
+     <__glink_PLTresolve>:
7ab123
+	100006f8:   7d 88 02 a6     mflr    r12
7ab123
+	100006fc:   42 9f 00 05     bcl     20,4*cr7+so,10000700
7ab123
+	10000700:   7d 68 02 a6     mflr    r11
7ab123
+	10000704:   e8 4b ff f0     ld      r2,-16(r11)
7ab123
+	10000708:   7d 88 03 a6     mtlr    r12
7ab123
+	1000070c:   7d 82 5a 14     add     r12,r2,r11
7ab123
+	10000710:   e9 6c 00 00     ld      r11,0(r12)
7ab123
+	10000714:   e8 4c 00 08     ld      r2,8(r12)
7ab123
+	10000718:   7d 69 03 a6     mtctr   r11
7ab123
+	1000071c:   e9 6c 00 10     ld      r11,16(r12)
7ab123
+	10000720:   4e 80 04 20     bctr
7ab123
 
7ab123
    Eventually, this code will figure out how to skip all of this,
7ab123
    including the dynamic linker.  At the moment, we just get through
7ab123
@@ -234,8 +267,8 @@ ppc64_standard_linkage2_target (struct f
7ab123
   CORE_ADDR desc
7ab123
     = ((CORE_ADDR) get_frame_register_unsigned (frame,
7ab123
 						tdep->ppc_gp0_regnum + 2)
7ab123
-       + (ppc_insn_d_field (insn[0]) << 16)
7ab123
-       + ppc_insn_ds_field (insn[2]));
7ab123
+       + (ppc_insn_d_field (insn[1]) << 16)
7ab123
+       + ppc_insn_ds_field (insn[3]));
7ab123
 
7ab123
   /* The first word of the descriptor is the entry point.  Return that.  */
7ab123
   return ppc64_desc_entry_point (gdbarch, desc);
7ab123
@@ -266,23 +299,20 @@ ppc64_standard_linkage3_target (struct f
7ab123
 CORE_ADDR
7ab123
 ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
7ab123
 {
7ab123
-  unsigned int ppc64_standard_linkage1_insn[PPC64_STANDARD_LINKAGE1_LEN];
7ab123
-  unsigned int ppc64_standard_linkage2_insn[PPC64_STANDARD_LINKAGE2_LEN];
7ab123
-  unsigned int ppc64_standard_linkage3_insn[PPC64_STANDARD_LINKAGE3_LEN];
7ab123
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
7ab123
+  unsigned int insns[MAX (MAX (ARRAY_SIZE (ppc64_standard_linkage1),
7ab123
+			       ARRAY_SIZE (ppc64_standard_linkage2)),
7ab123
+			  ARRAY_SIZE (ppc64_standard_linkage3)) - 1];
7ab123
   CORE_ADDR target;
7ab123
 
7ab123
-  if (ppc_insns_match_pattern (pc, ppc64_standard_linkage1,
7ab123
-			       ppc64_standard_linkage1_insn))
7ab123
-    pc = ppc64_standard_linkage1_target (frame, pc,
7ab123
-					 ppc64_standard_linkage1_insn);
7ab123
-  else if (ppc_insns_match_pattern (pc, ppc64_standard_linkage2,
7ab123
-				    ppc64_standard_linkage2_insn))
7ab123
-    pc = ppc64_standard_linkage2_target (frame, pc,
7ab123
-					 ppc64_standard_linkage2_insn);
7ab123
-  else if (ppc_insns_match_pattern (pc, ppc64_standard_linkage3,
7ab123
-				    ppc64_standard_linkage3_insn))
7ab123
-    pc = ppc64_standard_linkage3_target (frame, pc,
7ab123
-					 ppc64_standard_linkage3_insn);
7ab123
+  if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3, insns)
7ab123
+      && (insns[8] != 0 || insns[9] != 0))
7ab123
+    pc = ppc64_standard_linkage3_target (frame, pc, insns);
7ab123
+  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2, insns)
7ab123
+	   && (insns[10] != 0 || insns[11] != 0))
7ab123
+    pc = ppc64_standard_linkage2_target (frame, pc, insns);
7ab123
+  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1, insns))
7ab123
+    pc = ppc64_standard_linkage1_target (frame, pc, insns);
7ab123
   else
7ab123
     return 0;
7ab123
 
7ab123
Index: gdb-7.6.1/gdb/rs6000-tdep.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/gdb/rs6000-tdep.c
7ab123
+++ gdb-7.6.1/gdb/rs6000-tdep.c
7ab123
@@ -4289,14 +4289,15 @@ show_powerpc_exact_watchpoints (struct u
7ab123
   fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value);
7ab123
 }
7ab123
 
7ab123
-/* Read a PPC instruction from memory.  PPC instructions are always
7ab123
-   big-endian, no matter what endianness the program is running in, so
7ab123
-   we can hardcode BFD_ENDIAN_BIG for read_memory_unsigned_integer.  */
7ab123
+/* Read a PPC instruction from memory.  */
7ab123
 
7ab123
 static unsigned int
7ab123
-read_insn (CORE_ADDR pc)
7ab123
+read_insn (struct frame_info *frame, CORE_ADDR pc)
7ab123
 {
7ab123
-  return read_memory_unsigned_integer (pc, 4, BFD_ENDIAN_BIG);
7ab123
+  struct gdbarch *gdbarch = get_frame_arch (frame);
7ab123
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
7ab123
+
7ab123
+  return read_memory_unsigned_integer (pc, 4, byte_order);
7ab123
 }
7ab123
 
7ab123
 /* Return non-zero if the instructions at PC match the series
7ab123
@@ -4313,19 +4314,25 @@ read_insn (CORE_ADDR pc)
7ab123
    i'th instruction in memory.  */
7ab123
 
7ab123
 int
7ab123
-ppc_insns_match_pattern (CORE_ADDR pc, struct ppc_insn_pattern *pattern,
7ab123
-			 unsigned int *insn)
7ab123
+ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
7ab123
+			 struct ppc_insn_pattern *pattern,
7ab123
+			 unsigned int *insns)
7ab123
 {
7ab123
   int i;
7ab123
+  unsigned int insn;
7ab123
 
7ab123
-  for (i = 0; pattern[i].mask; i++)
7ab123
+  for (i = 0, insn = 0; pattern[i].mask; i++)
7ab123
     {
7ab123
-      insn[i] = read_insn (pc);
7ab123
-      if ((insn[i] & pattern[i].mask) == pattern[i].data)
7ab123
-	pc += 4;
7ab123
-      else if (pattern[i].optional)
7ab123
-	insn[i] = 0;
7ab123
-      else
7ab123
+      if (insn == 0)
7ab123
+	insn = read_insn (frame, pc);
7ab123
+      insns[i] = 0;
7ab123
+      if ((insn & pattern[i].mask) == pattern[i].data)
7ab123
+	{
7ab123
+	  insns[i] = insn;
7ab123
+	  pc += 4;
7ab123
+	  insn = 0;
7ab123
+	}
7ab123
+      else if (!pattern[i].optional)
7ab123
 	return 0;
7ab123
     }
7ab123