[v4,2/2] v4l2: v4l2_compat: Compile compat layer core with native time_t
diff mbox series

Message ID 20261122220724.2951625-3-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • v4l2_compat: Support 64-bit time_t on 32-bit systems
Related show

Commit Message

Laurent Pinchart Nov. 22, 2026, 10:07 p.m. UTC
On 32-bit systems, the whole libcamera V4L2 compatibility layer is
compiled with 32-bit time_t as a consequence of disabling transparent
large file support that in turn requires undefining _TIME_BITS. The
compatibility layer ends up using the 32-bit time_t layout of V4L2 ioctl
structures. This breaks applications compiled with 64-bit time_t
support.

Fixing this for all use cases requires translating between structures
that use 32-bit and 64-bit time_t. A simpler partial solution is however
possible for the most common cases.

Transparent large file support and time_t impact different parts of the
V4L2 compatibility layer. The former is only needed in the entry points,
handled in v4l2_compat.cpp, while the latter only impacts the V4L2 ioctl
handlers in v4l2_camera_proxy.cpp. We can compile the entry points with
transparent large file support disabled (and therefore with 32-bit
time_t), and the rest of the compatibility later with the system
defaults.

Applications using the same time_t size as the system default will work
correctly. Two cases will still be unsupported:

- Applications using 64-bit time_t on a 32-bit time_t system
- Applications using 32-bit time_t on a 64-bit time_t system

The former should be very rare, as systems are transitioning to 64-bit
time_t. The latter is likely less rare, but is still not a very common
use case.

Implement the simpler fix for the time being. If hybrid time_t use cases
need to be supported, translation between ioctl structures will be
implemented.

Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/290
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Prasanth R <ragaprasanth@gmail.com>
Tested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
---
Changes since v3:

- Flip libraries around: compile v4l2-compat.cpp in the static library
  and name it v4l2-compat-interceptor
- Set -fvisibility=hidden for the outer library, not the inner library
---
 src/v4l2/meson.build | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build
index 2c0404147183..d0dd19fdaf02 100644
--- a/src/v4l2/meson.build
+++ b/src/v4l2/meson.build
@@ -6,15 +6,11 @@  if not v4l2_enabled
     subdir_done()
 endif
 
-v4l2_compat_sources = files([
-    'v4l2_camera.cpp',
-    'v4l2_camera_file.cpp',
-    'v4l2_camera_proxy.cpp',
+v4l2_compat_interceptors_sources = files([
     'v4l2_compat.cpp',
-    'v4l2_compat_manager.cpp',
 ])
 
-v4l2_compat_cpp_args = [
+v4l2_compat_interceptors_cpp_args = [
     # Meson enables large file support unconditionally, which redirect file
     # operations to 64-bit versions. This results in some symbols being
     # renamed, for instance open() being renamed to open64(). As the V4L2
@@ -24,12 +20,29 @@  v4l2_compat_cpp_args = [
     '-D_FILE_OFFSET_BITS=32',
     '-D_LARGEFILE64_SOURCE',
     '-U_TIME_BITS',
+]
+
+v4l2_compat_interceptors = static_library('v4l2-compat-interceptors',
+                                          v4l2_compat_interceptors_sources,
+                                          install : false,
+                                          dependencies : [libcamera_private],
+                                          cpp_args : v4l2_compat_interceptors_cpp_args)
+
+v4l2_compat_sources = files([
+    'v4l2_camera.cpp',
+    'v4l2_camera_file.cpp',
+    'v4l2_camera_proxy.cpp',
+    'v4l2_compat_manager.cpp',
+])
+
+v4l2_compat_cpp_args = [
     '-fvisibility=hidden',
 ]
 
 v4l2_compat = shared_library('v4l2-compat',
                              v4l2_compat_sources,
                              name_prefix : '',
+                             link_whole : v4l2_compat_interceptors,
                              install : true,
                              install_dir : libcamera_libexecdir,
                              dependencies : [libcamera_private, libdl],