Add HASTIMERS probe to work around bug in gcc 9.3

This commit is contained in:
Rob Landley 2021-10-31 14:32:19 -05:00
parent d2ee698f90
commit b0e204b33d
3 changed files with 37 additions and 2 deletions

View File

@ -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

View File

@ -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 <syscall.h>
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

View File

@ -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 <sys/syscall.h>
#include <unistd.h>
int main(void) { copyfilerange(0, 0, 1, 0, 123, 0); }
EOF
probesymbol TOYBOX_HASTIMERS -lrt << EOF
#include <signal.h>
#include <time.h>
int main(void) {void *x=0;timer_create(CLOCK_MONOTONIC,x,x);}
EOF
}