Skip to contentSkip to conversation

v4l2-tracer: wrap open64/mmap64 functions only if linux && __GLIBC__

PATCH New Peter Seiderer 1 participant 2 messages Mar 31, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 v4l2-tracer: wrap open64/mmap64 functions only if linux && __GLIBC__

Wrap open64/mmap64 functions only if linux && __GLIBC__, as done in lib/libv4l1/v4l1comapt.c and lib/libv4l2/v4l2convert.c since commit 'libv4l: Wrap LFS64 functions only if linux && __GLIBC__' (403a4e2697a1ff96fe2fa16589039595f21cadf0), should fix musl libc compile.

---
 utils/v4l2-tracer/libv4l2tracer.cpp | 4 ++++
 1 file changed, 4 insertions(+)
utils/v4l2-tracer/libv4l2tracer.cpp +4 -0
index a9f039c7..68f6304a 100644
@@ -89,6 +89,7 @@ int open(const char *path, int oflag, ...)
 	return fd;
 }
 
+#if defined(linux) && defined(__GLIBC__)
 int open64(const char *path, int oflag, ...)
 {
 	errno = 0;
@@ -124,6 +125,7 @@ int open64(const char *path, int oflag, ...)
 
 	return fd;
 }
+#endif
 
 int close(int fd)
 {
@@ -177,6 +179,7 @@ void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
 	return buf_address_pointer;
 }
 
+#if defined(linux) && defined(__GLIBC__)
 void *mmap64(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
 {
 	errno = 0;
@@ -191,6 +194,7 @@ void *mmap64(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
 
 	return buf_address_pointer;
 }
+#endif
 
 int munmap(void *start, size_t length)
 {
Signature · 1 line
2.40.0
#1 lore raw

PATCH 2/2 libv4l1/libv4l2/v4l2-tracer: use common meson c_args/cpp_args to disable transparent large file support

Use common meson c_args/cpp_args to disable transparent large file support for the wrappers as already done in utils/v4l2-tracer for lib/libv4l1/v4l1compat.c and lib/libv4l2/v4l2convert.c too.

---
 lib/libv4l1/meson.build       |  1 +
 lib/libv4l1/v4l1compat.c      |  5 -----
 lib/libv4l2/meson.build       |  1 +
 lib/libv4l2/v4l2convert.c     |  5 -----
 meson.build                   | 10 ++++++++++
 utils/v4l2-tracer/meson.build | 13 +------------
 6 files changed, 13 insertions(+), 22 deletions(-)
lib/libv4l1/meson.build +1 -0
index e1df2fa2..e1fba346 100644
@@ -60,5 +60,6 @@ v4l1compat = shared_module('v4l1compat',
                            name_prefix : '',
                            install : true,
                            install_dir : libv4l1privdir,
+                           c_args : v4l2_wrapper_args,
                            dependencies : v4l1compat_deps,
                            include_directories : v4l2_utils_incdir)
lib/libv4l1/v4l1compat.c +0 -5
index 705d7d4b..2db68423 100644
@@ -19,11 +19,6 @@
 # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA
  */
 
-/* ensure we see *64 variants and they aren't transparently used */
-#undef _LARGEFILE_SOURCE
-#undef _FILE_OFFSET_BITS
-#define _LARGEFILE64_SOURCE 1
-
 #include <stdlib.h>
 #include <stdarg.h>
 #include <fcntl.h>
lib/libv4l2/meson.build +1 -0
index bd6e0e7f..9d6ecd5f 100644
@@ -69,5 +69,6 @@ v4l2convert = shared_module('v4l2convert',
                             name_prefix : '',
                             install : true,
                             install_dir : libv4l2privdir,
+                            c_args : v4l2_wrapper_args,
                             dependencies : v4l2convert_deps,
                             include_directories : v4l2_utils_incdir)
lib/libv4l2/v4l2convert.c +0 -5
index 97bed9a9..396ed3ea 100644
@@ -23,11 +23,6 @@
 /* prevent GCC 4.7 inlining error */
 #undef _FORTIFY_SOURCE
 
-/* ensure we see *64 variants and they aren't transparently used */
-#undef _LARGEFILE_SOURCE
-#undef _FILE_OFFSET_BITS
-#define _LARGEFILE64_SOURCE 1
-
 #include <stdarg.h>
 #include <stdlib.h>
 #include <fcntl.h>
meson.build +10 -0
index 1e76b0f4..75398917 100644
@@ -47,6 +47,16 @@ common_arguments = [
     '-include', meson.current_build_dir() / 'config.h',
 ]
 
+v4l2_wrapper_args = [
+    # As the library needs to provide both 32-bit and 64-bit versions
+    # of file operations, disable transparent large file support (fixes
+    # 'Error: symbol `open64/mmap64' is already defined' compile failure
+    # otherwise)
+    '-U_FILE_OFFSET_BITS',
+    '-D_FILE_OFFSET_BITS=32',
+    '-D_LARGEFILE64_SOURCE',
+]
+
 v4l2_utils_incdir_arr = [
     'lib' / 'include',
 ]
utils/v4l2-tracer/meson.build +1 -12
index ed2c1df8..47c0a1f6 100644
@@ -70,21 +70,10 @@ libv4l2_tracer_incdir = [
     v4l2_utils_incdir,
 ]
 
-libv4l2_tracer_cpp_args = [
-    # Meson enables large file support unconditionally, which redirects file
-    # operations to 64-bit versions. This results in some symbols being
-    # renamed, for instance open() being renamed to open64(). As the library
-    # needs to provide both 32-bit and 64-bit versions of file operations,
-    # disable transparent large file support.
-    '-U_FILE_OFFSET_BITS',
-    '-D_FILE_OFFSET_BITS=32',
-    '-D_LARGEFILE64_SOURCE',
-]
-
 libv4l2tracer = shared_module('v4l2tracer',
                               libv4l2tracer_sources,
                               install : true,
-                              cpp_args : libv4l2_tracer_cpp_args,
+                              cpp_args : v4l2_wrapper_args,
                               dependencies : libv4l2tracer_deps,
                               include_directories : libv4l2_tracer_incdir)
 
Signature · 1 line
2.40.0