|
|
5de29b |
#
|
|
|
5de29b |
# commit 76a9b9986141b1a7d9fd290c349d27fcee780c7a
|
|
|
5de29b |
# Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
|
|
|
5de29b |
# Date: Thu Nov 7 05:34:22 2013 -0600
|
|
|
5de29b |
#
|
|
|
5de29b |
# PowerPC: Fix vDSO missing ODP entries
|
|
|
5de29b |
#
|
|
|
5de29b |
# This patch fixes the vDSO symbol used directed in IFUNC resolver where
|
|
|
5de29b |
# they do not have an associated ODP entry leading to undefined behavior
|
|
|
5de29b |
# in some cases. It adds an artificial OPD static entry to such cases
|
|
|
5de29b |
# and set its TOC to non 0 to avoid triggering lazy resolutions.
|
|
|
5de29b |
#
|
|
|
12745e |
diff -urN glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
|
|
|
5de29b |
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h 2015-01-15 16:05:08.853681325 -0500
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h 2015-01-15 16:06:11.451747716 -0500
|
|
|
5de29b |
@@ -34,12 +34,32 @@
|
|
|
5de29b |
|
|
|
5de29b |
extern void *__vdso_time;
|
|
|
5de29b |
|
|
|
5de29b |
-/* This macro is needed for PPC64 to return a skeleton OPD entry of a vDSO
|
|
|
5de29b |
- symbol. This works because _dl_vdso_vsym always return the function
|
|
|
5de29b |
- address, and no vDSO symbols use the TOC or chain pointers from the OPD
|
|
|
5de29b |
- so we can allow them to be garbage. */
|
|
|
5de29b |
-#if defined(__PPC64__) || defined(__powerpc64__)
|
|
|
5de29b |
-#define VDSO_IFUNC_RET(value) ((void *) &(value))
|
|
|
5de29b |
+/* The correct solution is for _dl_vdso_vsym to return the address of the OPD
|
|
|
5de29b |
+ for the kernel VDSO function. That address would then be stored in the
|
|
|
5de29b |
+ __vdso_* variables and returned as the result of the IFUNC resolver function.
|
|
|
5de29b |
+ Yet, the kernel does not contain any OPD entries for the VDSO functions
|
|
|
5de29b |
+ (incomplete implementation). However, PLT relocations for IFUNCs still expect
|
|
|
5de29b |
+ the address of an OPD to be returned from the IFUNC resolver function (since
|
|
|
5de29b |
+ PLT entries on PPC64 are just copies of OPDs). The solution for now is to
|
|
|
5de29b |
+ create an artificial static OPD for each VDSO function returned by a resolver
|
|
|
5de29b |
+ function. The TOC value is set to a non-zero value to avoid triggering lazy
|
|
|
5de29b |
+ symbol resolution via .glink0/.plt0 for a zero TOC (requires thread-safe PLT
|
|
|
5de29b |
+ sequences) when the dynamic linker isn't prepared for it e.g. RTLD_NOW. None
|
|
|
5de29b |
+ of the kernel VDSO routines use the TOC or AUX values so any non-zero value
|
|
|
5de29b |
+ will work. Note that function pointer comparisons will not use this artificial
|
|
|
5de29b |
+ static OPD since those are resolved via ADDR64 relocations and will point at
|
|
|
5de29b |
+ the non-IFUNC default OPD for the symbol. Lastly, because the IFUNC relocations
|
|
|
5de29b |
+ are processed immediately at startup the resolver functions and this code need
|
|
|
5de29b |
+ not be thread-safe, but if the caller writes to a PLT slot it must do so in a
|
|
|
5de29b |
+ thread-safe manner with all the required barriers. */
|
|
|
5de29b |
+#if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2
|
|
|
5de29b |
+#define VDSO_IFUNC_RET(value) \
|
|
|
5de29b |
+ ({ \
|
|
|
5de29b |
+ static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \
|
|
|
5de29b |
+ vdso_opd.fd_func = (Elf64_Addr)value; \
|
|
|
5de29b |
+ &vdso_opd; \
|
|
|
5de29b |
+ })
|
|
|
5de29b |
+
|
|
|
5de29b |
#else
|
|
|
5de29b |
#define VDSO_IFUNC_RET(value) ((void *) (value))
|
|
|
5de29b |
#endif
|
|
|
12745e |
diff -urN glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
|
|
|
5de29b |
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c 2015-01-15 16:05:08.912679502 -0500
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c 2015-01-15 16:06:11.451747716 -0500
|
|
|
5de29b |
@@ -21,6 +21,7 @@
|
|
|
5de29b |
|
|
|
5de29b |
# include <dl-vdso.h>
|
|
|
5de29b |
# include <bits/libc-vdso.h>
|
|
|
5de29b |
+# include <dl-machine.h>
|
|
|
5de29b |
|
|
|
5de29b |
void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday");
|
|
|
5de29b |
|
|
|
12745e |
diff -urN glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c
|
|
|
5de29b |
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c 2015-01-15 16:05:08.912679502 -0500
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/time.c 2015-01-15 16:06:11.451747716 -0500
|
|
|
5de29b |
@@ -20,7 +20,9 @@
|
|
|
5de29b |
|
|
|
5de29b |
# include <time.h>
|
|
|
5de29b |
# include <sysdep.h>
|
|
|
5de29b |
+# include <dl-vdso.h>
|
|
|
5de29b |
# include <bits/libc-vdso.h>
|
|
|
5de29b |
+# include <dl-machine.h>
|
|
|
5de29b |
|
|
|
5de29b |
void *time_ifunc (void) asm ("time");
|
|
|
5de29b |
|