diff mbox series

[1/1] package/mjpg-streamer: fix undefined symbol error

Message ID 20240324185659.1777379-1-bernd@kuhls.net
State Changes Requested
Headers show
Series [1/1] package/mjpg-streamer: fix undefined symbol error | expand

Commit Message

Bernd Kuhls March 24, 2024, 6:56 p.m. UTC
Fixes runtime error:

    dlopen: /usr/lib/mjpg-streamer/input_uvc.so: undefined symbol: resolutions_help

Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
---
 ...ix-undefined-symbol-resolutions_help.patch | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 package/mjpg-streamer/0001-input_uvc-fix-undefined-symbol-resolutions_help.patch

Comments

Thomas Petazzoni May 10, 2024, 7:49 p.m. UTC | #1
Hello Bernd,

On Sun, 24 Mar 2024 19:56:59 +0100
Bernd Kuhls <bernd@kuhls.net> wrote:

> +diff --git a/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt b/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
> +index 72b24fa..90bbfa0 100644
> +--- a/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
> ++++ b/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
> +@@ -22,6 +22,7 @@ if (PLUGIN_INPUT_UVC)
> +     MJPG_STREAMER_PLUGIN_COMPILE(input_uvc dynctrl.c
> +                                            input_uvc.c
> +                                            jpeg_utils.c
> ++                                           ../../utils.c
> +                                            v4l2uvc.c)

Thanks for the patch. Are you sure this is the right fix?

Indeed, the way I understand it is that there is a main executable
(mjpg-streamer), which loads using dlopen() a number of plugins. This
symbol resolutions_help is already provided by the mjpg-streamer main
executable itself, so why can't the dlopen()'ed plugin use it? Here
you're basically duplicating this symbol into the plugin itself. Is
that the right way to fix this issue? I am not sure 100% clear on what
are the rules that allow a dlopen() library to use the symbols of the
"thing" that dlopen()s the plugin, but it seems like it is possible.

Also, there is another plugin, input_opencv, which uses the exact same
symbol, so it would also need to be fixed.

Opinion from upstream here would be greatly appreciated to see how they
chose to design their code base.

Thanks!

Thomas
Thomas Petazzoni Aug. 5, 2024, 10:21 p.m. UTC | #2
Hello Bernd,

On Fri, 10 May 2024 21:49:57 +0200
Thomas Petazzoni via buildroot <buildroot@buildroot.org> wrote:

> Thanks for the patch. Are you sure this is the right fix?
> 
> Indeed, the way I understand it is that there is a main executable
> (mjpg-streamer), which loads using dlopen() a number of plugins. This
> symbol resolutions_help is already provided by the mjpg-streamer main
> executable itself, so why can't the dlopen()'ed plugin use it? Here
> you're basically duplicating this symbol into the plugin itself. Is
> that the right way to fix this issue? I am not sure 100% clear on what
> are the rules that allow a dlopen() library to use the symbols of the
> "thing" that dlopen()s the plugin, but it seems like it is possible.
> 
> Also, there is another plugin, input_opencv, which uses the exact same
> symbol, so it would also need to be fixed.
> 
> Opinion from upstream here would be greatly appreciated to see how they
> chose to design their code base.

Since I had no feedback from you on this question, I had a deeper look,
and indeed your proposed fix is incorrect: the plugin should really
call into the resolutions_help() function of the mjpg_streamer
executable.

It doesn't work because the resolutions_help() symbol is not explicitly
exported *and* we are stripping our executables.

An easy solution is to export all symbols of the main binary, which can
be achieved by adding:

set_property(TARGET mjpg_streamer PROPERTY ENABLE_EXPORTS ON)

into the CMakeLists.txt file. A better solution would be to only export
those symbols which are needed by the plugins, but obviously it
requires a bit more work.

I couldn't test at runtime, but before my patch, I can clearly see that
the stripped mjpg_streamer no longer has any symbol table containing
resolutions_help(), while after my patch it contains a symbol table
with this symbol.

Could you give it a try and report back?

Thanks a lot!

Thomas
diff mbox series

Patch

diff --git a/package/mjpg-streamer/0001-input_uvc-fix-undefined-symbol-resolutions_help.patch b/package/mjpg-streamer/0001-input_uvc-fix-undefined-symbol-resolutions_help.patch
new file mode 100644
index 0000000000..f7feb2bb07
--- /dev/null
+++ b/package/mjpg-streamer/0001-input_uvc-fix-undefined-symbol-resolutions_help.patch
@@ -0,0 +1,27 @@ 
+From 32bd867cc8a51568c031430a2886712438052945 Mon Sep 17 00:00:00 2001
+From: Bernd Kuhls <bernd@kuhls.net>
+Date: Sat, 9 Mar 2024 23:15:52 +0100
+Subject: [PATCH] input_uvc: fix 'undefined symbol: resolutions_help'
+
+Upstream: https://github.com/jacksonliam/mjpg-streamer/pull/401
+
+Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
+---
+ mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt b/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
+index 72b24fa..90bbfa0 100644
+--- a/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
++++ b/mjpg-streamer-experimental/plugins/input_uvc/CMakeLists.txt
+@@ -22,6 +22,7 @@ if (PLUGIN_INPUT_UVC)
+     MJPG_STREAMER_PLUGIN_COMPILE(input_uvc dynctrl.c
+                                            input_uvc.c
+                                            jpeg_utils.c
++                                           ../../utils.c
+                                            v4l2uvc.c)
+ 
+     if (V4L2_LIB)
+-- 
+2.39.2
+