From: Stan Shebs Date: Tue, 25 Sep 2018 17:52:37 +0000 (-0700) Subject: Add workaround for infinite looping in ppc vsyscalls X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2d69ea7ac4b918e5325bf477bf06a3ad6685f4d;p=thirdparty%2Fglibc.git Add workaround for infinite looping in ppc vsyscalls --- diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c index 8bc7e813e60..3f6fdcf9aa8 100644 --- a/sysdeps/posix/clock_getres.c +++ b/sysdeps/posix/clock_getres.c @@ -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 diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c index 96df78ab1ed..7ef43307b5a 100644 --- a/sysdeps/unix/clock_gettime.c +++ b/sysdeps/unix/clock_gettime.c @@ -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