arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-ppc64le-42.patch

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