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

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