ce426f
# commit 61cd8fe4017c251617dd300818917e61a12ab48e
ce426f
# Author: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
ce426f
# Date:   Wed Dec 4 06:59:37 2013 -0600
ce426f
# 
ce426f
#     PowerPC64 ELFv2 ABI 5/6: LD_AUDIT interface changes
ce426f
#     
ce426f
#     The ELFv2 ABI changes the calling convention by passing and returning
ce426f
#     structures in registers in more cases than the old ABI:
ce426f
#     http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01145.html
ce426f
#     http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01147.html
ce426f
#     
ce426f
#     For the most part, this does not affect glibc, since glibc assembler
ce426f
#     files do not use structure parameters / return values.  However, one
ce426f
#     place is affected: the LD_AUDIT interface provides a structure to
ce426f
#     the audit routine that contains all registers holding function
ce426f
#     argument and return values for the intercepted PLT call.
ce426f
#     
ce426f
#     Since the new ABI now sometimes uses registers to return values
ce426f
#     that were never used for this purpose in the old ABI, this structure
ce426f
#     has to be extended.  To force audit routines to be modified for the
ce426f
#     new ABI if necessary, the patch defines v2 variants of the la_ppc64
ce426f
#     types and routines.
ce426f
#     
ce426f
#     In addition, the patch contains two unrelated changes to the
ce426f
#     PLT trampoline routines: it fixes a bug where FPR return values
ce426f
#     were stored in the wrong place, and it removes the unnecessary
ce426f
#     save/restore of CR.
ce426f
# 
ce426f
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/bits/link.h glibc-2.17-c758a686/sysdeps/powerpc/bits/link.h
ce426f
--- glibc-2.17-c758a686/sysdeps/powerpc/bits/link.h	2014-05-29 14:11:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/sysdeps/powerpc/bits/link.h	2014-05-29 14:11:20.000000000 -0500
ce426f
@@ -63,7 +63,7 @@
ce426f
 
ce426f
 __END_DECLS
ce426f
 
ce426f
-#else
ce426f
+#elif _CALL_ELF != 2
ce426f
 
ce426f
 /* Registers for entry into PLT on PPC64.  */
ce426f
 typedef struct La_ppc64_regs
ce426f
@@ -107,4 +107,48 @@
ce426f
 
ce426f
 __END_DECLS
ce426f
 
ce426f
+#else
ce426f
+
ce426f
+/* Registers for entry into PLT on PPC64 in the ELFv2 ABI.  */
ce426f
+typedef struct La_ppc64v2_regs
ce426f
+{
ce426f
+  uint64_t lr_reg[8];
ce426f
+  double lr_fp[13];
ce426f
+  uint32_t __padding;
ce426f
+  uint32_t lr_vrsave;
ce426f
+  uint32_t lr_vreg[12][4] __attribute__ ((aligned (16)));
ce426f
+  uint64_t lr_r1;
ce426f
+  uint64_t lr_lr;
ce426f
+} La_ppc64v2_regs;
ce426f
+
ce426f
+/* Return values for calls from PLT on PPC64 in the ELFv2 ABI.  */
ce426f
+typedef struct La_ppc64v2_retval
ce426f
+{
ce426f
+  uint64_t lrv_r3;
ce426f
+  uint64_t lrv_r4;
ce426f
+  double lrv_fp[10];
ce426f
+  uint32_t lrv_vreg[8][4] __attribute__ ((aligned (16)));
ce426f
+} La_ppc64v2_retval;
ce426f
+
ce426f
+
ce426f
+__BEGIN_DECLS
ce426f
+
ce426f
+extern Elf64_Addr la_ppc64v2_gnu_pltenter (Elf64_Sym *__sym,
ce426f
+					   unsigned int __ndx,
ce426f
+					   uintptr_t *__refcook,
ce426f
+					   uintptr_t *__defcook,
ce426f
+					   La_ppc64v2_regs *__regs,
ce426f
+					   unsigned int *__flags,
ce426f
+					   const char *__symname,
ce426f
+					   long int *__framesizep);
ce426f
+extern unsigned int la_ppc64v2_gnu_pltexit (Elf64_Sym *__sym,
ce426f
+					    unsigned int __ndx,
ce426f
+					    uintptr_t *__refcook,
ce426f
+					    uintptr_t *__defcook,
ce426f
+					    const La_ppc64v2_regs *__inregs,
ce426f
+					    La_ppc64v2_retval *__outregs,
ce426f
+					    const char *__symname);
ce426f
+
ce426f
+__END_DECLS
ce426f
+
ce426f
 #endif
ce426f
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/ldsodefs.h glibc-2.17-c758a686/sysdeps/powerpc/ldsodefs.h
ce426f
--- glibc-2.17-c758a686/sysdeps/powerpc/ldsodefs.h	2014-05-29 14:11:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/sysdeps/powerpc/ldsodefs.h	2014-05-29 14:11:20.000000000 -0500
ce426f
@@ -25,6 +25,8 @@
ce426f
 struct La_ppc32_retval;
ce426f
 struct La_ppc64_regs;
ce426f
 struct La_ppc64_retval;
ce426f
+struct La_ppc64v2_regs;
ce426f
+struct La_ppc64v2_retval;
ce426f
 
ce426f
 #define ARCH_PLTENTER_MEMBERS						\
ce426f
     Elf32_Addr (*ppc32_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *, \
ce426f
@@ -34,7 +36,12 @@
ce426f
     Elf64_Addr (*ppc64_gnu_pltenter) (Elf64_Sym *, unsigned int, uintptr_t *, \
ce426f
 				      uintptr_t *, struct La_ppc64_regs *, \
ce426f
 				      unsigned int *, const char *name,	\
ce426f
-				      long int *framesizep)
ce426f
+				      long int *framesizep);		\
ce426f
+    Elf64_Addr (*ppc64v2_gnu_pltenter) (Elf64_Sym *, unsigned int,	\
ce426f
+					uintptr_t *,  uintptr_t *,	\
ce426f
+					struct La_ppc64v2_regs *,	\
ce426f
+					unsigned int *, const char *name, \
ce426f
+					long int *framesizep)
ce426f
 
ce426f
 #define ARCH_PLTEXIT_MEMBERS						\
ce426f
     unsigned int (*ppc32_gnu_pltexit) (Elf32_Sym *, unsigned int,	\
ce426f
@@ -47,7 +54,14 @@
ce426f
 				       uintptr_t *,			\
ce426f
 				       uintptr_t *,			\
ce426f
 				       const struct La_ppc64_regs *,	\
ce426f
-				       struct La_ppc64_retval *, const char *)
ce426f
+				       struct La_ppc64_retval *,	\
ce426f
+				       const char *);			\
ce426f
+    unsigned int (*ppc64v2_gnu_pltexit) (Elf64_Sym *, unsigned int,	\
ce426f
+					 uintptr_t *,			\
ce426f
+					 uintptr_t *,			\
ce426f
+					 const struct La_ppc64v2_regs *,\
ce426f
+					 struct La_ppc64v2_retval *,	\
ce426f
+					 const char *)
ce426f
 
ce426f
 #include_next <ldsodefs.h>
ce426f
 
ce426f
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h
ce426f
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h	2014-05-29 14:11:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h	2014-05-29 14:11:20.000000000 -0500
ce426f
@@ -546,8 +546,13 @@
ce426f
 
ce426f
 
ce426f
 /* Names of the architecture-specific auditing callback functions.  */
ce426f
+#if _CALL_ELF != 2
ce426f
 #define ARCH_LA_PLTENTER ppc64_gnu_pltenter
ce426f
 #define ARCH_LA_PLTEXIT ppc64_gnu_pltexit
ce426f
+#else
ce426f
+#define ARCH_LA_PLTENTER ppc64v2_gnu_pltenter
ce426f
+#define ARCH_LA_PLTEXIT ppc64v2_gnu_pltexit
ce426f
+#endif
ce426f
 
ce426f
 #endif /* dl_machine_h */
ce426f
 
ce426f
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S
ce426f
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S	2014-05-29 14:11:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S	2014-05-29 14:11:20.000000000 -0500
ce426f
@@ -50,11 +50,8 @@
ce426f
 /* Store the LR in the LR Save area.  */
ce426f
 	std	r0,FRAME_SIZE+FRAME_LR_SAVE(r1)
ce426f
 	cfi_offset (lr, FRAME_LR_SAVE)
ce426f
-	mfcr	r0
ce426f
 	std	r9,INT_PARMS+48(r1)
ce426f
 	std	r10,INT_PARMS+56(r1)
ce426f
-/* I'm almost certain we don't have to save cr...  be safe.  */
ce426f
-	std	r0,FRAME_SIZE+FRAME_CR_SAVE(r1)
ce426f
 	bl	JUMPTARGET(_dl_fixup)
ce426f
 #ifndef SHARED
ce426f
 	nop
ce426f
@@ -66,11 +63,9 @@
ce426f
 	ld	r8,INT_PARMS+40(r1)
ce426f
 	ld	r7,INT_PARMS+32(r1)
ce426f
 	mtlr	r0
ce426f
-	ld	r0,FRAME_SIZE+FRAME_CR_SAVE(r1)
ce426f
 	ld	r6,INT_PARMS+24(r1)
ce426f
 	ld	r5,INT_PARMS+16(r1)
ce426f
 	ld	r4,INT_PARMS+8(r1)
ce426f
-	mtcrf	0xFF,r0
ce426f
 /* Prepare for calling the function returned by fixup.  */
ce426f
 	PPC64_LOAD_FUNCPTR r3
ce426f
 	ld	r3,INT_PARMS+0(r1)
ce426f
@@ -85,18 +80,30 @@
ce426f
 #undef FRAME_SIZE
ce426f
 #undef INT_PARMS
ce426f
 
ce426f
-	/* Stack layout:
ce426f
-	   (Note: some of these are not required for the ELFv2 ABI.)
ce426f
-	  +592   previous backchain
ce426f
-	  +584   spill_r31
ce426f
-	  +576   spill_r30
ce426f
-	  +560   v1
ce426f
-	  +552   fp4
ce426f
-	  +544   fp3
ce426f
-	  +536   fp2
ce426f
-	  +528   fp1
ce426f
-	  +520   r4
ce426f
-	  +512   r3
ce426f
+	/* Stack layout:		ELFv2 ABI.
ce426f
+					+752   previous backchain
ce426f
+					+744   spill_r31
ce426f
+					+736   spill_r30
ce426f
+					+720   v8
ce426f
+					+704   v7
ce426f
+					+688   v6
ce426f
+					+672   v5
ce426f
+					+656   v4
ce426f
+					+640   v3
ce426f
+					+624   v2
ce426f
+					+608   v1
ce426f
+					+600   fp10
ce426f
+	  ELFv1 ABI			+592   fp9
ce426f
+	  +592   previous backchain	+584   fp8
ce426f
+	  +584   spill_r31		+576   fp7
ce426f
+	  +576   spill_r30		+568   fp6
ce426f
+	  +560   v1			+560   fp5
ce426f
+	  +552   fp4			+552   fp4
ce426f
+	  +544   fp3			+544   fp3
ce426f
+	  +536   fp2			+536   fp2
ce426f
+	  +528   fp1			+528   fp1
ce426f
+	  +520   r4			+520   r4
ce426f
+	  +512   r3			+512   r3
ce426f
 	   return values
ce426f
           +504   free
ce426f
 	  +496   stackframe
ce426f
@@ -157,10 +164,15 @@
ce426f
 	  +8     CR save area
ce426f
 	r1+0     stack back chain
ce426f
 	*/
ce426f
-#define FRAME_SIZE 592
ce426f
+#if _CALL_ELF == 2
ce426f
+# define FRAME_SIZE 752
ce426f
+# define VR_RTN 608
ce426f
+#else
ce426f
+# define FRAME_SIZE 592
ce426f
+# define VR_RTN 560
ce426f
+#endif
ce426f
 #define INT_RTN 512
ce426f
 #define FPR_RTN 528
ce426f
-#define VR_RTN 560
ce426f
 #define STACK_FRAME 496
ce426f
 #define CALLING_LR 488
ce426f
 #define CALLING_SP 480
ce426f
@@ -205,18 +217,14 @@
ce426f
 	mflr	r5
ce426f
 	std	r7,INT_PARMS+32(r1)
ce426f
 	std	r8,INT_PARMS+40(r1)
ce426f
-/* Store the LR in the LR Save area of the previous frame.  */
ce426f
-/* XXX Do we have to do this?  */
ce426f
+/* Store the LR in the LR Save area.  */
ce426f
 	la	r8,FRAME_SIZE(r1)
ce426f
 	std	r5,FRAME_SIZE+FRAME_LR_SAVE(r1)
ce426f
 	cfi_offset (lr, FRAME_LR_SAVE)
ce426f
 	std	r5,CALLING_LR(r1)
ce426f
-	mfcr	r0
ce426f
 	std	r9,INT_PARMS+48(r1)
ce426f
 	std	r10,INT_PARMS+56(r1)
ce426f
 	std	r8,CALLING_SP(r1)
ce426f
-/* I'm almost certain we don't have to save cr...  be safe.  */
ce426f
-	std	r0,FRAME_SIZE+FRAME_CR_SAVE(r1)
ce426f
 	ld	r12,.LC__dl_hwcap@toc(r2)
ce426f
 #ifdef SHARED
ce426f
 	/* Load _rtld_local_ro._dl_hwcap.  */
ce426f
@@ -319,11 +327,9 @@
ce426f
 	ld	r8,INT_PARMS+40(r1)
ce426f
 	ld	r7,INT_PARMS+32(r1)
ce426f
 	mtlr	r0
ce426f
-	ld	r0,FRAME_SIZE+FRAME_CR_SAVE(r1)
ce426f
 	ld	r6,INT_PARMS+24(r1)
ce426f
 	ld	r5,INT_PARMS+16(r1)
ce426f
 	ld	r4,INT_PARMS+8(r1)
ce426f
-	mtcrf	0xFF,r0
ce426f
 /* Prepare for calling the function returned by fixup.  */
ce426f
 	PPC64_LOAD_FUNCPTR r3
ce426f
 	ld	r3,INT_PARMS+0(r1)
ce426f
@@ -346,10 +352,11 @@
ce426f
 	lfd	fp12,FPR_PARMS+88(r1)
ce426f
 	lfd	fp13,FPR_PARMS+96(r1)
ce426f
 /* Unwind the stack frame, and jump.  */
ce426f
-	ld	r31,584(r1)
ce426f
-	ld	r30,576(r1)
ce426f
+	ld	r31,FRAME_SIZE-8(r1)
ce426f
+	ld	r30,FRAME_SIZE-16(r1)
ce426f
 	addi	r1,r1,FRAME_SIZE
ce426f
 	bctr
ce426f
+
ce426f
 L(do_pltexit):
ce426f
 	la	r10,(VR_PARMS+0)(r1)
ce426f
 	la	r9,(VR_PARMS+16)(r1)
ce426f
@@ -383,11 +390,9 @@
ce426f
 	ld	r8,INT_PARMS+40(r1)
ce426f
 	ld	r7,INT_PARMS+32(r1)
ce426f
 	mtlr	r0
ce426f
-	ld	r0,FRAME_SIZE+FRAME_CR_SAVE(r1)
ce426f
 	ld	r6,INT_PARMS+24(r1)
ce426f
 	ld	r5,INT_PARMS+16(r1)
ce426f
 	ld	r4,INT_PARMS+8(r1)
ce426f
-	mtcrf	0xFF,r0
ce426f
 /* Prepare for calling the function returned by fixup.  */
ce426f
 	std	r2,FRAME_TOC_SAVE(r1)
ce426f
 	PPC64_LOAD_FUNCPTR r3
ce426f
@@ -413,16 +418,37 @@
ce426f
 /* But return here and store the return values.  */
ce426f
 	std	r3,INT_RTN(r1)
ce426f
 	std	r4,INT_RTN+8(r1)
ce426f
-	stfd	fp1,FPR_PARMS+0(r1)
ce426f
-	stfd	fp2,FPR_PARMS+8(r1)
ce426f
+	stfd	fp1,FPR_RTN+0(r1)
ce426f
+	stfd	fp2,FPR_RTN+8(r1)
ce426f
 	cmpdi	cr0,r12,0
ce426f
 	la	r10,VR_RTN(r1)
ce426f
-	stfd	fp3,FPR_PARMS+16(r1)
ce426f
-	stfd	fp4,FPR_PARMS+24(r1)
ce426f
+	stfd	fp3,FPR_RTN+16(r1)
ce426f
+	stfd	fp4,FPR_RTN+24(r1)
ce426f
+#if _CALL_ELF == 2
ce426f
+	la	r12,VR_RTN+16(r1)
ce426f
+	stfd	fp5,FPR_RTN+32(r1)
ce426f
+	stfd	fp6,FPR_RTN+40(r1)
ce426f
+	li	r5,32
ce426f
+	li	r6,64
ce426f
+	stfd	fp7,FPR_RTN+48(r1)
ce426f
+	stfd	fp8,FPR_RTN+56(r1)
ce426f
+	stfd	fp9,FPR_RTN+64(r1)
ce426f
+	stfd	fp10,FPR_RTN+72(r1)
ce426f
+#endif
ce426f
 	mr	r3,r31
ce426f
 	mr	r4,r30
ce426f
 	beq	L(callpltexit)
ce426f
 	stvx	v2,0,r10
ce426f
+#if _CALL_ELF == 2
ce426f
+	stvx	v3,0,r12
ce426f
+	stvx	v4,r5,r10
ce426f
+	stvx	v5,r5,r12
ce426f
+	addi	r5,r5,64
ce426f
+	stvx	v6,r6,r10
ce426f
+	stvx	v7,r6,r12
ce426f
+	stvx	v8,r5,r10
ce426f
+	stvx	v9,r5,r12
ce426f
+#endif
ce426f
 L(callpltexit):
ce426f
 	addi	r5,r1,INT_PARMS
ce426f
 	addi	r6,r1,INT_RTN
ce426f
@@ -434,18 +460,39 @@
ce426f
 	lwz	r12,VR_VRSAVE(r1)
ce426f
 	ld	r3,INT_RTN(r1)
ce426f
 	ld	r4,INT_RTN+8(r1)
ce426f
-	lfd	fp1,FPR_PARMS+0(r1)
ce426f
-	lfd	fp2,FPR_PARMS+8(r1)
ce426f
+	lfd	fp1,FPR_RTN+0(r1)
ce426f
+	lfd	fp2,FPR_RTN+8(r1)
ce426f
 	cmpdi	cr0,r12,0
ce426f
-	la	r10,VR_RTN(r1)
ce426f
-	lfd	fp3,FPR_PARMS+16(r1)
ce426f
-	lfd	fp4,FPR_PARMS+24(r1)
ce426f
+	la	r11,VR_RTN(r1)
ce426f
+	lfd	fp3,FPR_RTN+16(r1)
ce426f
+	lfd	fp4,FPR_RTN+24(r1)
ce426f
+#if _CALL_ELF == 2
ce426f
+	la	r12,VR_RTN+16(r1)
ce426f
+	lfd	fp5,FPR_RTN+32(r1)
ce426f
+	lfd	fp6,FPR_RTN+40(r1)
ce426f
+	li	r30,32
ce426f
+	li	r31,64
ce426f
+	lfd	fp7,FPR_RTN+48(r1)
ce426f
+	lfd	fp8,FPR_RTN+56(r1)
ce426f
+	lfd	fp9,FPR_RTN+64(r1)
ce426f
+	lfd	fp10,FPR_RTN+72(r1)
ce426f
+#endif
ce426f
 	beq	L(pltexitreturn)
ce426f
-	lvx	v2,0,r10
ce426f
+	lvx	v2,0,r11
ce426f
+#if _CALL_ELF == 2
ce426f
+	lvx	v3,0,r12
ce426f
+	lvx	v4,r30,r11
ce426f
+	lvx	v5,r30,r12
ce426f
+	addi	r30,r30,64
ce426f
+	lvx	v6,r31,r11
ce426f
+	lvx	v7,r31,r12
ce426f
+	lvx	v8,r30,r11
ce426f
+	lvx	v9,r30,r12
ce426f
+#endif
ce426f
 L(pltexitreturn):
ce426f
 	ld	r0,FRAME_SIZE+FRAME_LR_SAVE(r1)
ce426f
-	ld	r31,584(r1)
ce426f
-	ld	r30,576(r1)
ce426f
+	ld	r31,FRAME_SIZE-8(r1)
ce426f
+	ld	r30,FRAME_SIZE-16(r1)
ce426f
 	mtlr	r0
ce426f
 	ld	r1,0(r1)
ce426f
 	blr
ce426f
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/tst-audit.h glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/tst-audit.h
ce426f
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/tst-audit.h	2014-05-29 14:11:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/tst-audit.h	2014-05-29 14:11:20.000000000 -0500
ce426f
@@ -18,8 +18,16 @@
ce426f
    License along with the GNU C Library.  If not, see
ce426f
    <http://www.gnu.org/licenses/>.  */
ce426f
 
ce426f
+#if _CALL_ELF != 2
ce426f
 #define pltenter la_ppc64_gnu_pltenter
ce426f
 #define pltexit la_ppc64_gnu_pltexit
ce426f
 #define La_regs La_ppc64_regs
ce426f
 #define La_retval La_ppc64_retval
ce426f
 #define int_retval lrv_r3
ce426f
+#else
ce426f
+#define pltenter la_ppc64v2_gnu_pltenter
ce426f
+#define pltexit la_ppc64v2_gnu_pltexit
ce426f
+#define La_regs La_ppc64v2_regs
ce426f
+#define La_retval La_ppc64v2_retval
ce426f
+#define int_retval lrv_r3
ce426f
+#endif