]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add workaround for infinite looping in ppc vsyscalls
authorStan Shebs <stanshebs@google.com>
Tue, 25 Sep 2018 17:52:37 +0000 (10:52 -0700)
committerFangrui Song <i@maskray.me>
Sat, 28 Aug 2021 00:23:13 +0000 (17:23 -0700)
sysdeps/posix/clock_getres.c
sysdeps/unix/clock_gettime.c

index 8bc7e813e603b3842dd58fecc525ddadbc7001d2..3f6fdcf9aa85f5262763c4a806a13e3184737c75 100644 (file)
@@ -73,6 +73,19 @@ realtime_getres (struct timespec *res)
   return -1;
 }
 
+#if defined __clang__ && defined __powerpc64__
+/* On ppc, __clock_getres's body eventually expands into asm code
+   that does a bctrl, but clang does not recognize the need to save
+   the link register, so calls loop infinitely instead of returning.
+   As workaround, make a dummy function call that forces a link
+   register save.  */
+volatile int clock_getres_dummy_glob;
+
+void __attribute__((noinline)) clock_getres_dummy ()
+{
+  clock_getres_dummy_glob = 45;
+}
+#endif
 
 /* Get resolution of clock.  */
 int
@@ -80,6 +93,10 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
 {
   int retval = -1;
 
+#if defined __clang__ && defined __powerpc64__
+  clock_getres_dummy ();
+#endif
+
   switch (clock_id)
     {
 #ifdef SYSDEP_GETRES
index 96df78ab1ed09c042ac755ca05c7ee85cced8d68..7ef43307b5aec0d03176d0bce24f5636c4a44b52 100644 (file)
@@ -86,6 +86,19 @@ realtime_gettime (struct timespec *tp)
   return retval;
 }
 
+#if defined __clang__ && defined __powerpc64__
+/* On ppc, __clock_gettime's body eventually expands into asm code
+   that does a bctrl, but clang does not recognize the need to save
+   the link register, so calls loop infinitely instead of returning.
+   As workaround, make a dummy function call that forces a link
+   register save.  */
+volatile int clock_gettime_dummy_glob;
+
+void __attribute__((noinline)) clock_gettime_dummy ()
+{
+  clock_gettime_dummy_glob = 45;
+}
+#endif
 
 /* Get current value of CLOCK and store it in TP.  */
 int
@@ -93,6 +106,10 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 {
   int retval = -1;
 
+#if defined __clang__ && defined __powerpc64__
+  clock_gettime_dummy ();
+#endif
+
   switch (clock_id)
     {
 #ifdef SYSDEP_GETTIME