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

7ab123
commit a078d95abc554b6c2572fcab5550591639b1c871
7ab123
Author: Alan Modra <amodra@gmail.com>
7ab123
Date:   Tue Oct 29 16:17:22 2013 +1030
7ab123
7ab123
    Support ELFv2 stack frame.
7ab123
    
7ab123
    The toc pointer save slot changes on ELFv2 from 40(1) to 24(1).
7ab123
    
7ab123
    	* elf64-ppc.c (STK_LR, STK_TOC, STK_LINKER): Define.
7ab123
    	(savegpr0_tail, restgpr0_tail, savefpr0_tail, restfpr0_tail)
7ab123
    	build_plt_stub, build_tls_get_addr_stub, ppc_build_one_stub,
7ab123
    	ppc64_elf_relocate_section): Use new defines.
7ab123
7ab123
Index: gdb-7.6.1/bfd/elf64-ppc.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/bfd/elf64-ppc.c
7ab123
+++ gdb-7.6.1/bfd/elf64-ppc.c
7ab123
@@ -130,6 +130,14 @@ static bfd_vma opd_entry_value
7ab123
 /* The initial size of the plt reserved for the dynamic linker.  */
7ab123
 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
7ab123
 
7ab123
+/* Offsets to some stack save slots.  */
7ab123
+#define STK_LR 16
7ab123
+#define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
7ab123
+/* This one is dodgy.  ABIv2 does not have a linker word, so use the
7ab123
+   CR save slot.  Used only by optimised __tls_get_addr call stub,
7ab123
+   relying on __tls_get_addr_opt not saving CR..  */
7ab123
+#define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
7ab123
+
7ab123
 /* TOC base pointers offset from start of TOC.  */
7ab123
 #define TOC_BASE_OFF	0x8000
7ab123
 
7ab123
@@ -140,7 +148,7 @@ static bfd_vma opd_entry_value
7ab123
 /* .plt call stub instructions.  The normal stub is like this, but
7ab123
    sometimes the .plt entry crosses a 64k boundary and we need to
7ab123
    insert an addi to adjust r11.  */
7ab123
-#define STD_R2_40R1	0xf8410028	/* std	 %r2,40(%r1)	     */
7ab123
+#define STD_R2_0R1	0xf8410000	/* std	 %r2,0+40(%r1)	     */
7ab123
 #define ADDIS_R11_R2	0x3d620000	/* addis %r11,%r2,xxx@ha     */
7ab123
 #define LD_R12_0R11	0xe98b0000	/* ld	 %r12,xxx+0@l(%r11)  */
7ab123
 #define MTCTR_R12	0x7d8903a6	/* mtctr %r12		     */
7ab123
@@ -164,7 +172,7 @@ static bfd_vma opd_entry_value
7ab123
 #define LD_R11_0R2	0xe9620000	/* ld	 %r11,xxx+0(%r2) */
7ab123
 #define LD_R2_0R2	0xe8420000	/* ld	 %r2,xxx+0(%r2)  */
7ab123
 
7ab123
-#define LD_R2_40R1	0xe8410028	/* ld    %r2,40(%r1)     */
7ab123
+#define LD_R2_0R1	0xe8410000	/* ld    %r2,0(%r1)      */
7ab123
 
7ab123
 /* glink call stub instructions.  We enter with the index in R0.  */
7ab123
 #define GLINK_CALL_STUB_SIZE (16*4)
7ab123
@@ -6326,7 +6334,7 @@ static bfd_byte *
7ab123
 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
7ab123
 {
7ab123
   p = savegpr0 (abfd, p, r);
7ab123
-  bfd_put_32 (abfd, STD_R0_0R1 + 16, p);
7ab123
+  bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
7ab123
   p = p + 4;
7ab123
   bfd_put_32 (abfd, BLR, p);
7ab123
   return p + 4;
7ab123
@@ -6342,7 +6350,7 @@ restgpr0 (bfd *abfd, bfd_byte *p, int r)
7ab123
 static bfd_byte *
7ab123
 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
7ab123
 {
7ab123
-  bfd_put_32 (abfd, LD_R0_0R1 + 16, p);
7ab123
+  bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
7ab123
   p = p + 4;
7ab123
   p = restgpr0 (abfd, p, r);
7ab123
   bfd_put_32 (abfd, MTLR_R0, p);
7ab123
@@ -6397,7 +6405,7 @@ static bfd_byte *
7ab123
 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
7ab123
 {
7ab123
   p = savefpr (abfd, p, r);
7ab123
-  bfd_put_32 (abfd, STD_R0_0R1 + 16, p);
7ab123
+  bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
7ab123
   p = p + 4;
7ab123
   bfd_put_32 (abfd, BLR, p);
7ab123
   return p + 4;
7ab123
@@ -6413,7 +6421,7 @@ restfpr (bfd *abfd, bfd_byte *p, int r)
7ab123
 static bfd_byte *
7ab123
 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
7ab123
 {
7ab123
-  bfd_put_32 (abfd, LD_R0_0R1 + 16, p);
7ab123
+  bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
7ab123
   p = p + 4;
7ab123
   p = restfpr (abfd, p, r);
7ab123
   bfd_put_32 (abfd, MTLR_R0, p);
7ab123
@@ -9873,7 +9881,7 @@ build_plt_stub (struct ppc_link_hash_tab
7ab123
 	}
7ab123
       if (ALWAYS_EMIT_R2SAVE
7ab123
 	  || stub_entry->stub_type == ppc_stub_plt_call_r2save)
7ab123
-	bfd_put_32 (obfd, STD_R2_40R1, p),			p += 4;
7ab123
+	bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p),	p += 4;
7ab123
       bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p),	p += 4;
7ab123
       bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p),	p += 4;
7ab123
       if (plt_load_toc
7ab123
@@ -9927,7 +9935,7 @@ build_plt_stub (struct ppc_link_hash_tab
7ab123
 	}
7ab123
       if (ALWAYS_EMIT_R2SAVE
7ab123
 	  || stub_entry->stub_type == ppc_stub_plt_call_r2save)
7ab123
-	bfd_put_32 (obfd, STD_R2_40R1, p),			p += 4;
7ab123
+	bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p),	p += 4;
7ab123
       bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p),	p += 4;
7ab123
       if (plt_load_toc
7ab123
 	  && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
7ab123
@@ -9968,11 +9976,9 @@ build_plt_stub (struct ppc_link_hash_tab
7ab123
 #define ADD_R3_R12_R13	0x7c6c6a14
7ab123
 #define BEQLR		0x4d820020
7ab123
 #define MR_R3_R0	0x7c030378
7ab123
-#define MFLR_R11	0x7d6802a6
7ab123
 #define STD_R11_0R1	0xf9610000
7ab123
 #define BCTRL		0x4e800421
7ab123
 #define LD_R11_0R1	0xe9610000
7ab123
-#define LD_R2_0R1	0xe8410000
7ab123
 #define MTLR_R11	0x7d6803a6
7ab123
 
7ab123
 static inline bfd_byte *
7ab123
@@ -9990,15 +9996,15 @@ build_tls_get_addr_stub (struct ppc_link
7ab123
   bfd_put_32 (obfd, BEQLR, p),			p += 4;
7ab123
   bfd_put_32 (obfd, MR_R3_R0, p),		p += 4;
7ab123
   bfd_put_32 (obfd, MFLR_R11, p),		p += 4;
7ab123
-  bfd_put_32 (obfd, STD_R11_0R1 + 32, p),	p += 4;
7ab123
+  bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
7ab123
 
7ab123
   if (r != NULL)
7ab123
     r[0].r_offset += 9 * 4;
7ab123
   p = build_plt_stub (htab, stub_entry, p, offset, r);
7ab123
   bfd_put_32 (obfd, BCTRL, p - 4);
7ab123
 
7ab123
-  bfd_put_32 (obfd, LD_R11_0R1 + 32, p),	p += 4;
7ab123
-  bfd_put_32 (obfd, LD_R2_0R1 + 40, p),		p += 4;
7ab123
+  bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p),	p += 4;
7ab123
+  bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p),	p += 4;
7ab123
   bfd_put_32 (obfd, MTLR_R11, p),		p += 4;
7ab123
   bfd_put_32 (obfd, BLR, p),			p += 4;
7ab123
 
7ab123
@@ -10122,7 +10128,7 @@ ppc_build_one_stub (struct bfd_hash_entr
7ab123
 	      htab->stub_error = TRUE;
7ab123
 	      return FALSE;
7ab123
 	    }
7ab123
-	  bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
7ab123
+	  bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
7ab123
 	  loc += 4;
7ab123
 	  size = 12;
7ab123
 	  if (PPC_HA (r2off) != 0)
7ab123
@@ -10318,7 +10324,7 @@ ppc_build_one_stub (struct bfd_hash_entr
7ab123
 	      return FALSE;
7ab123
 	    }
7ab123
 
7ab123
-	  bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
7ab123
+	  bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
7ab123
 	  loc += 4;
7ab123
 	  size = 20;
7ab123
 	  if (PPC_HA (off) != 0)
7ab123
@@ -13113,7 +13119,8 @@ ppc64_elf_relocate_section (bfd *output_
7ab123
 	      insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
7ab123
 	      if (insn == NOP
7ab123
 		  || insn == CROR_151515 || insn == CROR_313131)
7ab123
-		bfd_put_32 (input_bfd, STD_R2_40R1,
7ab123
+		bfd_put_32 (input_bfd,
7ab123
+			    STD_R2_0R1 + STK_TOC (htab),
7ab123
 			    contents + rel->r_offset);
7ab123
 	    }
7ab123
 	  break;
7ab123
@@ -13172,7 +13179,8 @@ ppc64_elf_relocate_section (bfd *output_
7ab123
 			  /* Special stub used, leave nop alone.  */
7ab123
 			}
7ab123
 		      else
7ab123
-			bfd_put_32 (input_bfd, LD_R2_40R1,
7ab123
+			bfd_put_32 (input_bfd,
7ab123
+				    LD_R2_0R1 + STK_TOC (htab),
7ab123
 				    contents + rel->r_offset + 4);
7ab123
 		      can_plt_call = TRUE;
7ab123
 		    }