From 4e832afb77a158a6bb59f7adac6d9db5ecd5a4b8 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 5 Nov 2024 14:40:21 +0000 Subject: [PATCH 6/8] core-shim: limit _FORTIFY_SOURCE to 2 for ALT linux gcc for ppoll workaround Fixes: https://github.com/ColinIanKing/stress-ng/issues/452 Signed-off-by: Colin Ian King --- Makefile | 8 ++++++++ core-shim.c | 40 ++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 2661376a258a..cb395115cd64 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,14 @@ ifneq ($(shell $(CC) -v 2>&1 | grep scan-build),) COMPILER = scan-build endif +# +# check for ALT linux gcc, define HAVE_ALT_LINUX_GCC, see core-shim.c +# https://github.com/ColinIanKing/stress-ng/issues/452 +# +ifneq ($(shell $(CC) -v 2>&1 | grep Target | grep "alt-linux"),) +override CFLAGS += -DHAVE_ALT_LINUX_GCC +endif + KERNEL=$(shell uname -s) NODENAME=$(shell uname -n) diff --git a/core-shim.c b/core-shim.c index a7813474ab86..2f4b88f8188c 100644 --- a/core-shim.c +++ b/core-shim.c @@ -19,6 +19,17 @@ */ #define STRESS_CORE_SHIM +/* + * For ALT Linux gcc use at most _FORTIFY_SOURCE level 2 + * https://github.com/ColinIanKing/stress-ng/issues/452 + */ +#if defined(HAVE_ALT_LINUX_GCC) && \ + defined(_FORTIFY_SOURCE) && \ + _FORTIFY_SOURCE > 2 +#undef _FORTIFY_SOURCE +#define _FORTIFY_SOURCE 2 +#endif + #include "stress-ng.h" #include "core-arch.h" #include "core-attribute.h" @@ -2825,7 +2836,6 @@ int shim_mseal(void *addr, size_t len, unsigned long flags) #endif } - /* * shim_ppoll() * shim wrapper for ppoll @@ -2836,26 +2846,20 @@ int shim_ppoll( const struct timespec *tmo_p, const sigset_t *sigmask) { - #if defined(HAVE_PPOLL) - -#if defined(_FORTIFY_SOURCE) -#undef STRESS__FORTIFY_SOURCE -#define STRESS__FORTIFY_SOURCE _FORTIFY_SOURCE -#undef _FORTIFY_SOURCE -#define _FORTIFY_SOURCE 2 -#endif - return ppoll(fds, nfds, tmo_p, sigmask); +#elif defined(__NR_ppoll) && defined(_NSIG) + struct timespec tval; -#if defined(STRESS__FORTIFY_SOURCE) -#undef _FORTIFY_SOURCE -#define _FORTIFY_SOURCE STRESS__FORTIFY_SOURCE -#undef STRESS__FORTIFY_SOURCE -#endif - -#elif defined(__NR_ppoll) - return (int)syscall(__NR_ppoll, fds, nfds, tmo_p, sigmask); + /* + * The kernel will update the timeout, so use a tmp val + * instead + */ + if (tmo_p != NULL) { + tval = *tmo_p; + tmo_p = &tval; + } + return (int)syscall(__NR_ppoll, fds, nfds, tmo_p, sigmask, _NSIG / 8); #else return shim_enosys(0, fds, nfds, tmo_p, sigmask); #endif -- 2.47.0