wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.64k stars 321 forks source link

make failed in libfaketime@master on centos8_aarch64 #386

Closed Tom-python0121 closed 2 years ago

Tom-python0121 commented 2 years ago

Steps to reproduce the issue

[root@localhost weipan]# git clone https://github.com/wolfcw/libfaketime.git
Cloning into 'libfaketime'...
remote: Enumerating objects: 2337, done.
remote: Counting objects: 100% (461/461), done.
remote: Compressing objects: 100% (280/280), done.
remote: Total 2337 (delta 290), reused 312 (delta 174), pack-reused 1876
Receiving objects: 100% (2337/2337), 800.36 KiB | 1.10 MiB/s, done.
Resolving deltas: 100% (1459/1459), done.
[root@localhost weipan]# ls
libfaketime
[root@localhost weipan]# cd libfaketime/
[root@localhost libfaketime]# ls
COPYING  Makefile  man  NEWS  README  README.developers  README.OSX  README.packagers  src  test  TODO
[root@localhost libfaketime]# make
make  -C src all
make[1]: Entering directory '/home/weipan/libfaketime/src'
cc -o libfaketime.o -c -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'    libfaketime.c
libfaketime.c:2240:5: error: conflicting types for ‘gettimeofday’
 int gettimeofday(struct timeval *tv, void *tz)
     ^~~~~~~~~~~~
In file included from /usr/include/sys/procfs.h:32,
                 from /usr/include/sys/ucontext.h:36,
                 from /usr/include/signal.h:306,
                 from libfaketime.c:79:
/usr/include/sys/time.h:68:12: note: previous declaration of ‘gettimeofday’ was here
 extern int gettimeofday (struct timeval *__restrict __tv,
            ^~~~~~~~~~~~
make[1]: *** [Makefile:140: libfaketime.o] Error 1
make[1]: Leaving directory '/home/weipan/libfaketime/src'
make: *** [Makefile:8: all] Error 2

I see:https://github.com/wolfcw/libfaketime/issues/293,This problem always occurs when I compile on ARM64, but the compilation on x86_64 is OK.But I can't confirm what is the reason for error: conflicting types?

Tom-python0121 commented 2 years ago

I suspect that the function declaration is inconsistent with the parameter or return value type in the function call. I debug it and find that the compilation process does not follow the gettimeofday function method, but the compiler of arm64 always takes it out, leading to compilation failure. So I temporarily blocked the gettimeofday method, so that the compilation tests were OK.

Tom-python0121 commented 2 years ago

If you have a better solution, please provide it.

[root@localhost libfaketime]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper Target: aarch64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)

Tom-python0121 commented 2 years ago

image image

I find that the input parameters are different. The gettimeofday function defines a parameter of the void type, but the name is a parameter of the struct timezone type. As a result, the preceding error occurs. I'll close the issue once the error is detected.

Tom-python0121 commented 2 years ago

Steps to reproduce the issue

[root@localhost spack-src]# git diff
diff --git a/src/libfaketime.c b/src/libfaketime.c
index e632395..6fd6eca 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -2219,7 +2219,7 @@ int ftime(struct timeb *tb)
 #ifdef MACOS_DYLD_INTERPOSE
 int macos_gettimeofday(struct timeval *tv, void *tz)
 #else
-int gettimeofday(struct timeval *tv, void *tz)
+int gettimeofday(struct timeval *tv, struct timezone *tz)
 #endif
 {
   int result;

[root@localhost spack-src]# make
make  -C src all
make[1]: Entering directory '/home/spack-stage/root/spack-stage-libfaketime-0.9.10-hwaa7ovwsgrhu3qso53cwmemrbl3jwtp/spack-src/src'
cc -o libfaketime.o -c -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'    libfaketime.c
cc -o libfaketime.so.1 -Wl,-soname,libfaketime.so.1  -lpthread -Wl,--version-script=libfaketime.map -shared libfaketime.o -ldl -lm -lrt
cc -o libfaketimeMT.o -c -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"'   -DPTHREAD_SINGLETHREADED_TIME libfaketime.c
cc -o libfaketimeMT.so.1 -Wl,-soname,libfaketimeMT.so.1  -lpthread -Wl,--version-script=libfaketime.map -shared libfaketimeMT.o -ldl -lm -lrt
make[1]: Leaving directory '/home/spack-stage/root/spack-stage-libfaketime-0.9.10-hwaa7ovwsgrhu3qso53cwmemrbl3jwtp/spack-src/src'
perldude commented 2 years ago

FWIW, I had this same problem but when I was doing the build in a centOS container on an M1 MacBook. The problem comes starts with libfaketime.c including signal.h. That, in turn, includes sys/procfs.h. Since it's a system file, it can vary between architectures (and it does). On the M1 it includes sys/procfs.h, which includes sys/time.h (that is not the case on my Intel iMac). Here is the change I made to libfaketime.c:

#if defined PTHREAD_SINGLETHREADED_TIME || defined FAKE_PTHREAD
#include <pthread.h>
> #ifdef __aarch64__
> #define _SYS_TIME_H 1
> #endif
#include <signal.h>
#endif

Defining _SYS_TIME_H keeps sys/time.h from being included. Seems to work.