From 5e5ee15db2364d090624733c3eadf874b31ef08d Mon Sep 17 00:00:00 2001 From: Zixing Liu Date: Sun, 24 Mar 2024 10:52:15 +0100 Subject: [PATCH] preload: Fix building with _FILE_OFFSET_BITS Unsetting `_FILE_OFFSET_BITS` causes time_t to be treated as 32-bit instead of the 64-bit that we want with `-D_TIME_BITS=64`. Fixes #216 Co-Authored-By: Steve Langasek Co-Authored-By: Martin Pitt --- src/libumockdev-preload.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/libumockdev-preload.c b/src/libumockdev-preload.c index 7e1ea6f..bed4774 100644 --- a/src/libumockdev-preload.c +++ b/src/libumockdev-preload.c @@ -22,12 +22,30 @@ * along with umockdev; If not, see . */ -/* override -D_FILE_OFFSET_BITS, it breaks us */ -#undef _FILE_OFFSET_BITS - /* for getting stat64 */ #define _GNU_SOURCE +#include + +#ifdef __GLIBC__ +/* Remove gcc asm aliasing so that our interposed symbols work as expected */ +#include + +#include +extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf, + size_t __buflen), ttyname_r); + +#ifdef __REDIRECT +#undef __REDIRECT +#endif +#define __REDIRECT(name, proto, alias) name proto +#ifdef __REDIRECT_NTH +#undef __REDIRECT_NTH +#endif +#define __REDIRECT_NTH(name, proto, alias) name proto __THROW + +#endif /* __GLIBC__ */ + #include #include #include @@ -63,6 +81,14 @@ #include "utils.h" #include "ioctl_tree.h" +#ifdef __GLIBC__ +/* Fixup for making a mess with __REDIRECT above */ +#ifdef __USE_TIME_BITS64 +#define clock_gettime __clock_gettime64 +extern int clock_gettime(clockid_t clockid, struct timespec *tp); +#endif +#endif + /* fix missing O_TMPFILE on some systems */ #ifndef O_TMPFILE #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)