]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
build: check for __xstat declarations
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 15 Sep 2024 00:40:14 +0000 (01:40 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 17 Sep 2024 03:01:35 +0000 (22:01 -0500)
Currently we check the function is resolved at link time. Although what
we really care is if the headers are silently transposing any of our stat
calls to __xstat{,64}. If so, we'd want to wrap the latter functions.

As the now-removed comment says, glibc 2.33 was the first release to no
longer have static inline wrappers that do the transposition. See the
glibc commit 8ed005daf0ab ("Remove stat wrapper functions, move them to
exported symbols") for more details.

So change the checking to check_decl/has_header_symbol and keep them for
distributions with older glibc.

NOTE: to summarise/contrast this wrt the previous open64, etc
 - here: we had inline wrappers and declarations (as below)
 - others: no inline wrappers and optionally declarations

glibc 2.32
extern ... __xstat(); extern inline stat(...) { return __xstat(...); }

glibc 2.33
extern stat(...);

Note we group the 64 variant as well, since the codepath has been
identical (wrt core logic) to the normal __xstat().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/131
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
configure.ac
meson.build
testsuite/path.c

index 39e336900bece76f7234804b7c3fd5935a4f776b..15def643c634c80253fee9e48f48c8523609811c 100644 (file)
@@ -39,7 +39,6 @@ AC_PROG_CC_C99
 # Function and structure checks
 #####################################################################
 
-AC_CHECK_FUNCS_ONCE(__xstat)
 AC_CHECK_FUNCS_ONCE([open64 stat64 fopen64 __stat64_time64])
 AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 
@@ -48,16 +47,13 @@ CC_CHECK_FUNC_BUILTIN([__builtin_types_compatible_p])
 CC_CHECK_FUNC_BUILTIN([__builtin_uaddl_overflow], [ ], [ ])
 CC_CHECK_FUNC_BUILTIN([__builtin_uaddll_overflow], [ ], [ ])
 
-# Non glibc compilers (musl and newer versions of bionic) do not need
-# the 64 LFS API wrapping.
-AC_CHECK_DECLS_ONCE([[__GLIBC__]], [], [], [[#include <features.h>]])
-
 # dietlibc doesn't have st.st_mtim struct member
 AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
 
 # basename may be only available in libgen.h with the POSIX behavior,
 # not desired here
 AC_CHECK_DECLS_ONCE([[basename]], [], [], [[#include <string.h>]])
+AC_CHECK_DECLS_ONCE([[__xstat]], [], [], [[#include <sys/stat.h]])
 
 AC_MSG_CHECKING([whether _Static_assert() is supported])
 AC_COMPILE_IFELSE(
index 047e96472be91736a0a939f0cdeb9b2956fea56c..16ff67b9a4f4879a65604bbf3ae048c622368bb8 100644 (file)
@@ -34,7 +34,6 @@ cdata.set10('_GNU_SOURCE', true)
 ################################################################################
 
 _funcs = [
-  '__xstat',
   'open64', 'stat64', 'fopen64', '__stat64_time64',
   '__secure_getenv', 'secure_getenv',
 ]
@@ -88,11 +87,12 @@ endforeach
 # not desired here
 _decls = [
   ['basename', 'string.h'],
+  ['__xstat', 'sys/stat.h'],
 ]
 foreach tuple : _decls
   decl = tuple[0]
   header = tuple[1]
-  glibc = cc.has_header_symbol(header, decl, args : '-D_GNU_SOURCE')
+  have  = cc.has_header_symbol(header, decl, args : '-D_GNU_SOURCE')
   cdata.set10('HAVE_DECL_@0@'.format(decl.to_upper()), have)
 endforeach
 
index 26e0f4bcef0109a69177e15670c6ee1b94535d7e..9b1f97a945cd326f4c086f7f3bf3f5ca03116697 100644 (file)
@@ -152,15 +152,7 @@ TS_EXPORT int open ## suffix (const char *path, int flags, ...)    \
        return _fn(p, flags);                                   \
 }
 
-/*
- * wrapper template for __xstat family
- * This family got deprecated/dropped in glibc 2.32.9000, but we still need
- * to keep it for a while for programs that were built against previous versions
- */
 #define WRAP_VERSTAT(prefix, suffix)                       \
-TS_EXPORT int prefix ## stat ## suffix (int ver,           \
-                             const char *path,             \
-                             struct stat ## suffix *st);   \
 TS_EXPORT int prefix ## stat ## suffix (int ver,           \
                              const char *path,             \
                              struct stat ## suffix *st)    \
@@ -205,9 +197,7 @@ WRAP_2ARGS(int, -1, __stat64_time64, void *);
 WRAP_OPEN(64);
 #endif
 
-#ifdef HAVE___XSTAT
+#if HAVE_DECL___XSTAT
 WRAP_VERSTAT(__x,);
-#if HAVE_DECL___GLIBC__
 WRAP_VERSTAT(__x,64);
 #endif
-#endif