bca718
commit 4603c51ef7989d7eb800cdd6f42aab206f891077
bca718
Author: Stefan Liebler <stli@linux.vnet.ibm.com>
bca718
Date:   Thu Mar 31 17:37:16 2016 +0200
bca718
bca718
    S390: Save and restore fprs/vrs while resolving symbols.
bca718
    
bca718
    On s390, no fpr/vrs were saved while resolving a symbol
bca718
    via _dl_runtime_resolve/_dl_runtime_profile.
bca718
    
bca718
    According to the abi, the fpr-arguments are defined as call clobbered.
bca718
    In leaf-functions, gcc 4.9 and newer can use fprs for saving/restoring gprs
bca718
    instead of saving them to the stack.
bca718
    If gcc do this in one of the resolver-functions, then the floating point
bca718
    arguments of a library-function are invalid for the first library-function-call.
bca718
    Thus, this patch saves/restores the fprs around the resolving code.
bca718
    
bca718
    The same could occur for vector registers. Furthermore an ifunc-resolver
bca718
    could also clobber the vector/floating point argument registers.
bca718
    Thus this patch provides the further variants _dl_runtime_resolve_vx/
bca718
    _dl_runtime_profile_vx, which are used if the kernel claims, that
bca718
    we run on a machine with vector registers.
bca718
    
bca718
    Furthermore, if _dl_runtime_profile calls _dl_call_pltexit,
bca718
    the pointers to inregs-/outregs-structs were setup invalid.
bca718
    Now they point to the correct location in the stack-frame.
bca718
    Before branching back to the caller, the return values are now
bca718
    restored instead of containing the return values of the
bca718
    _dl_call_pltexit() call.
bca718
    On s390-32, an endless loop occurs if _dl_call_pltexit() should be called.
bca718
    Now, this code-path branches to this function instead of just after the
bca718
    preceding basr-instruction.
bca718
    
bca718
    ChangeLog:
bca718
    
bca718
    	* sysdeps/s390/s390-32/dl-trampoline.S: Include dl-trampoline.h twice
bca718
    	to create a non-vector/vector version for _dl_runtime_resolve and
bca718
    	_dl_runtime_profile. Move implementation to ...
bca718
    	* sysdeps/s390/s390-32/dl-trampoline.h: ... here.
bca718
    	(_dl_runtime_resolve) Save and restore fpr/vrs.
bca718
    	(_dl_runtime_profile) Save and restore vrs and fix some issues
bca718
    	if _dl_call_pltexit is called.
bca718
    	* sysdeps/s390/s390-32/dl-machine.h (elf_machine_runtime_setup):
bca718
    	Choose the correct resolver function if running on a machine with vx.
bca718
    	* sysdeps/s390/s390-64/dl-trampoline.S: Include dl-trampoline.h twice
bca718
    	to create a non-vector/vector version for _dl_runtime_resolve and
bca718
    	_dl_runtime_profile. Move implementation to ...
bca718
    	* sysdeps/s390/s390-64/dl-trampoline.h: ... here.
bca718
    	(_dl_runtime_resolve) Save and restore fpr/vrs.
bca718
    	(_dl_runtime_profile) Save and restore vrs and fix some issues
bca718
    	* sysdeps/s390/s390-64/dl-machine.h: (elf_machine_runtime_setup):
bca718
    	Choose the correct resolver function if running on a machine with vx.
bca718
bca718
diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h
bca718
index 14bde3b..ec0ae4a 100644
bca718
--- a/sysdeps/s390/s390-32/dl-machine.h
bca718
+++ b/sysdeps/s390/s390-32/dl-machine.h
bca718
@@ -89,6 +89,11 @@
bca718
 {
bca718
   extern void _dl_runtime_resolve (Elf32_Word);
bca718
   extern void _dl_runtime_profile (Elf32_Word);
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+  extern void _dl_runtime_resolve_vx (Elf32_Word);
bca718
+  extern void _dl_runtime_profile_vx (Elf32_Word);
bca718
+#endif
bca718
+
bca718
 
bca718
   if (l->l_info[DT_JMPREL] && lazy)
bca718
     {
bca718
@@ -116,7 +121,14 @@
bca718
 	 end in this function.  */
bca718
       if (__builtin_expect (profile, 0))
bca718
 	{
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+	  if (GLRO(dl_hwcap) & HWCAP_S390_VX)
bca718
+	    got[2] = (Elf32_Addr) &_dl_runtime_profile_vx;
bca718
+	  else
bca718
+	    got[2] = (Elf32_Addr) &_dl_runtime_profile;
bca718
+#else
bca718
 	  got[2] = (Elf32_Addr) &_dl_runtime_profile;
bca718
+#endif
bca718
 
bca718
 	  if (GLRO(dl_profile) != NULL
bca718
 	      && _dl_name_match_p (GLRO(dl_profile), l))
bca718
@@ -125,9 +137,18 @@
bca718
 	    GL(dl_profile_map) = l;
bca718
 	}
bca718
       else
bca718
-	/* This function will get called to fix up the GOT entry indicated by
bca718
-	   the offset on the stack, and then jump to the resolved address.  */
bca718
-	got[2] = (Elf32_Addr) &_dl_runtime_resolve;
bca718
+	{
bca718
+	  /* This function will get called to fix up the GOT entry indicated by
bca718
+	     the offset on the stack, and then jump to the resolved address.  */
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+	  if (GLRO(dl_hwcap) & HWCAP_S390_VX)
bca718
+	    got[2] = (Elf32_Addr) &_dl_runtime_resolve_vx;
bca718
+	  else
bca718
+	    got[2] = (Elf32_Addr) &_dl_runtime_resolve;
bca718
+#else
bca718
+	  got[2] = (Elf32_Addr) &_dl_runtime_resolve;
bca718
+#endif
bca718
+	}
bca718
     }
bca718
 
bca718
   return lazy;
bca718
diff --git a/sysdeps/s390/s390-32/dl-trampoline.S b/sysdeps/s390/s390-32/dl-trampoline.S
bca718
index 1645610..859183c 100644
bca718
--- a/sysdeps/s390/s390-32/dl-trampoline.S
bca718
+++ b/sysdeps/s390/s390-32/dl-trampoline.S
bca718
@@ -16,130 +16,18 @@
bca718
    License along with the GNU C Library; if not, see
bca718
    <http://www.gnu.org/licenses/>.  */
bca718
 
bca718
-/* This code is used in dl-runtime.c to call the `fixup' function
bca718
-   and then redirect to the address it returns.  */
bca718
-
bca718
-/* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
bca718
- * with the following linkage:
bca718
- *   r2 - r6 : parameter registers
bca718
- *   f0, f2 : floating point parameter registers
bca718
- *   24(r15), 28(r15) : PLT arguments PLT1, PLT2
bca718
- *   96(r15) : additional stack parameters
bca718
- * The normal clobber rules for function calls apply:
bca718
- *   r0 - r5 : call clobbered
bca718
- *   r6 - r13 :	 call saved
bca718
- *   r14 : return address (call clobbered)
bca718
- *   r15 : stack pointer (call saved)
bca718
- *   f4, f6 : call saved
bca718
- *   f0 - f3, f5, f7 - f15 : call clobbered
bca718
- */
bca718
-
bca718
 #include <sysdep.h>
bca718
 
bca718
 	.text
bca718
-	.globl _dl_runtime_resolve
bca718
-	.type _dl_runtime_resolve, @function
bca718
-	cfi_startproc
bca718
-	.align 16
bca718
-_dl_runtime_resolve:
bca718
-	stm    %r2,%r5,32(%r15)		# save registers
bca718
-	st     %r14,8(%r15)
bca718
-	cfi_offset (r14, -88)
bca718
-	lr     %r0,%r15			# create stack frame
bca718
-	ahi    %r15,-96
bca718
-	cfi_adjust_cfa_offset (96)
bca718
-	st     0,0(%r15)
bca718
-	lm     %r2,%r3,120(%r15)	# load args saved by PLT
bca718
-	basr   %r1,0
bca718
-0:	l      %r14,1f-0b(%r1)
bca718
-	bas    %r14,0(%r14,%r1)		# call resolver
bca718
-	lr     %r1,%r2			# function addr returned in r2
bca718
-	ahi    %r15,96			# remove stack frame
bca718
-	cfi_adjust_cfa_offset (-96)
bca718
-	l      %r14,8(15)		# restore registers
bca718
-	lm     %r2,%r5,32(%r15)
bca718
-	br     %r1
bca718
-1:	.long  _dl_fixup - 0b
bca718
-	cfi_endproc
bca718
-	.size _dl_runtime_resolve, .-_dl_runtime_resolve
bca718
-
bca718
-
bca718
-#ifndef PROF
bca718
-	.globl _dl_runtime_profile
bca718
-	.type _dl_runtime_profile, @function
bca718
-	cfi_startproc
bca718
-	.align 16
bca718
-_dl_runtime_profile:
bca718
-	stm    %r2,%r6,32(%r15)		# save registers
bca718
-	std    %f0,56(%r15)
bca718
-	std    %f2,64(%r15)
bca718
-	st     %r6,8(%r15)
bca718
-	st     %r12,12(%r15)
bca718
-	st     %r14,16(%r15)
bca718
-	cfi_offset (r6, -64)
bca718
-	cfi_offset (f0, -40)
bca718
-	cfi_offset (f2, -32)
bca718
-	cfi_offset (r12, -84)
bca718
-	cfi_offset (r14, -80)
bca718
-	lr     %r12,%r15		# create stack frame
bca718
-	cfi_def_cfa_register (12)
bca718
-	ahi    %r15,-96
bca718
-	st     %r12,0(%r15)
bca718
-	lm     %r2,%r3,24(%r12)		# load arguments saved by PLT
bca718
-	lr     %r4,%r14			# return address as third parameter
bca718
-	basr   %r1,0
bca718
-0:	l      %r14,6f-0b(%r1)
bca718
-	la     %r5,32(%r12)		# pointer to struct La_s390_32_regs
bca718
-	la     %r6,20(%r12)		# long int * framesize
bca718
-	bas    %r14,0(%r14,%r1)		# call resolver
bca718
-	lr     %r1,%r2			# function addr returned in r2
bca718
-	icm    %r0,15,20(%r12)		# load & test framesize
bca718
-	jnm    2f
bca718
-
bca718
-	lm     %r2,%r6,32(%r12)
bca718
-	ld     %f0,56(%r12)
bca718
-	ld     %f2,64(%r12)
bca718
-	lr     %r15,%r12		# remove stack frame
bca718
-	cfi_def_cfa_register (15)
bca718
-	l      %r14,16(%r15)		# restore registers
bca718
-	l      %r12,12(%r15)
bca718
-	br     %r1			# tail-call to the resolved function
bca718
-
bca718
-	cfi_def_cfa_register (12)
bca718
-2:	jz     4f			# framesize == 0 ?
bca718
-	ahi    %r0,7			# align framesize to 8
bca718
-	lhi    %r2,-8
bca718
-	nr     %r0,%r2
bca718
-	slr    %r15,%r0			# make room for framesize bytes
bca718
-	st     %r12,0(%r15)
bca718
-	la     %r2,96(%r15)
bca718
-	la     %r3,96(%r12)
bca718
-	srl    %r0,3
bca718
-3:	mvc    0(8,%r2),0(%r3)		# copy additional parameters
bca718
-	la     %r2,8(%r2)
bca718
-	la     %r3,8(%r3)
bca718
-	brct   %r0,3b
bca718
-4:	lm     %r2,%r6,32(%r12)		# load register parameters
bca718
-	ld     %f0,56(%r12)
bca718
-	ld     %f2,64(%r12)
bca718
-	basr   %r14,%r1			# call resolved function
bca718
-	stm    %r2,%r3,72(%r12)
bca718
-	std    %f0,80(%r12)
bca718
-	lm     %r2,%r3,24(%r12)		# load arguments saved by PLT
bca718
-	basr   %r1,0
bca718
-5:	l      %r14,7f-5b(%r1)
bca718
-	la     %r4,32(%r12)		# pointer to struct La_s390_32_regs
bca718
-	la     %r5,72(%r12)		# pointer to struct La_s390_32_retval
bca718
-	basr   %r14,%r1			# call _dl_call_pltexit
bca718
-
bca718
-	lr     %r15,%r12		# remove stack frame
bca718
-	cfi_def_cfa_register (15)
bca718
-	l      %r14,16(%r15)		# restore registers
bca718
-	l      %r12,12(%r15)
bca718
-	br     %r14
bca718
-
bca718
-6:	.long  _dl_profile_fixup - 0b
bca718
-7:	.long  _dl_call_pltexit - 5b
bca718
-	cfi_endproc
bca718
-	.size _dl_runtime_profile, .-_dl_runtime_profile
bca718
+/* Create variant of _dl_runtime_resolve/profile for machines before z13.
bca718
+   No vector registers are saved/restored.  */
bca718
+#include <dl-trampoline.h>
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+/* Create variant of _dl_runtime_resolve/profile for z13 and newer.
bca718
+   The vector registers are saved/restored, too.*/
bca718
+# define _dl_runtime_resolve _dl_runtime_resolve_vx
bca718
+# define _dl_runtime_profile _dl_runtime_profile_vx
bca718
+# define RESTORE_VRS
bca718
+# include <dl-trampoline.h>
bca718
 #endif
bca718
diff --git a/sysdeps/s390/s390-32/dl-trampoline.h b/sysdeps/s390/s390-32/dl-trampoline.h
bca718
new file mode 100644
bca718
index 0000000..a152a7b
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/s390-32/dl-trampoline.h
bca718
@@ -0,0 +1,215 @@
bca718
+/* PLT trampolines.  s390 version.
bca718
+   Copyright (C) 2016 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+/* This code is used in dl-runtime.c to call the `fixup' function
bca718
+   and then redirect to the address it returns.  */
bca718
+
bca718
+/* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
bca718
+ * with the following linkage:
bca718
+ *   r2 - r6 : parameter registers
bca718
+ *   f0, f2 : floating point parameter registers
bca718
+ *   v24, v26, v28, v30, v25, v27, v29, v31 : vector parameter registers
bca718
+ *   24(r15), 28(r15) : PLT arguments PLT1, PLT2
bca718
+ *   96(r15) : additional stack parameters
bca718
+ * The normal clobber rules for function calls apply:
bca718
+ *   r0 - r5 : call clobbered
bca718
+ *   r6 - r13 :	call saved
bca718
+ *   r14 : return address (call clobbered)
bca718
+ *   r15 : stack pointer (call saved)
bca718
+ *   f4, f6 : call saved
bca718
+ *   f0 - f3, f5, f7 - f15 : call clobbered
bca718
+ *   v0 - v3, v5, v7 - v15 : bytes 0-7 overlap with fprs: call clobbered
bca718
+               bytes 8-15: call clobbered
bca718
+ *   v4, v6 : bytes 0-7 overlap with f4, f6: call saved
bca718
+              bytes 8-15: call clobbered
bca718
+ *   v16 - v31 : call clobbered
bca718
+ */
bca718
+
bca718
+
bca718
+	.globl _dl_runtime_resolve
bca718
+	.type _dl_runtime_resolve, @function
bca718
+	cfi_startproc
bca718
+	.align 16
bca718
+_dl_runtime_resolve:
bca718
+	stm    %r2,%r5,32(%r15)		# save registers
bca718
+	cfi_offset (r2, -64)
bca718
+	cfi_offset (r3, -60)
bca718
+	cfi_offset (r4, -56)
bca718
+	cfi_offset (r5, -52)
bca718
+	std    %f0,56(%r15)
bca718
+	cfi_offset (f0, -40)
bca718
+	std    %f2,64(%r15)
bca718
+	cfi_offset (f2, -32)
bca718
+	st     %r14,8(%r15)
bca718
+	cfi_offset (r14, -88)
bca718
+	lr     %r0,%r15
bca718
+	lm     %r2,%r3,24(%r15)		# load args saved by PLT
bca718
+#ifdef RESTORE_VRS
bca718
+	ahi    %r15,-224		# create stack frame
bca718
+	cfi_adjust_cfa_offset (224)
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+	vstm   %v24,%v31,96(%r15)	# store call-clobbered vr arguments
bca718
+	cfi_offset (v24, -224)
bca718
+	cfi_offset (v25, -208)
bca718
+	cfi_offset (v26, -192)
bca718
+	cfi_offset (v27, -176)
bca718
+	cfi_offset (v28, -160)
bca718
+	cfi_offset (v29, -144)
bca718
+	cfi_offset (v30, -128)
bca718
+	cfi_offset (v31, -112)
bca718
+	.machine pop
bca718
+#else
bca718
+	ahi    %r15,-96			# create stack frame
bca718
+	cfi_adjust_cfa_offset (96)
bca718
+#endif
bca718
+	st     %r0,0(%r15)		# write backchain
bca718
+	basr   %r1,0
bca718
+0:	l      %r14,1f-0b(%r1)
bca718
+	bas    %r14,0(%r14,%r1)		# call _dl_fixup
bca718
+	lr     %r1,%r2			# function addr returned in r2
bca718
+#ifdef RESTORE_VRS
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+	vlm    %v24,%v31,96(%r15)	# restore vector registers
bca718
+	.machine pop
bca718
+	aghi   %r15,224			# remove stack frame
bca718
+	cfi_adjust_cfa_offset (-224)
bca718
+#else
bca718
+	ahi    %r15,96			# remove stack frame
bca718
+	cfi_adjust_cfa_offset (-96)
bca718
+#endif
bca718
+	l      %r14,8(15)		# restore registers
bca718
+	ld     %f0,56(%r15)
bca718
+	ld     %f2,64(%r15)
bca718
+	lm     %r2,%r5,32(%r15)
bca718
+	br     %r1
bca718
+1:	.long  _dl_fixup - 0b
bca718
+	cfi_endproc
bca718
+	.size _dl_runtime_resolve, .-_dl_runtime_resolve
bca718
+
bca718
+
bca718
+#ifndef PROF
bca718
+	.globl _dl_runtime_profile
bca718
+	.type _dl_runtime_profile, @function
bca718
+	cfi_startproc
bca718
+	.align 16
bca718
+_dl_runtime_profile:
bca718
+	stm    %r2,%r6,32(%r15)		# save registers
bca718
+	cfi_offset (r2, -64)		# + r6 needed as arg for
bca718
+	cfi_offset (r3, -60)		#  _dl_profile_fixup
bca718
+	cfi_offset (r4, -56)
bca718
+	cfi_offset (r5, -52)
bca718
+	cfi_offset (r6, -48)
bca718
+	std    %f0,56(%r15)
bca718
+	cfi_offset (f0, -40)
bca718
+	std    %f2,64(%r15)
bca718
+	cfi_offset (f2, -32)
bca718
+	st     %r12,12(%r15)		# r12 is used as backup of r15
bca718
+	cfi_offset (r12, -84)
bca718
+	st     %r14,16(%r15)
bca718
+	cfi_offset (r14, -80)
bca718
+	lr     %r12,%r15		# backup stack pointer
bca718
+	cfi_def_cfa_register (12)
bca718
+#ifdef RESTORE_VRS
bca718
+	ahi    %r15,-224		# create stack frame
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+	vstm   %v24,%v31,96(%r15)	# store call-clobbered vr arguments
bca718
+	cfi_offset (v24, -224)
bca718
+	cfi_offset (v25, -208)
bca718
+	cfi_offset (v26, -192)
bca718
+	cfi_offset (v27, -176)
bca718
+	cfi_offset (v28, -160)
bca718
+	cfi_offset (v29, -144)
bca718
+	cfi_offset (v30, -128)
bca718
+	cfi_offset (v31, -112)
bca718
+	.machine pop
bca718
+#else
bca718
+	ahi    %r15,-96			# create stack frame
bca718
+#endif
bca718
+	st     %r12,0(%r15)		# save backchain
bca718
+	lm     %r2,%r3,24(%r12)		# load arguments saved by PLT
bca718
+	lr     %r4,%r14			# return address as third parameter
bca718
+	basr   %r1,0
bca718
+0:	l      %r14,6f-0b(%r1)
bca718
+	la     %r5,32(%r12)		# pointer to struct La_s390_32_regs
bca718
+	la     %r6,20(%r12)		# long int * framesize
bca718
+	bas    %r14,0(%r14,%r1)		# call resolver
bca718
+	lr     %r1,%r2			# function addr returned in r2
bca718
+	ld     %f0,56(%r12)		# restore call-clobbered arg fprs
bca718
+	ld     %f2,64(%r12)
bca718
+#ifdef RESTORE_VRS
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+	vlm    %v24,%v31,96(%r15)	# restore call-clobbered arg vrs
bca718
+	.machine pop
bca718
+#endif
bca718
+	icm    %r0,15,20(%r12)		# load & test framesize
bca718
+	jnm    2f
bca718
+
bca718
+	lm     %r2,%r6,32(%r12)
bca718
+	lr     %r15,%r12		# remove stack frame
bca718
+	cfi_def_cfa_register (15)
bca718
+	l      %r14,16(%r15)		# restore registers
bca718
+	l      %r12,12(%r15)
bca718
+	br     %r1			# tail-call to the resolved function
bca718
+
bca718
+	cfi_def_cfa_register (12)
bca718
+2:	jz     4f			# framesize == 0 ?
bca718
+	ahi    %r0,7			# align framesize to 8
bca718
+	lhi    %r2,-8
bca718
+	nr     %r0,%r2
bca718
+	slr    %r15,%r0			# make room for framesize bytes
bca718
+	st     %r12,0(%r15)		# save backchain
bca718
+	la     %r2,96(%r15)
bca718
+	la     %r3,96(%r12)
bca718
+	srl    %r0,3
bca718
+3:	mvc    0(8,%r2),0(%r3)		# copy additional parameters
bca718
+	la     %r2,8(%r2)
bca718
+	la     %r3,8(%r3)
bca718
+	brct   %r0,3b
bca718
+4:	lm     %r2,%r6,32(%r12)		# load register parameters
bca718
+	basr   %r14,%r1			# call resolved function
bca718
+	stm    %r2,%r3,72(%r12)		# store return values r2, r3, f0
bca718
+	std    %f0,80(%r12)		# to struct La_s390_32_retval
bca718
+	lm     %r2,%r3,24(%r12)		# load arguments saved by PLT
bca718
+	basr   %r1,0
bca718
+5:	l      %r14,7f-5b(%r1)
bca718
+	la     %r4,32(%r12)		# pointer to struct La_s390_32_regs
bca718
+	la     %r5,72(%r12)		# pointer to struct La_s390_32_retval
bca718
+	bas    %r14,0(%r14,%r1)		# call _dl_call_pltexit
bca718
+
bca718
+	lr     %r15,%r12		# remove stack frame
bca718
+	cfi_def_cfa_register (15)
bca718
+	l      %r14,16(%r15)		# restore registers
bca718
+	l      %r12,12(%r15)
bca718
+	l      %r2,72(%r15)		# restore return values
bca718
+	l      %r3,76(%r15)
bca718
+	ld     %f0,80(%r15)
bca718
+	br     %r14
bca718
+
bca718
+6:	.long  _dl_profile_fixup - 0b
bca718
+7:	.long  _dl_call_pltexit - 5b
bca718
+	cfi_endproc
bca718
+	.size _dl_runtime_profile, .-_dl_runtime_profile
bca718
+#endif
bca718
diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h
bca718
index cb81aaf..9ee7c92 100644
bca718
--- a/sysdeps/s390/s390-64/dl-machine.h
bca718
+++ b/sysdeps/s390/s390-64/dl-machine.h
bca718
@@ -26,6 +26,7 @@
bca718
 #include <sys/param.h>
bca718
 #include <string.h>
bca718
 #include <link.h>
bca718
+#include <sysdeps/s390/dl-procinfo.h>
bca718
 #include <dl-irel.h>
bca718
 
bca718
 #define ELF_MACHINE_IRELATIVE       R_390_IRELATIVE
bca718
@@ -78,6 +79,10 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
bca718
 {
bca718
   extern void _dl_runtime_resolve (Elf64_Word);
bca718
   extern void _dl_runtime_profile (Elf64_Word);
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+  extern void _dl_runtime_resolve_vx (Elf64_Word);
bca718
+  extern void _dl_runtime_profile_vx (Elf64_Word);
bca718
+#endif
bca718
 
bca718
   if (l->l_info[DT_JMPREL] && lazy)
bca718
     {
bca718
@@ -105,7 +110,14 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
bca718
 	 end in this function.	*/
bca718
       if (__builtin_expect (profile, 0))
bca718
 	{
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+	  if (GLRO(dl_hwcap) & HWCAP_S390_VX)
bca718
+	    got[2] = (Elf64_Addr) &_dl_runtime_profile_vx;
bca718
+	  else
bca718
+	    got[2] = (Elf64_Addr) &_dl_runtime_profile;
bca718
+#else
bca718
 	  got[2] = (Elf64_Addr) &_dl_runtime_profile;
bca718
+#endif
bca718
 
bca718
 	  if (GLRO(dl_profile) != NULL
bca718
 	      && _dl_name_match_p (GLRO(dl_profile), l))
bca718
@@ -114,9 +126,18 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
bca718
 	    GL(dl_profile_map) = l;
bca718
 	}
bca718
       else
bca718
-	/* This function will get called to fix up the GOT entry indicated by
bca718
-	   the offset on the stack, and then jump to the resolved address.  */
bca718
-	got[2] = (Elf64_Addr) &_dl_runtime_resolve;
bca718
+	{
bca718
+	  /* This function will get called to fix up the GOT entry indicated by
bca718
+	     the offset on the stack, and then jump to the resolved address.  */
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+	  if (GLRO(dl_hwcap) & HWCAP_S390_VX)
bca718
+	    got[2] = (Elf64_Addr) &_dl_runtime_resolve_vx;
bca718
+	  else
bca718
+	    got[2] = (Elf64_Addr) &_dl_runtime_resolve;
bca718
+#else
bca718
+	  got[2] = (Elf64_Addr) &_dl_runtime_resolve;
bca718
+#endif
bca718
+	}
bca718
     }
bca718
 
bca718
   return lazy;
bca718
diff --git a/sysdeps/s390/s390-64/dl-trampoline.S b/sysdeps/s390/s390-64/dl-trampoline.S
bca718
index 6919ed0..1b0c9e2 100644
bca718
--- a/sysdeps/s390/s390-64/dl-trampoline.S
bca718
+++ b/sysdeps/s390/s390-64/dl-trampoline.S
bca718
@@ -16,126 +16,18 @@
bca718
    License along with the GNU C Library; if not, see
bca718
    <http://www.gnu.org/licenses/>.  */
bca718
 
bca718
-/* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
bca718
- * with the following linkage:
bca718
- *   r2 - r6 : parameter registers
bca718
- *   f0, f2, f4, f6 : floating point parameter registers
bca718
- *   48(r15), 56(r15) : PLT arguments PLT1, PLT2
bca718
- *   160(r15) : additional stack parameters
bca718
- * The normal clobber rules for function calls apply:
bca718
- *   r0 - r5 : call clobbered
bca718
- *   r6 - r13 :	 call saved
bca718
- *   r14 : return address (call clobbered)
bca718
- *   r15 : stack pointer (call saved)
bca718
- *   f1, f3, f5, f7 : call saved
bca718
- *   f0 - f3, f5, f7 - f15 : call clobbered
bca718
- */
bca718
-
bca718
 #include <sysdep.h>
bca718
 
bca718
 	.text
bca718
-	.globl _dl_runtime_resolve
bca718
-	.type _dl_runtime_resolve, @function
bca718
-	cfi_startproc
bca718
-	.align 16
bca718
-_dl_runtime_resolve:
bca718
-	stmg   %r2,%r5,64(15)	# save call-clobbered argument registers
bca718
-	stg    %r14,96(15)
bca718
-	cfi_offset (r14, -64)
bca718
-	lgr    %r0,%r15
bca718
-	aghi   %r15,-160	# create stack frame
bca718
-	cfi_adjust_cfa_offset (160)
bca718
-	stg    %r0,0(%r15)      # write backchain
bca718
-	lmg    %r2,%r3,208(%r15)# load args saved by PLT
bca718
-	brasl  %r14,_dl_fixup	# call fixup
bca718
-	lgr    %r1,%r2		# function addr returned in r2
bca718
-	aghi   %r15,160		# remove stack frame
bca718
-	cfi_adjust_cfa_offset (-160)
bca718
-	lg     %r14,96(15)	# restore registers
bca718
-	lmg    %r2,%r5,64(15)
bca718
-	br     %r1
bca718
-	cfi_endproc
bca718
-	.size _dl_runtime_resolve, .-_dl_runtime_resolve
bca718
-
bca718
-
bca718
-#ifndef PROF
bca718
-	.globl _dl_runtime_profile
bca718
-	.type _dl_runtime_profile, @function
bca718
-	cfi_startproc
bca718
-	.align 16
bca718
-_dl_runtime_profile:
bca718
-	stmg   %r2,%r6,64(%r15)		# save call-clobbered arg regs
bca718
-	std    %f0,104(%r15)		# + r6 needed as arg for
bca718
-	std    %f2,112(%r15)		#  _dl_profile_fixup
bca718
-	std    %f4,120(%r15)
bca718
-	std    %f6,128(%r15)
bca718
-	stg    %r12,24(%r15)		# r12 is used as backup of r15
bca718
-	stg    %r14,32(%r15)
bca718
-	cfi_offset (r6, -96)
bca718
-	cfi_offset (f0, -56)
bca718
-	cfi_offset (f2, -48)
bca718
-	cfi_offset (f4, -40)
bca718
-	cfi_offset (f6, -32)
bca718
-	cfi_offset (r12, -136)
bca718
-	cfi_offset (r14, -128)
bca718
-	lgr    %r12,%r15		# backup stack pointer
bca718
-	cfi_def_cfa_register (12)
bca718
-	aghi   %r15,-160		# create stack frame
bca718
-	stg    %r12,0(%r15)		# save backchain
bca718
-	lmg    %r2,%r3,48(%r12)		# load arguments saved by PLT
bca718
-	lgr    %r4,%r14			# return address as third parameter
bca718
-	la     %r5,64(%r12)		# pointer to struct La_s390_32_regs
bca718
-	la     %r6,40(%r12)		# long int * framesize
bca718
-	brasl  %r14,_dl_profile_fixup	# call resolver
bca718
-	lgr    %r1,%r2			# function addr returned in r2
bca718
-	lg     %r0,40(%r12)		# load framesize
bca718
-	ltgr   %r0,%r0
bca718
-	jnm    1f
bca718
-
bca718
-	lmg    %r2,%r6,64(%r12)		# framesize < 0 means no pltexit call
bca718
-	ld     %f0,104(%r12)		# so we can do a tail call without
bca718
-	ld     %f2,112(%r12)		# copying the arg overflow area
bca718
-	ld     %f4,120(%r12)
bca718
-	ld     %f6,128(%r12)
bca718
-
bca718
-	lgr    %r15,%r12		# remove stack frame
bca718
-	cfi_def_cfa_register (15)
bca718
-	lg     %r14,32(%r15)		# restore registers
bca718
-	lg     %r12,24(%r15)
bca718
-	br     %r1			# tail-call to resolved function
bca718
-
bca718
-	cfi_def_cfa_register (12)
bca718
-1:	jz     4f			# framesize == 0 ?
bca718
-	aghi   %r0,7			# align framesize to 8
bca718
-	nill   %r0,0xfff8
bca718
-	slgr   %r15,%r0			# make room for framesize bytes
bca718
-	stg    %r12,0(%r15)
bca718
-	la     %r2,160(%r15)
bca718
-	la     %r3,160(%r12)
bca718
-	srlg   %r0,%r0,3
bca718
-3:	mvc    0(8,%r2),0(%r3)		# copy additional parameters
bca718
-	la     %r2,8(%r2)
bca718
-	la     %r3,8(%r3)
bca718
-	brctg  %r0,3b
bca718
-4:	lmg    %r2,%r6,64(%r12)		# load register parameters
bca718
-	ld     %f0,104(%r12)            # restore call-clobbered arg regs
bca718
-	ld     %f2,112(%r12)
bca718
-	ld     %f4,120(%r12)
bca718
-	ld     %f6,128(%r12)
bca718
-	basr   %r14,%r1			# call resolved function
bca718
-	stg    %r2,136(%r12)
bca718
-	std    %f0,144(%r12)
bca718
-	lmg    %r2,%r3,48(%r12)		# load arguments saved by PLT
bca718
-	la     %r4,32(%r12)		# pointer to struct La_s390_32_regs
bca718
-	la     %r5,72(%r12)		# pointer to struct La_s390_32_retval
bca718
-	brasl  %r14,_dl_call_pltexit
bca718
-
bca718
-	lgr    %r15,%r12		# remove stack frame
bca718
-	cfi_def_cfa_register (15)
bca718
-	lg     %r14,32(%r15)		# restore registers
bca718
-	lg     %r12,24(%r15)
bca718
-	br     %r14
bca718
-
bca718
-	cfi_endproc
bca718
-	.size _dl_runtime_profile, .-_dl_runtime_profile
bca718
+/* Create variant of _dl_runtime_resolve/profile for machines before z13.
bca718
+   No vector registers are saved/restored.  */
bca718
+#include <dl-trampoline.h>
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT
bca718
+/* Create variant of _dl_runtime_resolve/profile for z13 and newer.
bca718
+   The vector registers are saved/restored, too.*/
bca718
+# define _dl_runtime_resolve _dl_runtime_resolve_vx
bca718
+# define _dl_runtime_profile _dl_runtime_profile_vx
bca718
+# define RESTORE_VRS
bca718
+# include <dl-trampoline.h>
bca718
 #endif
bca718
diff --git a/sysdeps/s390/s390-64/dl-trampoline.h b/sysdeps/s390/s390-64/dl-trampoline.h
bca718
new file mode 100644
bca718
index 0000000..658e3a3
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/s390-64/dl-trampoline.h
bca718
@@ -0,0 +1,211 @@
bca718
+/* PLT trampolines.  s390x version.
bca718
+   Copyright (C) 2016 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+/* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
bca718
+ * with the following linkage:
bca718
+ *   r2 - r6 : parameter registers
bca718
+ *   f0, f2, f4, f6 : floating point parameter registers
bca718
+ *   v24, v26, v28, v30, v25, v27, v29, v31 : vector parameter registers
bca718
+ *   48(r15), 56(r15) : PLT arguments PLT1, PLT2
bca718
+ *   160(r15) : additional stack parameters
bca718
+ * The normal clobber rules for function calls apply:
bca718
+ *   r0 - r5 : call clobbered
bca718
+ *   r6 - r13 :	 call saved
bca718
+ *   r14 : return address (call clobbered)
bca718
+ *   r15 : stack pointer (call saved)
bca718
+ *   f0 - f7 : call clobbered
bca718
+ *   f8 - f15 : call saved
bca718
+ *   v0 - v7 : bytes 0-7 overlap with f0-f7: call clobbered
bca718
+               bytes 8-15: call clobbered
bca718
+ *   v8 - v15 : bytes 0-7 overlap with f8-f15: call saved
bca718
+                bytes 8-15: call clobbered
bca718
+ *   v16 - v31 : call clobbered
bca718
+ */
bca718
+
bca718
+	.globl _dl_runtime_resolve
bca718
+	.type _dl_runtime_resolve, @function
bca718
+	cfi_startproc
bca718
+	.align 16
bca718
+_dl_runtime_resolve:
bca718
+	stmg   %r2,%r5,64(%r15)	# save call-clobbered argument registers
bca718
+	cfi_offset (r2, -96)
bca718
+	cfi_offset (r3, -88)
bca718
+	cfi_offset (r4, -80)
bca718
+	cfi_offset (r5, -72)
bca718
+	std    %f0,104(%r15)
bca718
+	cfi_offset (f0, -56)
bca718
+	std    %f2,112(%r15)
bca718
+	cfi_offset (f2, -48)
bca718
+	std    %f4,120(%r15)
bca718
+	cfi_offset (f4, -40)
bca718
+	std    %f6,128(%r15)
bca718
+	cfi_offset (f6, -32)
bca718
+	stg    %r14,96(15)
bca718
+	cfi_offset (r14, -64)
bca718
+	lmg    %r2,%r3,48(%r15) # load args for fixup saved by PLT
bca718
+	lgr    %r0,%r15
bca718
+#ifdef RESTORE_VRS
bca718
+	aghi   %r15,-288        # create stack frame
bca718
+	cfi_adjust_cfa_offset (288)
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	vstm   %v24,%v31,160(%r15)# store call-clobbered vector argument registers
bca718
+	cfi_offset (v24, -288)
bca718
+	cfi_offset (v25, -272)
bca718
+	cfi_offset (v26, -256)
bca718
+	cfi_offset (v27, -240)
bca718
+	cfi_offset (v28, -224)
bca718
+	cfi_offset (v29, -208)
bca718
+	cfi_offset (v30, -192)
bca718
+	cfi_offset (v31, -176)
bca718
+	.machine pop
bca718
+#else
bca718
+	aghi   %r15,-160        # create stack frame
bca718
+	cfi_adjust_cfa_offset (160)
bca718
+#endif
bca718
+	stg    %r0,0(%r15)      # write backchain
bca718
+	brasl  %r14,_dl_fixup	# call _dl_fixup
bca718
+	lgr    %r1,%r2		# function addr returned in r2
bca718
+#ifdef RESTORE_VRS
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	vlm    %v24,%v31,160(%r15)# restore vector registers
bca718
+	.machine pop
bca718
+	aghi   %r15,288         # remove stack frame
bca718
+	cfi_adjust_cfa_offset (-288)
bca718
+#else
bca718
+	aghi   %r15,160         # remove stack frame
bca718
+	cfi_adjust_cfa_offset (-160)
bca718
+#endif
bca718
+	lg     %r14,96(%r15)	# restore registers
bca718
+	ld     %f0,104(%r15)
bca718
+	ld     %f2,112(%r15)
bca718
+	ld     %f4,120(%r15)
bca718
+	ld     %f6,128(%r15)
bca718
+	lmg    %r2,%r5,64(%r15)
bca718
+	br     %r1
bca718
+	cfi_endproc
bca718
+	.size _dl_runtime_resolve, .-_dl_runtime_resolve
bca718
+
bca718
+
bca718
+#ifndef PROF
bca718
+	.globl _dl_runtime_profile
bca718
+	.type _dl_runtime_profile, @function
bca718
+	cfi_startproc
bca718
+	.align 16
bca718
+_dl_runtime_profile:
bca718
+	stmg   %r2,%r6,64(%r15)		# save call-clobbered arg regs
bca718
+	cfi_offset (r2, -96)		# + r6 needed as arg for
bca718
+	cfi_offset (r3, -88)		#  _dl_profile_fixup
bca718
+	cfi_offset (r4, -80)
bca718
+	cfi_offset (r5, -72)
bca718
+	cfi_offset (r6, -64)
bca718
+	std    %f0,104(%r15)
bca718
+	cfi_offset (f0, -56)
bca718
+	std    %f2,112(%r15)
bca718
+	cfi_offset (f2, -48)
bca718
+	std    %f4,120(%r15)
bca718
+	cfi_offset (f4, -40)
bca718
+	std    %f6,128(%r15)
bca718
+	cfi_offset (f6, -32)
bca718
+	stg    %r12,24(%r15)		# r12 is used as backup of r15
bca718
+	cfi_offset (r12, -136)
bca718
+	stg    %r14,32(%r15)
bca718
+	cfi_offset (r14, -128)
bca718
+	lgr    %r12,%r15		# backup stack pointer
bca718
+	cfi_def_cfa_register (12)
bca718
+#ifdef RESTORE_VRS
bca718
+	aghi   %r15,-288		# create stack frame
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	vstm   %v24,%v31,160(%r15)# store call-clobbered vector argument registers
bca718
+	cfi_offset (v24, -288)
bca718
+	cfi_offset (v25, -272)
bca718
+	cfi_offset (v26, -256)
bca718
+	cfi_offset (v27, -240)
bca718
+	cfi_offset (v28, -224)
bca718
+	cfi_offset (v29, -208)
bca718
+	cfi_offset (v30, -192)
bca718
+	cfi_offset (v31, -176)
bca718
+	.machine pop
bca718
+#else
bca718
+	aghi   %r15,-160		# create stack frame
bca718
+#endif
bca718
+	stg    %r12,0(%r15)		# save backchain
bca718
+	lmg    %r2,%r3,48(%r12)		# load arguments saved by PLT
bca718
+	lgr    %r4,%r14			# return address as third parameter
bca718
+	la     %r5,64(%r12)		# pointer to struct La_s390_64_regs
bca718
+	la     %r6,40(%r12)		# long int * framesize
bca718
+	brasl  %r14,_dl_profile_fixup	# call resolver
bca718
+	lgr    %r1,%r2			# function addr returned in r2
bca718
+	ld     %f0,104(%r12)		# restore call-clobbered arg fprs
bca718
+	ld     %f2,112(%r12)
bca718
+	ld     %f4,120(%r12)
bca718
+	ld     %f6,128(%r12)
bca718
+#ifdef RESTORE_VRS
bca718
+	.machine push
bca718
+	.machine "z13"
bca718
+	vlm    %v24,%v31,160(%r15)	# restore call-clobbered arg vrs
bca718
+	.machine pop
bca718
+#endif
bca718
+	lg     %r0,40(%r12)		# load framesize
bca718
+	ltgr   %r0,%r0
bca718
+	jnm    1f
bca718
+
bca718
+	lmg    %r2,%r6,64(%r12)		# framesize < 0 means no pltexit call
bca718
+					# so we can do a tail call without
bca718
+					# copying the arg overflow area
bca718
+	lgr    %r15,%r12		# remove stack frame
bca718
+	cfi_def_cfa_register (15)
bca718
+	lg     %r14,32(%r15)		# restore registers
bca718
+	lg     %r12,24(%r15)
bca718
+	br     %r1			# tail-call to resolved function
bca718
+
bca718
+	cfi_def_cfa_register (12)
bca718
+1:	jz     4f			# framesize == 0 ?
bca718
+	aghi   %r0,7			# align framesize to 8
bca718
+	nill   %r0,0xfff8
bca718
+	slgr   %r15,%r0			# make room for framesize bytes
bca718
+	stg    %r12,0(%r15)		# save backchain
bca718
+	la     %r2,160(%r15)
bca718
+	la     %r3,160(%r12)
bca718
+	srlg   %r0,%r0,3
bca718
+3:	mvc    0(8,%r2),0(%r3)		# copy additional parameters
bca718
+	la     %r2,8(%r2)		# depending on framesize
bca718
+	la     %r3,8(%r3)
bca718
+	brctg  %r0,3b
bca718
+4:	lmg    %r2,%r6,64(%r12)		# restore call-clobbered arg gprs
bca718
+	basr   %r14,%r1			# call resolved function
bca718
+	stg    %r2,136(%r12)		# store return values r2, f0
bca718
+	std    %f0,144(%r12)		# to struct La_s390_64_retval
bca718
+	lmg    %r2,%r3,48(%r12)		# load arguments saved by PLT
bca718
+	la     %r4,64(%r12)		# pointer to struct La_s390_64_regs
bca718
+	la     %r5,136(%r12)		# pointer to struct La_s390_64_retval
bca718
+	brasl  %r14,_dl_call_pltexit
bca718
+
bca718
+	lgr    %r15,%r12		# remove stack frame
bca718
+	cfi_def_cfa_register (15)
bca718
+	lg     %r14,32(%r15)		# restore registers
bca718
+	lg     %r12,24(%r15)
bca718
+	lg     %r2,136(%r15)		# restore return values
bca718
+	ld     %f0,144(%r15)
bca718
+	br     %r14			# Jump back to caller
bca718
+
bca718
+	cfi_endproc
bca718
+	.size _dl_runtime_profile, .-_dl_runtime_profile
bca718
+#endif