zardus / preeny

Some helpful preload libraries for pwning stuff.
BSD 2-Clause "Simplified" License
1.57k stars 170 forks source link

error: conflicting types for ‘gettimeofday’ #69

Closed ghost closed 3 years ago

ghost commented 4 years ago

Build fails on Arch Linux:

/home/user/build/src/preeny/src/detime.c:24:5: error: conflicting types for ‘gettimeofday’
   24 | int gettimeofday(struct timeval *tv, struct timezone *tz)
      |     ^~~~~~~~~~~~
In file included from /home/user/build/src/preeny/src/detime.c:6:
/usr/include/sys/time.h:66:12: note: previous declaration of ‘gettimeofday’ was here
   66 | extern int gettimeofday (struct timeval *__restrict __tv,
      |            ^~~~~~~~~~~~
make[2]: *** [CMakeFiles/detime.dir/build.make:83: CMakeFiles/detime.dir/src/detime.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:688: CMakeFiles/detime.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
==> ERROR: A failure occurred in build().

Thanks in advance!

zardus commented 4 years ago

I don't have arch. Be the change you want to see in the world :-)

ghost commented 4 years ago

@zardus what information could I provide to help you? :)

SjonHortensius commented 4 years ago

this is caused by glibc-2.31

  • The gettimeofday function no longer reports information about a system-wide time zone. This 4.2-BSD-era feature has been deprecated for many years, as it cannot handle the full complexity of the world's timezones, but hitherto we have supported it on a best-effort basis. Changes required to support 64-bit time_t on 32-bit architectures have made this no longer practical.

    As of this release, callers of gettimeofday with a non-null 'tzp' argument should expect to receive a 'struct timezone' whose tz_minuteswest and tz_dsttime fields are zero. (For efficiency reasons, this does not always happen on a few Linux-based ports. This will be corrected in a future release.)

    All callers should supply a null pointer for the 'tzp' argument to gettimeofday. For accurate information about the time zone associated with the current time, use the localtime function.

    gettimeofday itself is obsolescent according to POSIX. We have no plans to remove access to this function, but portable programs should consider using clock_gettime instead.

Changing the second parameter of the gettimeofday overload to void *__restrict tzp will fix it for glibc-2.31+

martinclauss commented 4 years ago

I encountered the same problem with Fedora 32 today!

Best Martin

sudhackar commented 4 years ago

As pointed out by @SjonHortensius builds can be possible with

diff --git a/src/detime.c b/src/detime.c
index 441b584..5c9a8ce 100644
--- a/src/detime.c
+++ b/src/detime.c
@@ -21,9 +21,9 @@ time_t time(time_t *res)
 }

 #ifdef __unix__
-int gettimeofday(struct timeval *tv, struct timezone *tz)
+int gettimeofday(struct timeval *tv, void *__restrict tzp)
 {
-       
+       struct timezone *tz = (struct timezone *) tzp;
        char *sec_str = getenv("TV_SEC");
        char *usec_str = getenv("TV_USEC");
        tv->tv_sec = sec_str ? atoi(sec_str) : 0;

But since now gettimeofday will always zero the struct if tzp is non null, from release/2.31/master

/* Get the current time of day, putting it into *TV.
   If *TZ is not NULL, clear it.
   Returns 0 on success, -1 on errors.  */
int
___gettimeofday (struct timeval *restrict tv, void *restrict tz)
{
  if (__glibc_unlikely (tz != 0))
    memset (tz, 0, sizeof (struct timezone));

  struct timespec ts;
  if (__clock_gettime (CLOCK_REALTIME, &ts))
    return -1;

  TIMESPEC_TO_TIMEVAL (tv, &ts);
  return 0;
}

Should we get preeny to reflect that for newer builds?