about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdhemerval Zanella <azanella@linux.vnet.ibm.com>2013-11-07 05:34:22 -0600
committerAdhemerval Zanella <azanella@linux.vnet.ibm.com>2015-01-15 21:01:44 -0500
commite3008132765936162552b15a77fe348c01074310 (patch)
tree3da1f42e04e5ddb0d7079cb8da90bb581b6db729
parent6ff69e1eb81719ee907642f615cef889d5bf8b2c (diff)
downloadglibc-e3008132765936162552b15a77fe348c01074310.tar.gz
glibc-e3008132765936162552b15a77fe348c01074310.tar.xz
glibc-e3008132765936162552b15a77fe348c01074310.zip
PowerPC: Fix vDSO missing ODP entries
This patch fixes the vDSO symbol used directed in IFUNC resolver where
they do not have an associated ODP entry leading to undefined behavior
in some cases. It adds an artificial OPD static entry to such cases
and set its TOC to non 0 to avoid triggering lazy resolutions.
-rw-r--r--ChangeLog7
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h30
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/gettimeofday.c3
3 files changed, 35 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index e3f16eacb6..963a282cf1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-11-08  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
+
+	* sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h (VDSO_IFUNC_RET):
+	Add artificial ODP entry for vDSO symbol for PPC64.
+	* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: Adjust includes.
+	* sysdeps/unix/sysv/linux/powerpc/time.c: Likewise.
+
 2014-11-19  Carlos O'Donell  <carlos@redhat.com>
 	    Florian Weimer  <fweimer@redhat.com>
 	    Joseph Myers  <joseph@codesourcery.com>
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
index 820079fc19..4f5268fd37 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
@@ -32,12 +32,34 @@ extern void *__vdso_get_tbfreq;
 
 extern void *__vdso_getcpu;
 
-/* Macro to return vdso_xxx value on IFUNC implementations.
-   On PPC64 the returned value is actually an OPD entry.  */
 #if defined(__PPC64__) || defined(__powerpc64__)
-#define PTR_IFUNC_RET(value)  &value
+/* The correct solution is for _dl_vdso_vsym to return the address of the OPD
+   for the kernel VDSO function.  That address would then be stored in the
+   __vdso_* variables and returned as the result of the IFUNC resolver function.
+   Yet, the kernel does not contain any OPD entries for the VDSO functions
+   (incomplete implementation).  However, PLT relocations for IFUNCs still expect
+   the address of an OPD to be returned from the IFUNC resolver function (since
+   PLT entries on PPC64 are just copies of OPDs).  The solution for now is to
+   create an artificial static OPD for each VDSO function returned by a resolver
+   function.  The TOC value is set to a non-zero value to avoid triggering lazy
+   symbol resolution via .glink0/.plt0 for a zero TOC (requires thread-safe PLT
+   sequences) when the dynamic linker isn't prepared for it e.g. RTLD_NOW.  None
+   of the kernel VDSO routines use the TOC or AUX values so any non-zero value
+   will work.  Note that function pointer comparisons will not use this artificial
+   static OPD since those are resolved via ADDR64 relocations and will point at
+   the non-IFUNC default OPD for the symbol.  Lastly, because the IFUNC relocations
+   are processed immediately at startup the resolver functions and this code need
+   not be thread-safe, but if the caller writes to a PLT slot it must do so in a
+   thread-safe manner with all the required barriers.  */
+#define VDSO_IFUNC_RET(value)                            \
+  ({                                                     \
+    static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \
+    vdso_opd.fd_func = (Elf64_Addr)value;                \
+    &vdso_opd;                                           \
+  })
+
 #else
-#define PTR_IFUNC_RET(value)  value
+#define VDSO_IFUNC_RET(value)  ((void *) (value))
 #endif
 
 #endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
index 5943be77ab..06aae83cc5 100644
--- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
@@ -21,6 +21,7 @@
 
 # include <dl-vdso.h>
 # include <bits/libc-vdso.h>
+# include <dl-machine.h>
 
 void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday");
 
@@ -34,7 +35,7 @@ void *
 gettimeofday_ifunc (void)
 {
   /* If the vDSO is not available we fall back syscall.  */
-  return (__vdso_gettimeofday ? PTR_IFUNC_RET(__vdso_gettimeofday)
+  return (__vdso_gettimeofday ? VDSO_IFUNC_RET (__vdso_gettimeofday)
 	  : __gettimeofday_syscall);
 }
 asm (".type __gettimeofday, %gnu_indirect_function");