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