[PyQt] SIP Problem dynamic loading in wrapped library

Jens Thoms Toerring jt at toerring.de
Fri Apr 1 11:51:37 BST 2011


Hi

On Thu, Mar 31, 2011 at 11:35:00PM +0200, Jens Thoms Toerring wrote:
>   yesterday I wrote about a problem with a SIP wrapped
> shared library (written in C++) I have that in turn
> dynamically loads further shared libraries - which fails
> due to undefined symbols, but which definitely are defined
> in the wrapped library.

Just for the record: I finally found out what's going on. 
The main problem was that (at least some of) the plug-in
libraries were attempted to load already during the ini-
tialization of the wrapped library (there's a singleton
class for dealing with the plug-ins and the instance of
the class is created when the library is loaded and,
within the constructor some plug-ins are attempted to
load).

This wasn't a problem when linking a C++ program against
the wrapped class. But the wrapper class is dlopen()'ed
when it's import'ed. And this in turn leads to the wrap-
ped class being loaded, which then also tries to call
dlopen() - i.e. from within a dlopen() call. And that
fails. Now, dlopen() is not listed as a reentrant func-
tions, so this seems to explain things sufficiently.

That it worked when setting LD_PRELOAD to the wrapped
library is also no mystery anymore: with that setting the
library isn't dlopen()'ed but instead loaded while the
program (python) is started, just like a shared library
the program is linked against. Thus in this case dlopen()
isn't used and thus there's no reentrancy problem.

But the hint David Boddie gave is still valuable: Python
seems to 'import' modules with dlopen() with RTDL_LOCAL
and not RTLD_GLOBAL per default. So it is still necessary
to tell it explicitely to switch to RTLD_GLOBAL, using the
sys.setdlopenflags() function, before loading the wrapper
library, otherwise dlopen() calls from within the wrapped
library still will fail.
                           Best regards, Jens
-- 
  \   Jens Thoms Toerring  ________      jt at toerring.de
   \_______________________________      http://toerring.de


More information about the PyQt mailing list