Skip to contentSkip to conversation

v4l2-tracer: fix 'symbol mmap64/open64 is already defined' compile failure

PATCH In review Peter Seiderer 2 participants 3 messages Mar 30, 2023 – Mar 31, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l2-tracer: fix 'symbol mmap64/open64 is already defined' compile failure

Compiling for RPi4 (64-bit) using buildroot failes with the following error:

.../host/bin/aarch64-buildroot-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../.. -I../../utils/common -I.../aarch64-buildroot-linux-gnu/sysroot/usr/include/json-c -I../../lib/include -Wall -Wpointer-arith -D_GNU_SOURCE -I../../include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1 -std=gnu++11 -c libv4l2tracer.cpp -fPIC -DPIC -o .libs/libv4l2tracer_la-libv4l2tracer.o /tmp/ccfbectY.s: Assembler messages:
/tmp/ccfbectY.s:208: Error: symbol `open64' is already defined
/tmp/ccfbectY.s:762: Error: symbol `mmap64' is already defined

The preprocessor output shows:

  [...]
  extern "C" {
  # 61 ".../host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h" 3 4
  extern void * mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, __off64_t __offset) noexcept (true) __asm__ ("" "mmap64");
  [...]
  extern void *mmap64 (void *__addr, size_t __len, int __prot,
         int __flags, int __fd, __off64_t __offset) noexcept (true);

And host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h:

56 #ifndef __USE_FILE_OFFSET64
57 extern void *mmap (void *__addr, size_t __len, int __prot,
58 int __flags, int __fd, __off_t __offset) __THROW;
59 #else
60 # ifdef __REDIRECT_NTH
61 extern void * __REDIRECT_NTH (mmap,
62 (void *__addr, size_t __len, int __prot,
63 int __flags, int __fd, __off64_t __offset),
64 mmap64);
65 # else
66 # define mmap mmap64
67 # endif
68 #endif
69 #ifdef __USE_LARGEFILE64
70 extern void *mmap64 (void *__addr, size_t __len, int __prot,
71 int __flags, int __fd, __off64_t __offset) __THROW;
72 #endif

Fix it by applying the same undef _LARGEFILE_SOURCE/_FILE_OFFSET_BITS, define _LARGEFILE64_SOURCE as in as in lib/libv4l1/v4l1compat.c

---
Notes:

- maybe the 'defined(linux) && defined(__GLIBC__)' protection present in lib/libv4l1/v4l1compat.c for open64/mmap64 is needed for non glibc compiles of utils/v4l2-tracer/libv4l2tracer.cpp too?

---
 utils/v4l2-tracer/libv4l2tracer.cpp | 5 +++++
 1 file changed, 5 insertions(+)
utils/v4l2-tracer/libv4l2tracer.cpp +5 -0
index a9f039c7..1e3900db 100644
@@ -3,6 +3,11 @@
  * Copyright 2022 Collabora Ltd.
  */
 
+/* ensure we see *64 variants and they aren't transparently used */
+#undef _LARGEFILE_SOURCE
+#undef _FILE_OFFSET_BITS
+#define _LARGEFILE64_SOURCE 1
+
 #include "trace.h"
 #include <dlfcn.h>
 #include <stdarg.h>
Signature · 1 line
2.40.0
#1 lore raw

Hi Peter,

Quoted 38 lines · Peter Seiderer

Compiling for RPi4 (64-bit) using buildroot failes with the following error:

.../host/bin/aarch64-buildroot-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../.. -I../../utils/common -I.../aarch64-buildroot-linux-gnu/sysroot/usr/include/json-c -I../../lib/include -Wall -Wpointer-arith -D_GNU_SOURCE -I../../include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1 -std=gnu++11 -c libv4l2tracer.cpp -fPIC -DPIC -o .libs/libv4l2tracer_la-libv4l2tracer.o /tmp/ccfbectY.s: Assembler messages:
/tmp/ccfbectY.s:208: Error: symbol `open64' is already defined
/tmp/ccfbectY.s:762: Error: symbol `mmap64' is already defined

The preprocessor output shows:

  [...]
  extern "C" {
  # 61 ".../host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h" 3 4
  extern void * mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, __off64_t __offset) noexcept (true) __asm__ ("" "mmap64");
  [...]
  extern void *mmap64 (void *__addr, size_t __len, int __prot,
         int __flags, int __fd, __off64_t __offset) noexcept (true);

And host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h:

56 #ifndef __USE_FILE_OFFSET64
57 extern void *mmap (void *__addr, size_t __len, int __prot,
58 int __flags, int __fd, __off_t __offset) __THROW;
59 #else
60 # ifdef __REDIRECT_NTH
61 extern void * __REDIRECT_NTH (mmap,
62 (void *__addr, size_t __len, int __prot,
63 int __flags, int __fd, __off64_t __offset),
64 mmap64);
65 # else
66 # define mmap mmap64
67 # endif
68 #endif
69 #ifdef __USE_LARGEFILE64
70 extern void *mmap64 (void *__addr, size_t __len, int __prot,
71 int __flags, int __fd, __off64_t __offset) __THROW;
72 #endif

Quoted 2 lines

Fix it by applying the same undef _LARGEFILE_SOURCE/_FILE_OFFSET_BITS, define _LARGEFILE64_SOURCE as in as in lib/libv4l1/v4l1compat.c

If I look at 'man feature_test_macros', then that man page suggests that _LARGEFILE64_SOURCE is out of date and instead you should use '#define _FILE_OFFSET_BITS 64'.

Can you test that? If this works, then it should be applied to v4l1compat.c as well.

Quoted 8 lines

---
Notes:

- maybe the 'defined(linux) && defined(__GLIBC__)' protection present in lib/libv4l1/v4l1compat.c for open64/mmap64 is needed for non glibc compiles of utils/v4l2-tracer/libv4l2tracer.cpp too?

I think we need this too. If nothing else, it is consistent.

Regards,

Hans

Quoted 20 lines
---
 utils/v4l2-tracer/libv4l2tracer.cpp | 5 +++++
 1 file changed, 5 insertions(+)
utils/v4l2-tracer/libv4l2tracer.cpp +5 -0
index a9f039c7..1e3900db 100644
@@ -3,6 +3,11 @@
  * Copyright 2022 Collabora Ltd.
  */
 
+/* ensure we see *64 variants and they aren't transparently used */
+#undef _LARGEFILE_SOURCE
+#undef _FILE_OFFSET_BITS
+#define _LARGEFILE64_SOURCE 1
+
 #include "trace.h"
 #include <dlfcn.h>
 #include <stdarg.h>
#2 lore raw

Hello Hans,

Quoted 44 lines · Hans Verkuil

Hi Peter,

Quoted 38 lines · Peter Seiderer

Compiling for RPi4 (64-bit) using buildroot failes with the following error:

.../host/bin/aarch64-buildroot-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../.. -I../../utils/common -I.../aarch64-buildroot-linux-gnu/sysroot/usr/include/json-c -I../../lib/include -Wall -Wpointer-arith -D_GNU_SOURCE -I../../include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1 -std=gnu++11 -c libv4l2tracer.cpp -fPIC -DPIC -o .libs/libv4l2tracer_la-libv4l2tracer.o /tmp/ccfbectY.s: Assembler messages:
/tmp/ccfbectY.s:208: Error: symbol `open64' is already defined
/tmp/ccfbectY.s:762: Error: symbol `mmap64' is already defined

The preprocessor output shows:

  [...]
  extern "C" {
  # 61 ".../host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h" 3 4
  extern void * mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, __off64_t __offset) noexcept (true) __asm__ ("" "mmap64");
  [...]
  extern void *mmap64 (void *__addr, size_t __len, int __prot,
         int __flags, int __fd, __off64_t __offset) noexcept (true);

And host/aarch64-buildroot-linux-gnu/sysroot/usr/include/sys/mman.h:

56 #ifndef __USE_FILE_OFFSET64
57 extern void *mmap (void *__addr, size_t __len, int __prot,
58 int __flags, int __fd, __off_t __offset) __THROW;
59 #else
60 # ifdef __REDIRECT_NTH
61 extern void * __REDIRECT_NTH (mmap,
62 (void *__addr, size_t __len, int __prot,
63 int __flags, int __fd, __off64_t __offset),
64 mmap64);
65 # else
66 # define mmap mmap64
67 # endif
68 #endif
69 #ifdef __USE_LARGEFILE64
70 extern void *mmap64 (void *__addr, size_t __len, int __prot,
71 int __flags, int __fd, __off64_t __offset) __THROW;
72 #endif

Quoted 2 lines

Fix it by applying the same undef _LARGEFILE_SOURCE/_FILE_OFFSET_BITS, define _LARGEFILE64_SOURCE as in as in lib/libv4l1/v4l1compat.c

Quoted 6 lines

If I look at 'man feature_test_macros', then that man page suggests that _LARGEFILE64_SOURCE is out of date and instead you should use '#define _FILE_OFFSET_BITS 64'.

Can you test that? If this works, then it should be applied to v4l1compat.c as well.

Did you mean as utils/v4l2-tracer/meson.build all ready does:

73 libv4l2_tracer_cpp_args = [

 74     # Meson enables large file support unconditionally, which redirects file
 75     # operations to 64-bit versions. This results in some symbols being
 76     # renamed, for instance open() being renamed to open64(). As the library
 77     # needs to provide both 32-bit and 64-bit versions of file operations,
 78     # disable transparent large file support.
 79     '-U_FILE_OFFSET_BITS',
 80     '-D_FILE_OFFSET_BITS=32',
 81     '-D_LARGEFILE64_SOURCE',

82 ]

Did my previous test against the 1.24.1 release using the autoconf/automake build system...

A quick (compile) test for lib/libv4l1/v4l1compat.c with

	#undef _FILE_OFFSET_BITS
	#define _FILE_OFFSET_BITS 32
	#define _LARGEFILE64_SOURCE 1

seems to work...

Quoted 11 lines
Quoted 9 lines

---
Notes:

- maybe the 'defined(linux) && defined(__GLIBC__)' protection present in lib/libv4l1/v4l1compat.c for open64/mmap64 is needed for non glibc compiles of utils/v4l2-tracer/libv4l2tracer.cpp too?

I think we need this too. If nothing else, it is consistent.

So this patch should be o.k. for the stable-1.24 branch?

Will send one adding the 'defined(linux) && defined(__GLIBC__)' to v4l2-tracer and one changing the in-file undef/define to the meson.build solution for lib/libv4l1/v4l1compat.c (in case this is o.k. here)...

Regards,
Peter

Quoted 26 lines

Regards,

Hans

Quoted 20 lines
---
 utils/v4l2-tracer/libv4l2tracer.cpp | 5 +++++
 1 file changed, 5 insertions(+)
utils/v4l2-tracer/libv4l2tracer.cpp +5 -0
index a9f039c7..1e3900db 100644
@@ -3,6 +3,11 @@
  * Copyright 2022 Collabora Ltd.
  */
 
+/* ensure we see *64 variants and they aren't transparently used */
+#undef _LARGEFILE_SOURCE
+#undef _FILE_OFFSET_BITS
+#define _LARGEFILE64_SOURCE 1
+
 #include "trace.h"
 #include <dlfcn.h>
 #include <stdarg.h>