]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
build: check for open64, stat64 and fopen64
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 15 Sep 2024 09:11:49 +0000 (10:11 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 17 Sep 2024 03:01:34 +0000 (22:01 -0500)
... and use behind the respective ifdef HAVE_FOO guards instead of the
HAVE_DECL___GLIBC__ currently.

Since day one, glibc has declarations for the functions, which was
forwarding the normal functions to them, via asm linkage, et al.
Aka `extern int open(....) asm_linkage("open64").

In addition, a lot of libraries have grown to depend on the declarations
being available and functions being statically exposed via libc.so.

Whereas musl pre 1.2.4 (circa 2023) have exposed the symbols
statically, without a declaration for well over a decade. Newer musl,
no longer expose the symbol in their runtime but have retained the
define trick, stating it will be removed in the future.

Looking at the bionic front things are somewhat similar. Newer bionic
(circa 2019) have a declaration and an inline wrapper open64 function
forwarding to open. Throughout 2019, open64 did forward to misc other
internal functions thought.

Older pre 2019 bionic had a declaration alongside plug exposing the
symbol statically in their C runtime.... since 2014. Not sure what they
did prior to 2014, it's a target out of scope for us.

Considering the above, the most robust approach is to do a check/has
function checking.

With that, we no longer need the __GLIBC__ guard for the respective
functions.

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 863a166af3d7cc5aa8cdc2d4b5beb66dc1833362..373250eb18eded5ee0dd50ad0c7cf344cf4e4623 100644 (file)
@@ -40,6 +40,7 @@ AC_PROG_CC_C99
 #####################################################################
 
 AC_CHECK_FUNCS_ONCE(__xstat)
+AC_CHECK_FUNCS_ONCE([open64 stat64 fopen64])
 AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 
 CC_CHECK_FUNC_BUILTIN([__builtin_clz])
index dc0581aae91354a22b7d8c53ecebae94802b52b7..e37218cfa0adf325490276642de25862dfd291e4 100644 (file)
@@ -33,9 +33,14 @@ cdata.set10('_GNU_SOURCE', true)
 # Function and structure checks
 ################################################################################
 
-foreach decl : ['__xstat', '__secure_getenv', 'secure_getenv']
-  if cc.has_function(decl, args : '-D_GNU_SOURCE')
-    cdata.set('HAVE_@0@'.format(decl.to_upper()), true)
+_funcs = [
+  '__xstat',
+  'open64', 'stat64', 'fopen64',
+  '__secure_getenv', 'secure_getenv',
+]
+foreach func : _funcs
+  if cc.has_function(func, args : '-D_GNU_SOURCE')
+    cdata.set('HAVE_@0@'.format(func.to_upper()), true)
   endif
 endforeach
 
index b251fc8ad40db92045a5fc2a845b0b895f5bb221..0c1faea0cdd22f0688a9375e4ddab7f235ecdf33 100644 (file)
@@ -189,14 +189,20 @@ WRAP_2ARGS(int, -1, stat, struct stat*);
 
 WRAP_OPEN();
 
-#if HAVE_DECL___GLIBC__
+#ifdef HAVE_FOPEN64
 WRAP_2ARGS(FILE*, NULL, fopen64, const char*);
+#endif
+#ifdef HAVE_STAT64
 WRAP_2ARGS(int, -1, stat64, struct stat64*);
+#endif
 
+#if HAVE_DECL___GLIBC__
 struct __stat64_t64;
 extern int __stat64_time64 (const char *file, struct __stat64_t64 *buf);
 WRAP_2ARGS(int, -1, __stat64_time64, struct __stat64_t64*);
+#endif
 
+#ifdef HAVE_OPEN64
 WRAP_OPEN(64);
 #endif