Hi,
Unless I'm missing something, it seems that DirectFB's module loading
code is utterly broken for modules where the constructor is not invoked
automatically, e.g. due to miscompilation. (I am not sure why it exists
in the first place, though. Just for old and broken compilers/linkers?)
Currently, DirectFB's lib/direct/modules.c will try to call a function
with a name of shared_library_name with lib and .so removed in case the
module did not have an __attribute__((constructor)) function. This works
for many cases of the existing modules in the DirectFB source tree, but
not for all:
1) the constructor function name of many (but not all) modules has had
the string "_ctor" added a while ago.
2) some modules don't fit into this naming scheme (all which use the
DIRECT_INTERFACE_IMPLEMENTATION macro to implement an interface), as
they use different cApITAliSaTION rules for the function type name vs.
the shared library name (e.g. IDirectFBImageProvider_GIF_ctor() vs.
libidirectfbimageprovider_gif.so).
These two actually mean that trying to call a 'default' constructor
function after dlopen() has not been helpful for solving anything for
quite a while.
In addition, and this is more severe, even if the constructor can be
fixed, we'll likely get memory leaks. The destructor will not be called
and nobody would notice, because things will appear to be working,
making it hard to find the reason. OK, one could add printf()s and
warnings, but still. Or of course add even more code to somehow work
around the issue.
The question to be asked - would it be useful? And it appears to me that
given the existing code is not working in many cases (and nobody noticed
in the last couple of years(!) (AFAIR)), and we may get memory leaks,
that today it is not. I propose the removal of the related code.
Please see the patch attached.
What do you think?
Cheers,
Andre'
From 043cee291bf5d41c5cfbf1c1d5b7601699e4632c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Draszik?= <andre.dras...@st.com>
Date: Mon, 22 Nov 2010 10:27:51 +0000
Subject: [PATCH] Revert "If a dlopen()'ed module did not register itself, try
to dlsym() and call"
This reverts commit f1a8923dc6a4499e0bb24814e3e251753850043b.
Currently, DirectFB's lib/direct/modules.c will try to call a function with
a name of shared_library_name with lib and .so removed in case the module
did not have an __attribute__((constructor)) function. This works for many
cases of the existing modules in the DirectFB source tree, but not for all:
1) the constructor function name of many (but not all) modules has had the
string "_ctor" added a while ago.
2) some modules don't fit into this naming scheme (all which use the
DIRECT_INTERFACE_IMPLEMENTATION macro to implement an interface), as they
use different cApITAliSaTION rules for the function type name vs. the
shared library name (e.g. IDirectFBImageProvider_GIF_ctor() vs.
libidirectfbimageprovider_gif.so).
These two actually mean that trying to call a 'default' constructor function
after dlopen() has not been useful for quite a while.
---
lib/direct/modules.c | 35 +++++++----------------------------
1 files changed, 7 insertions(+), 28 deletions(-)
diff --git a/lib/direct/modules.c b/lib/direct/modules.c
index 8b34a4a..57e6382 100644
--- a/lib/direct/modules.c
+++ b/lib/direct/modules.c
@@ -249,38 +249,17 @@ direct_modules_explore_directory( DirectModuleDir
*directory )
if ((handle = open_module( module )) != NULL) {
if (!module->loaded) {
- int len;
- void (*func)( void );
-
- D_ERROR( "Direct/Modules: Module '%s' did not register
itself after loading! "
- "Trying default module constructor...\n",
entry->d_name );
-
- len = strlen( entry->d_name );
-
- entry->d_name[len-3] = 0;
-
- func = dlsym( handle, entry->d_name + 3 );
- if (func) {
- func();
+ dlclose( handle );
- if (!module->loaded) {
- D_ERROR( "Direct/Modules: ... even did not
register after "
- "explicitly calling the module
constructor!\n" );
- }
- }
- else {
- D_ERROR( "Direct/Modules: ... default contructor not
found!\n" );
- }
+ D_ERROR( "Direct/Modules: Module '%s' did not "
+ "register itself after loading!\n",
+ entry->d_name );
- if (!module->loaded) {
- module->disabled = true;
+ module->disabled = true;
- direct_list_prepend( &directory->entries,
- &module->link );
- }
+ direct_list_prepend( &directory->entries, &module->link );
}
-
- if (module->disabled) {
+ else if (module->disabled) {
module->loaded = false;
/* may call direct_modules_unregister() */
--
1.7.1
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev