-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fake 64-bit time on 32-bit systems #487
Conversation
Since debian generally added 64-bit time support on 32-bit arches, now glibc sometimes calls the clock_gettime64 syscall (and library wrapper). This function was missing, and is added here. Patch originally supplied here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1064555
timespec.tv_nsec is 32-bit, even though timeval.tv_usec is 64-bit (weirdly). This doesn't matter very much in practice because * on little endian architectures (which is all our 32-bit release arches) writing to a too big integer ends up writing the desired value in the desired location, and * it doesn't affect the overall struct size on any of our actual architectures (which align the uint64_t to 8 so must make the whole struct 16 not 12), so the write overflow is harmless. > #include <time.h> > #include <sys/time.h> > #include <stdio.h> > struct timeval tv; > struct timespec ts; > int main(void) { > printf("time_t %lld\n", (unsigned long long) sizeof(time_t)); > printf("timeval %lld %lld %lld\n", > (unsigned long long) sizeof(tv), > (unsigned long long) sizeof(tv.tv_sec), > (unsigned long long) sizeof(tv.tv_usec) > ); > printf("timespec %lld %lld %lld\n", > (unsigned long long) sizeof(ts), > (unsigned long long) sizeof(ts.tv_sec), > (unsigned long long) sizeof(ts.tv_nsec) > ); > } > (sid_armhf-dchroot)iwj@amdahl:~/Faketime/test$ gcc t.c > (sid_armhf-dchroot)iwj@amdahl:~/Faketime/test$ ./a.out > time_t 8 > timeval 16 8 8 > timespec 16 8 4 > (sid_armhf-dchroot)iwj@amdahl:~/Faketime/test$
Thanks, @ijackson, this is very much appreciated! |
@wolfcw @ijackson This PR broke our arm/v7 alpine linux build. I think alpine uses musl instead glibc and that clashes with the introduction of 4.543 /tmp/ccampOmB.s:11632: Error: symbol __clock_gettime64' is already defined Any ideas what can I do? Currently, it doesn't seem like I can disable the feature in either musl or in libfaketime. |
Hi. I'm afraid I have little idea. Looking at the error output, I think maybe musl is doing t64 by If that is the case, then without my series, faketime would fail to fake time for old programs with 32-bit time_t. (IDK if that is a thing with musl.) It would probably be possible to add more See also #482 (which was closed in error by github). It's possible that a proper fix to this situation would fix #482 too. |
Hi. This is an attempt at fixing #418.
The background is that faketime is used quite extensively in Debian, as part of various packages' tests. Most 32-bit architectures in Debian are now using 64-bit time_t, [1] and the lack of support in faketime broke those tests.
[1] The main exception is i386 (aka x86_32) which is still using 32-bit time_t, because the principal use case for that arch is running old proprietary binaries, which obviously can't be updated.
This patch series works in Debian - our CI has confirmed that all the packages which were broken by t64 are now fixed. (Some race fixes were necessary too - I'm going to make another MR with those.)
Debian is entirely ELF now. So it is possible that this series won't work on every platform supported by faketime. Probably, in that case, ifdeffery will be needed.
This series does not fix #482. faketime still has a Y2038 bug on 32-bit arches with t64. #482 didn't seem easy.