DescriptionMiroslav Lichvar
2025-05-22 12:37:40 UTC
The latest chrony package doesn't build correctly on aarch64 [1]. It fails in the test suite in the 139-nts test, giving odd errors. After some investigation it looks like there is a floating-point calculation that is broken in the update_monotonic_time() function in sched.c [2]. The last_select_ts_mono_ns value (uint32_t) divided by 1.0e9 gives extremely large values, sometimes even infinity.
It's not an issue with the test. I can reproduce it even when running chronyd directly like this: chronyd -Q 'server time.cloudflare.com nts iburst maxsamples 1'.
With the following patch applied to the chrony source code:
--- a/sched.c
+++ b/sched.c
@@ -755,6 +755,8 @@ update_monotonic_time(struct timespec *now, struct timespec *before)
/* Avoid frequent floating-point operations and handle small
increments to a large value */
+ fprintf(stderr, "%u %f\n", last_select_ts_mono_ns, last_select_ts_mono_ns / 1e9);
+
UTI_DiffTimespecs(&diff, now, before);
if (diff.tv_sec == 0) {
last_select_ts_mono_ns += diff.tv_nsec;
I'm getting output like this:
0 0.000000
2000000 8341940198100499958809877820903131852021940998468144139468053349526963123663956666898446020563246068538576711
595267021703081662275936469197561087887244473786488752473766452615549680474976493951269377976560957010897490774418567
313054638573006465252676696853593955606299734202472464384.000000
2000000 0.000000
4000000 inf
6000001 inf
Strangely, the problem disappears when I add -fno-inline to the CFLAGS. The minimal CFLAGS that reproduce the problem is "-O". "-O -fno-inline" works.
I'm not sure if it's really a compiler issue. I wasn't able to prepare a minimal reproducer. Also, there might be some weird interaction with gnutls. The problem doesn't seem to appear when the library is not used by chronyd for NTS.
[1] https://koji.fedoraproject.org/koji/taskinfo?taskID=133056637
[2] https://gitlab.com/chrony/chrony/-/blob/master/sched.c?ref_type=heads#L763
Package versions:
gcc-15.1.1-1.fc43.aarch64
gnutls-3.8.9-5.fc43.aarch64
Reproducible: Always
Steps to Reproduce:
1. try to build chrony-4.7-0.1.pre1.fc43 on aarch64
Actual Results:
Build fails
Expected Results:
Build succeeds