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

01917d
commit 71a39c98f8bedad54818c62ab2d567b0e2de546b
01917d
Author: Alan Modra <amodra@gmail.com>
01917d
Date:   Tue Oct 29 12:39:30 2013 +1030
01917d
01917d
    Change plt stubs to have destination in r12.
01917d
    
01917d
    This change is to support the new ELFv2 ABI, which uses the value in
01917d
    r12 on function entry to calculate the got/toc pointer.
01917d
    
01917d
    bfd/
01917d
    	* elf64-ppc.c (build_plt_stub): Switch stubs to use r11 as base
01917d
    	reg and r12 as destination.
01917d
    	(ppc_build_one_stub): Likewise.
01917d
    	(ppc64_elf_build_stubs): Likewise for glink.
01917d
    ld/testsuite/
01917d
    	* ld-powerpc/tls.s: Add proper .opd entry for _start.
01917d
    	* ld-powerpc/tlstoc.s: Likewise.
01917d
    	* ld-powerpc/relbrlt.d: Update for changed stubs.
01917d
    	* ld-powerpc/tls.d: Update for changed stubs and _start .opd entry.
01917d
    	* ld-powerpc/tls.g: Likewise.
01917d
    	* ld-powerpc/tlsexe.d: Likewise.
01917d
    	* ld-powerpc/tlsexe.g: Likewise.
01917d
    	* ld-powerpc/tlsexe.r: Likewise.
01917d
    	* ld-powerpc/tlsexetoc.d: Likewise.
01917d
    	* ld-powerpc/tlsexetoc.g: Likewise.
01917d
    	* ld-powerpc/tlsexetoc.r: Likewise.
01917d
    	* ld-powerpc/tlsso.d: Likewise.
01917d
    	* ld-powerpc/tlsso.g: Likewise.
01917d
    	* ld-powerpc/tlsso.r: Likewise.
01917d
    	* ld-powerpc/tlstoc.d: Likewise.
01917d
    	* ld-powerpc/tlstoc.g: Likewise.
01917d
    	* ld-powerpc/tlstocso.d: Likewise.
01917d
    	* ld-powerpc/tlstocso.g: Likewise.
01917d
    	* ld-powerpc/tlstocso.r: Likewise.
01917d
01917d
Index: gdb-7.6.1/bfd/elf64-ppc.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/bfd/elf64-ppc.c
01917d
+++ gdb-7.6.1/bfd/elf64-ppc.c
01917d
@@ -137,29 +137,29 @@ static bfd_vma opd_entry_value
01917d
 
01917d
 /* .plt call stub instructions.  The normal stub is like this, but
01917d
    sometimes the .plt entry crosses a 64k boundary and we need to
01917d
-   insert an addi to adjust r12.  */
01917d
+   insert an addi to adjust r11.  */
01917d
 #define PLT_CALL_STUB_SIZE (7*4)
01917d
-#define ADDIS_R12_R2	0x3d820000	/* addis %r12,%r2,xxx@ha     */
01917d
 #define STD_R2_40R1	0xf8410028	/* std	 %r2,40(%r1)	     */
01917d
-#define LD_R11_0R12	0xe96c0000	/* ld	 %r11,xxx+0@l(%r12)  */
01917d
-#define MTCTR_R11	0x7d6903a6	/* mtctr %r11		     */
01917d
-#define LD_R2_0R12	0xe84c0000	/* ld	 %r2,xxx+8@l(%r12)   */
01917d
-					/* ld	 %r11,xxx+16@l(%r12) */
01917d
+#define ADDIS_R11_R2	0x3d620000	/* addis %r11,%r2,xxx@ha     */
01917d
+#define LD_R12_0R11	0xe98b0000	/* ld	 %r12,xxx+0@l(%r11)  */
01917d
+#define MTCTR_R12	0x7d8903a6	/* mtctr %r12		     */
01917d
+#define LD_R2_0R11	0xe84b0000	/* ld	 %r2,xxx+8@l(%r11)   */
01917d
+#define LD_R11_0R11	0xe96b0000	/* ld	 %r11,xxx+16@l(%r11) */
01917d
 #define BCTR		0x4e800420	/* bctr			     */
01917d
 
01917d
-
01917d
-#define ADDIS_R12_R12	0x3d8c0000	/* addis %r12,%r12,off@ha  */
01917d
-#define ADDI_R12_R12	0x398c0000	/* addi %r12,%r12,off@l  */
01917d
+#define ADDI_R11_R11	0x396b0000	/* addi %r11,%r11,off@l  */
01917d
 #define ADDIS_R2_R2	0x3c420000	/* addis %r2,%r2,off@ha  */
01917d
 #define ADDI_R2_R2	0x38420000	/* addi  %r2,%r2,off@l   */
01917d
 
01917d
-#define XOR_R11_R11_R11	0x7d6b5a78	/* xor   %r11,%r11,%r11  */
01917d
-#define ADD_R12_R12_R11	0x7d8c5a14	/* add   %r12,%r12,%r11  */
01917d
+#define XOR_R2_R12_R12	0x7d826278	/* xor   %r2,%r12,%r12   */
01917d
+#define ADD_R11_R11_R2	0x7d6b1214	/* add   %r11,%r11,%r2   */
01917d
+#define XOR_R11_R12_R12	0x7d8b6278	/* xor   %r11,%r12,%r12  */
01917d
 #define ADD_R2_R2_R11	0x7c425a14	/* add   %r2,%r2,%r11    */
01917d
 #define CMPLDI_R2_0	0x28220000	/* cmpldi %r2,0          */
01917d
 #define BNECTR		0x4ca20420	/* bnectr+               */
01917d
 #define BNECTR_P4	0x4ce20420	/* bnectr+               */
01917d
 
01917d
+#define LD_R12_0R2	0xe9820000	/* ld	 %r12,xxx+0(%r2) */
01917d
 #define LD_R11_0R2	0xe9620000	/* ld	 %r11,xxx+0(%r2) */
01917d
 #define LD_R2_0R2	0xe8420000	/* ld	 %r2,xxx+0(%r2)  */
01917d
 
01917d
@@ -174,13 +174,13 @@ static bfd_vma opd_entry_value
01917d
 #define BCL_20_31	0x429f0005	/*  bcl 20,31,1f		*/
01917d
 					/* 1:				*/
01917d
 #define MFLR_R11	0x7d6802a6	/*  mflr %11			*/
01917d
-#define LD_R2_M16R11	0xe84bfff0	/*  ld %2,(0b-1b)(%11)		*/
01917d
+					/*  ld %2,(0b-1b)(%11)		*/
01917d
 #define MTLR_R12	0x7d8803a6	/*  mtlr %12			*/
01917d
-#define ADD_R12_R2_R11	0x7d825a14	/*  add %12,%2,%11		*/
01917d
-					/*  ld %11,0(%12)		*/
01917d
-					/*  ld %2,8(%12)		*/
01917d
-					/*  mtctr %11			*/
01917d
-					/*  ld %11,16(%12)		*/
01917d
+#define ADD_R11_R2_R11	0x7d625a14	/*  add %11,%2,%11		*/
01917d
+					/*  ld %12,0(%11)		*/
01917d
+					/*  ld %2,8(%11)		*/
01917d
+					/*  mtctr %12			*/
01917d
+					/*  ld %11,16(%11)		*/
01917d
 					/*  bctr			*/
01917d
 
01917d
 /* Pad with this.  */
01917d
@@ -3452,13 +3452,13 @@ ppc64_elf_get_synthetic_symtab (bfd *abf
01917d
    .
01917d
    .
01917d
    .	.foo_stub:
01917d
-   .		addis	12,2,Lfoo@toc@ha	# in practice, the call stub
01917d
-   .		addi	12,12,Lfoo@toc@l	# is slightly optimized, but
01917d
-   .		std	2,40(1)			# this is the general idea
01917d
-   .		ld	11,0(12)
01917d
-   .		ld	2,8(12)
01917d
-   .		mtctr	11
01917d
-   .		ld	11,16(12)
01917d
+   .		std	2,40(1)			# in practice, the call stub
01917d
+   .		addis	11,2,Lfoo@toc@ha	# is slightly optimized, but
01917d
+   .		addi	11,11,Lfoo@toc@l	# this is the general idea
01917d
+   .		ld	12,0(11)
01917d
+   .		ld	2,8(11)
01917d
+   .		mtctr	12
01917d
+   .		ld	11,16(11)
01917d
    .		bctr
01917d
    .
01917d
    .		.section .plt
01917d
@@ -3548,21 +3548,21 @@ must_be_dyn_reloc (struct bfd_link_info
01917d
    ppc_stub_plt_branch:
01917d
    Similar to the above, but a 24 bit branch in the stub section won't
01917d
    reach its destination.
01917d
-   .	addis	%r12,%r2,xxx@toc@ha
01917d
-   .	ld	%r11,xxx@toc@l(%r12)
01917d
-   .	mtctr	%r11
01917d
+   .	addis	%r11,%r2,xxx@toc@ha
01917d
+   .	ld	%r12,xxx@toc@l(%r11)
01917d
+   .	mtctr	%r12
01917d
    .	bctr
01917d
 
01917d
    ppc_stub_plt_call:
01917d
    Used to call a function in a shared library.  If it so happens that
01917d
    the plt entry referenced crosses a 64k boundary, then an extra
01917d
-   "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr".
01917d
-   .	addis	%r12,%r2,xxx@toc@ha
01917d
+   "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
01917d
    .	std	%r2,40(%r1)
01917d
-   .	ld	%r11,xxx+0@toc@l(%r12)
01917d
-   .	mtctr	%r11
01917d
-   .	ld	%r2,xxx+8@toc@l(%r12)
01917d
-   .	ld	%r11,xxx+16@toc@l(%r12)
01917d
+   .	addis	%r11,%r2,xxx@toc@ha
01917d
+   .	ld	%r12,xxx+0@toc@l(%r11)
01917d
+   .	mtctr	%r12
01917d
+   .	ld	%r2,xxx+8@toc@l(%r11)
01917d
+   .	ld	%r11,xxx+16@toc@l(%r11)
01917d
    .	bctr
01917d
 
01917d
    ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
01917d
@@ -3575,11 +3575,11 @@ must_be_dyn_reloc (struct bfd_link_info
01917d
 
01917d
    A ppc_stub_plt_branch with an r2 offset looks like:
01917d
    .	std	%r2,40(%r1)
01917d
-   .	addis	%r12,%r2,xxx@toc@ha
01917d
-   .	ld	%r11,xxx@toc@l(%r12)
01917d
+   .	addis	%r11,%r2,xxx@toc@ha
01917d
+   .	ld	%r12,xxx@toc@l(%r11)
01917d
    .	addis	%r2,%r2,off@ha
01917d
    .	addi	%r2,%r2,off@l
01917d
-   .	mtctr	%r11
01917d
+   .	mtctr	%r12
01917d
    .	bctr
01917d
 
01917d
    In cases where the "addis" instruction would add zero, the "addis" is
01917d
@@ -9569,9 +9569,9 @@ ppc_type_of_stub (asection *input_sec,
01917d
    the appropriate glink entry if so.
01917d
 
01917d
    .	fake dep barrier	compare
01917d
-   .	ld 11,xxx(2)		ld 11,xxx(2)
01917d
-   .	mtctr 11		mtctr 11
01917d
-   .	xor 11,11,11		ld 2,xxx+8(2)
01917d
+   .	ld 12,xxx(2)		ld 12,xxx(2)
01917d
+   .	mtctr 12		mtctr 12
01917d
+   .	xor 11,12,12		ld 2,xxx+8(2)
01917d
    .	add 2,2,11		cmpldi 2,0
01917d
    .	ld 2,xxx+8(2)		bnectr+
01917d
    .	bctr			b <glink_entry>
01917d
@@ -9706,22 +9706,22 @@ build_plt_stub (struct ppc_link_hash_tab
01917d
       if (ALWAYS_EMIT_R2SAVE
01917d
 	  || stub_entry->stub_type == ppc_stub_plt_call_r2save)
01917d
 	bfd_put_32 (obfd, STD_R2_40R1, p),			p += 4;
01917d
-      bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p),	p += 4;
01917d
-      bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p),	p += 4;
01917d
+      bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p),	p += 4;
01917d
+      bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p),	p += 4;
01917d
       if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
01917d
 	{
01917d
-	  bfd_put_32 (obfd, ADDI_R12_R12 | PPC_LO (offset), p),	p += 4;
01917d
+	  bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p),	p += 4;
01917d
 	  offset = 0;
01917d
 	}
01917d
-      bfd_put_32 (obfd, MTCTR_R11, p),				p += 4;
01917d
+      bfd_put_32 (obfd, MTCTR_R12, p),				p += 4;
01917d
       if (use_fake_dep)
01917d
 	{
01917d
-	  bfd_put_32 (obfd, XOR_R11_R11_R11, p),		p += 4;
01917d
-	  bfd_put_32 (obfd, ADD_R12_R12_R11, p),		p += 4;
01917d
+	  bfd_put_32 (obfd, XOR_R2_R12_R12, p),			p += 4;
01917d
+	  bfd_put_32 (obfd, ADD_R11_R11_R2, p),			p += 4;
01917d
 	}
01917d
-      bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset + 8), p),	p += 4;
01917d
+      bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p),	p += 4;
01917d
       if (plt_static_chain)
01917d
-	bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset + 16), p), p += 4;
01917d
+	bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
01917d
     }
01917d
   else
01917d
     {
01917d
@@ -9753,16 +9753,16 @@ build_plt_stub (struct ppc_link_hash_tab
01917d
       if (ALWAYS_EMIT_R2SAVE
01917d
 	  || stub_entry->stub_type == ppc_stub_plt_call_r2save)
01917d
 	bfd_put_32 (obfd, STD_R2_40R1, p),			p += 4;
01917d
-      bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset), p),	p += 4;
01917d
+      bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p),	p += 4;
01917d
       if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
01917d
 	{
01917d
 	  bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p),	p += 4;
01917d
 	  offset = 0;
01917d
 	}
01917d
-      bfd_put_32 (obfd, MTCTR_R11, p),				p += 4;
01917d
+      bfd_put_32 (obfd, MTCTR_R12, p),				p += 4;
01917d
       if (use_fake_dep)
01917d
 	{
01917d
-	  bfd_put_32 (obfd, XOR_R11_R11_R11, p),		p += 4;
01917d
+	  bfd_put_32 (obfd, XOR_R11_R12_R12, p),		p += 4;
01917d
 	  bfd_put_32 (obfd, ADD_R2_R2_R11, p),			p += 4;
01917d
 	}
01917d
       if (plt_static_chain)
01917d
@@ -10111,14 +10111,14 @@ ppc_build_one_stub (struct bfd_hash_entr
01917d
 	  if (PPC_HA (off) != 0)
01917d
 	    {
01917d
 	      size = 16;
01917d
-	      bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
01917d
 	      loc += 4;
01917d
-	      bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
01917d
 	    }
01917d
 	  else
01917d
 	    {
01917d
 	      size = 12;
01917d
-	      bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
01917d
 	    }
01917d
 	}
01917d
       else
01917d
@@ -10137,14 +10137,14 @@ ppc_build_one_stub (struct bfd_hash_entr
01917d
 	  if (PPC_HA (off) != 0)
01917d
 	    {
01917d
 	      size += 4;
01917d
-	      bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
01917d
 	      loc += 4;
01917d
-	      bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
01917d
 	      loc += 4;
01917d
 	    }
01917d
 	  else
01917d
 	    {
01917d
-	      bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (off), loc);
01917d
+	      bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
01917d
 	      loc += 4;
01917d
 	    }
01917d
 
01917d
@@ -10157,7 +10157,7 @@ ppc_build_one_stub (struct bfd_hash_entr
01917d
 	  bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
01917d
 	}
01917d
       loc += 4;
01917d
-      bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc);
01917d
+      bfd_put_32 (htab->stub_bfd, MTCTR_R12, loc);
01917d
       loc += 4;
01917d
       bfd_put_32 (htab->stub_bfd, BCTR, loc);
01917d
       break;
01917d
@@ -11909,19 +11909,19 @@ ppc64_elf_build_stubs (bfd_boolean emit_
01917d
       p += 4;
01917d
       bfd_put_32 (htab->glink->owner, MFLR_R11, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, LD_R2_M16R11, p);
01917d
+      bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
01917d
       p += 4;
01917d
       bfd_put_32 (htab->glink->owner, MTLR_R12, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, ADD_R12_R2_R11, p);
01917d
+      bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, LD_R11_0R12, p);
01917d
+      bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p);
01917d
+      bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, MTCTR_R11, p);
01917d
+      bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
01917d
       p += 4;
01917d
-      bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p);
01917d
+      bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
01917d
       p += 4;
01917d
       bfd_put_32 (htab->glink->owner, BCTR, p);
01917d
       p += 4;