From b0e204b33d77df151e2c33c48973820ba0fe0ca7 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 31 Oct 2021 14:32:19 -0500 Subject: [PATCH] Add HASTIMERS probe to work around bug in gcc 9.3 --- lib/portability.c | 23 +++++++++++++++++++++++ lib/portability.h | 7 +++++++ scripts/genconfig.sh | 9 +++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/portability.c b/lib/portability.c index 776b1fb9..cd917bc9 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -678,4 +678,27 @@ int timer_settime(timer_t t, int flags, struct itimerspec *new, void *old) mangled.it_value.tv_usec = new->it_value.tv_nsec / 1000; return setitimer(ITIMER_REAL, &mangled, NULL); } +// glibc requires -lrt for linux syscalls, which pulls in libgcc_eh.a for +// static linking, and gcc 9.3 leaks pthread calls from that breaking the build +// These are both just linux syscalls: wrap them ourselves +#elif !CFG_TOYBOX_HASTIMERS +int timer_create_wrap(clockid_t c, struct sigevent *se, timer_t *t) +{ + // convert overengineered structure to what kernel actually uses + struct ksigevent { void *sv; int signo, notify, tid; } kk = { + 0, se->sigev_signo, se->sigev_notify, 0 + }; + int timer; + + if (syscall(SYS_timer_create, c, &kk, &timer)<0) return -1; + *t = (timer_t)(long)timer; + + return 0; +} + +int timer_settime_wrap(timer_t t, int flags, struct itimerspec *val, + struct itimerspec *old) +{ + return syscall(SYS_timer_settime, t, flags, val, old); +} #endif diff --git a/lib/portability.h b/lib/portability.h index 5ddfea5c..ac3d0f12 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -387,4 +387,11 @@ struct itimerspec { }; int timer_create(clock_t c, struct sigevent *se, timer_t *t); int timer_settime(timer_t t, int flags, struct itimerspec *new, void *old); +#elif !CFG_TOYBOX_HASTIMERS +#include +int timer_create_wrap(clockid_t c, struct sigevent *se, timer_t *t); +#define timer_create(...) timer_create_wrap(__VA_ARGS__) +int timer_settime_wrap(timer_t t, int flags, struct itimerspec *val, + struct itimerspec *old); +#define timer_settime(...) timer_settime_wrap(__VA_ARGS__) #endif diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index 955c82cd..95b901ed 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -9,14 +9,14 @@ source scripts/portability.sh probecc() { - ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $1 - + ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc -o /dev/null - "$@" } # Probe for a single config symbol with a "compiles or not" test. # Symbol name is first argument, flags second, feed C file to stdin probesymbol() { - probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n + probecc "${@:2}" 2>/dev/null && DEFAULT=y || DEFAULT=n rm a.out 2>/dev/null echo -e "config $1\n\tbool" || exit 1 echo -e "\tdefault $DEFAULT\n" || exit 1 @@ -112,6 +112,11 @@ EOF #include #include int main(void) { copyfilerange(0, 0, 1, 0, 123, 0); } +EOF + probesymbol TOYBOX_HASTIMERS -lrt << EOF + #include + #include + int main(void) {void *x=0;timer_create(CLOCK_MONOTONIC,x,x);} EOF } -- 2.39.2