libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dlopen from dlopend library question


From: Gleb Natapov
Subject: Re: dlopen from dlopend library question
Date: Mon, 8 Aug 2005 12:20:51 +0300

On Mon, Aug 08, 2005 at 11:10:08AM +0200, Ralf Wildenhues wrote:
> Hi Gleb,
> 
> * Gleb Natapov wrote on Sun, Aug 07, 2005 at 11:31:54AM CEST:
> > > > Program 'prog' calls dlopen(liba.so, RTLD_GLOBAL), in constructor 
> > > > liba.so
> > > > calls dlopen(plugin.so) and this call fails with unresolved symbols
> > > > from liba.so.
> > > > 
> > > > If we add function init_a() to liba.so and move dlopen(plugin.so) from 
> > > > constructor to the function and we call this function from 'prog' after
> > > > dlopen (liba.so, RTLD_GLOBAL) then everything works as expected.
> > > 
> > > Best would be if you showed short reproducible code.  Not that I know
> > > whether I could help you then.
> > >
> > Attached. To compile run following:
> > $ gcc liba.c -shared -o liba.so
> > $ gcc plugin.c -shared -o plugin.so
> > $ gcc prog.c -ldl -o prog
> 
> Some notes:
> - In general, you _must_ use -fPIC to compile the code that ends up in
>   shared objects.  Above will fail blatantly on x86_64, for example.
> 
> - You should make use of dlerror, for example like this, in
>   the failure case:
>   fprintf (stderr, "Load of plugin.so failed: %s\n", dlerror());
> 
I wrote it in 5 minutes just for demo :) Original project uses libtool.

> - Quoting 'info gcc Link\ Options':
> | 
> |  (1) On some systems, `gcc -shared' needs to build supplementary stub
> | code for constructors to work.  On multi-libbed systems, `gcc -shared'
> | must select the correct support libraries to link against.  Failing to
> | supply the correct flags may lead to subtle defects.  Supplying them in
> | cases where they are not necessary is innocuous.
> 
> So, for example, using
>   gcc plugin.c -shared -o plugin.so -L. -la
> 
> and then using
> 
>   LD_LIRBARY_PAH=. ./prog
> 
> will succeed.
I know that linking plugin.so with liba solves the issue, but 
the question is why RTLD_GLOBAL doesn't take effect in library init function. 
Currently the problem was solved by not calling dlopen in init.

--
                        Gleb.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]