From: David S. <ds...@sc...> - 2004-04-05 21:32:22
|
On Mon, Apr 05, 2004 at 10:37:32PM +0200, Julio M. Merino Vidal wrote: > So, if I understood it correctly, here is what's going on when I do > 'gst-inspect esdsink': > > 1) gst-inspect finds and opens the esdsink plugin, which is the libgstesd.so > shared file. > 2) It searches for the plugin_init function and calls it. Actually, it looks for gst_plugin_desc, which is a structure that almost always contains a pointer to a function called plugin_init, for historical reasons. > 3) plugin_init from libgstesd.so does a gst_library_load to load the > libgstaudio.so plugin, so that it can later call its functions. > 4) esdsink calls a function from libgstaudio, and should work because the > library has been loaded. But instead, it fails. > > Am I right? Yes. > If so, I've prepared a simple testcase that tries to simulate > this behavior (w/o using any of the gst/glib code, just plain calls to > dlopen and other functions). You can find it here (less than 1kb): > > ftp://ftp.NetBSD.org/pub/NetBSD/misc/jmmv/plugins-tc.tar.gz > > This fails under NetBSD, as seen below: It also fails under Linux. Patch below. I'm not entirely certain how to interpret the POSIX spec in this case. (Have I mentioned that I really dislike dlopen()?) dave... diff -u plugins-tc/Makefile plugins-tc-ds/Makefile --- plugins-tc/Makefile 2004-04-05 13:25:52.000000000 -0700 +++ plugins-tc-ds/Makefile 2004-04-05 14:15:32.000000000 -0700 @@ -1,7 +1,7 @@ all: main plugin1.so plugin2.so main: main.c - cc -o main main.c + cc -o main main.c -ldl plugin1.so: plugin1.c cc -shared -Wl,--export-dynamic -fPIC -DPIC -o plugin1.so plugin1.c -ldl diff -u plugins-tc/main.c plugins-tc-ds/main.c --- plugins-tc/main.c 2004-04-05 13:25:40.000000000 -0700 +++ plugins-tc-ds/main.c 2004-04-05 14:15:12.000000000 -0700 @@ -2,7 +2,7 @@ #include <stdio.h> #if defined(__NetBSD__) -#define RTDL_LAZY DL_LAZY +#define RTLD_LAZY DL_LAZY #endif int @@ -12,7 +12,7 @@ void (*plugin_init)(void); void (*plugin_func)(void); - if ((handle = dlopen("./plugin1.so", RTDL_LAZY)) == NULL) + if ((handle = dlopen("./plugin1.so", RTLD_LAZY)) == NULL) dlerror(); plugin_init = dlsym(handle, "plugin1_init"); diff -u plugins-tc/plugin1.c plugins-tc-ds/plugin1.c --- plugins-tc/plugin1.c 2004-04-05 13:25:34.000000000 -0700 +++ plugins-tc-ds/plugin1.c 2004-04-05 14:16:48.000000000 -0700 @@ -2,13 +2,13 @@ #include <stdio.h> #if defined(__NetBSD__) -#define RTDL_LAZY DL_LAZY +#define RTLD_LAZY DL_LAZY #endif void plugin1_init(void) { - if (dlopen("./plugin2.so", RTDL_LAZY) == NULL) + if (dlopen("./plugin2.so", RTLD_LAZY | RTLD_GLOBAL) == NULL) dlerror(); (void)printf("plugin1 initialized\n"); } dave... |