]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add workaround for infinite looping in ppc vsyscall for sched_getcpu.
authorStan Shebs <stanshebs@google.com>
Fri, 24 Jan 2020 16:17:38 +0000 (08:17 -0800)
committerFangrui Song <i@maskray.me>
Sat, 28 Aug 2021 00:26:03 +0000 (17:26 -0700)
sysdeps/unix/sysv/linux/sched_getcpu.c

index b69eeda15c60330ecb2db937d240b645767fb507..2279026bec41e42efe9f11e755e805c24db42972 100644 (file)
 #endif
 #include <sysdep-vdso.h>
 
+#if defined __clang__ && defined __powerpc64__
+/* On ppc, sched_getcpu'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 sched_getcpu_dummy_glob;
+
+void __attribute__((noinline)) sched_getcpu_dummy ()
+{
+  sched_getcpu_dummy_glob = 45;
+}
+#endif
+
 int
 sched_getcpu (void)
 {
 #ifdef __NR_getcpu
   unsigned int cpu;
+#if defined __clang__ && defined __powerpc64__
+  sched_getcpu_dummy ();
+#endif
   int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL);
 
   return r == -1 ? r : cpu;