The attached patches fix the FTBFS for faketime on 32-bit architectures for me.

I tested the patches on armhf and hppa architectures.

There are two issues:
a) faketime is a low-level library, faking libc and
syscalls. So, on a 32-bit platform we need to compile
natively without _FILE_OFFSET_BITS _TIME_BITS defines defined.
This is done by adding "abi=-time64" to the rules file:
export DEB_BUILD_MAINT_OPTIONS = hardening=+all abi=-time64
(see faketime_rules.patch)

b) 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 by the second patch.

Please apply.
Helge
diff -up ./debian/rules.org ./debian/rules
--- ./debian/rules.org	2024-11-16 08:57:30.246403826 +0000
+++ ./debian/rules	2024-11-16 08:58:13.654549967 +0000
@@ -13,7 +13,7 @@ DEB_CFLAGS_MAINT_APPEND += -DFAKE_RANDOM
 
 export DEB_CFLAGS_MAINT_APPEND
 
-export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+export DEB_BUILD_MAINT_OPTIONS = hardening=+all abi=-time64
 
 # make sure dh_makeshlibs does not modify post{inst,rm} scripts:
 # (avoids lintian's postinst-has-useless-call-to-ldconfig)
diff -up ./src/libfaketime.c.org ./src/libfaketime.c
--- ./src/libfaketime.c.org	2024-11-16 08:57:44.218450779 +0000
+++ ./src/libfaketime.c	2024-11-16 09:32:33.916384565 +0000
@@ -159,6 +159,13 @@ struct utimbuf {
 #include <sys/random.h>
 #endif
 
+/* __timespec64 is needed for clock_gettime64 on 32-bit architectures */
+struct __timespec64
+{
+  uint64_t tv_sec;         /* Seconds */
+  uint64_t tv_nsec;        /* Nanoseconds */
+};
+
 /*
  * Per thread variable, which we turn on inside real_* calls to avoid modifying
  * time multiple times of for the whole process to prevent faking time
@@ -193,6 +200,7 @@ static time_t       (*real_time)
 static int          (*real_ftime)           (struct timeb *);
 static int          (*real_gettimeofday)    (struct timeval *, void *);
 static int          (*real_clock_gettime)   (clockid_t clk_id, struct timespec *tp);
+static int          (*real_clock_gettime64) (clockid_t clk_id, struct __timespec64 *tp);
 static int          (*real_timespec_get)    (struct timespec *ts, int base);
 #ifdef FAKE_INTERNAL_CALLS
 static int          (*real___ftime)           (struct timeb *);
@@ -2319,6 +2327,17 @@ int clock_gettime(clockid_t clk_id, stru
   return result;
 }
 
+/* this is used by 32-bit architectures only */
+int __clock_gettime64(clockid_t clk_id, struct __timespec64 *tp64)
+{
+  struct timespec tp;
+  int result;
+
+  result = clock_gettime(clk_id, &tp);
+  tp64->tv_sec = tp.tv_sec;
+  tp64->tv_nsec = tp.tv_nsec;
+  return result;
+}
 
 #ifdef MACOS_DYLD_INTERPOSE
 int macos_timespec_get(struct timespec *ts, int base)
@@ -2652,6 +2671,11 @@ static void ftpl_init(void)
   {
     real_clock_gettime  =   dlsym(RTLD_NEXT, "clock_gettime");
   }
+  real_clock_gettime64 =    dlsym(RTLD_NEXT, "clock_gettime64");
+  if (NULL == real_clock_gettime64)
+  {
+    real_clock_gettime64 =  dlsym(RTLD_NEXT, "__clock_gettime64");
+  }
 #ifdef FAKE_TIMERS
 #if defined(__sun)
     real_timer_gettime_233 =  dlsym(RTLD_NEXT, "timer_gettime");
diff -up ./test/Makefile.org ./test/Makefile
--- ./test/Makefile.org	2024-11-16 08:58:10.542539464 +0000
+++ ./test/Makefile	2024-11-16 09:32:48.696419444 +0000
@@ -1,6 +1,6 @@
 CC = gcc
 
-CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS)
+CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra $(FAKETIME_COMPILE_CFLAGS) -U_FILE_OFFSET_BITS -U_TIME_BITS
 LDFLAGS += -lrt -lpthread
 
 SRC = timetest.c

Reply via email to