dlclose an RTLD_GLOBAL

D

diegofsantos

Hi,
I have created an C++ application that uses shared libs (plugins -
object factories). I need
to load and unload the libs at run time.
I need to open the shared libs with RTLD_GLOBAL parameter and I open
all shared libs without any problems. But when I try to unload the
libs (dlclose), my application crashs (segmentation fault). If I dont
use RTLD_GLOBAL, all works fine.

Here are a piece of my code that loads the libs:

while ( (temp=man->getActiveNameFromFile())!=NULL)
{
void *dlib;

dlib = dlopen(temp,RTLD_NOW|RTLD_GLOBAL);
liblist.push_back(dlib);
if (dlib == NULL)
{
fl_alert(dlerror());
}
}


Note that I put all handles (void *) in a std::list. The dlopen
works fine, all libs are loaded.
Then, I try to unload all libs as the following:

std::list<void *>::iterator it;

for (it=liblist.begin(); it!=liblist.end(); it++)
if (dlclose(*it))
printf("\nErro\n");

But the applications always crash here.

I have tried to use dlclose in reverse order too without success.

Please, can anyone help me?

I'd like to load and unload the shared libs dynamically, but I
couldn't unload it.

Thanks in advance,

Diego
 
P

Piyo

Hi,
I have created an C++ application that uses shared libs (plugins -
object factories). I need
to load and unload the libs at run time.
I need to open the shared libs with RTLD_GLOBAL parameter and I open

Can you explain why you need to load symbols globally instead of
locally?
all shared libs without any problems. But when I try to unload the
libs (dlclose), my application crashs (segmentation fault). If I dont
use RTLD_GLOBAL, all works fine.

It may be the case that some symbol in all of your plugin is trumping
a symbol in your global namespace on loading. Then you unload it but the
program still requires that symbol. This might cause your problem.

Other sources of shared libs crashes are globals
(static or otherwise) or hanging onto any references to objects
instantiated by your plugin. If you do not destroy all globals and/or
refs to objects and then you unload the plugin, the object destructor
is now invalid.

HTH!!
 
P

Piyo

Hi,
I have created an C++ application that uses shared libs (plugins -
object factories). I need
to load and unload the libs at run time.
I need to open the shared libs with RTLD_GLOBAL parameter and I open

Can you explain why you need to load symbols globally instead of
locally?
all shared libs without any problems. But when I try to unload the
libs (dlclose), my application crashs (segmentation fault). If I dont
use RTLD_GLOBAL, all works fine.

It may be the case that some symbol in all of your plugin is trumping
a symbol in your global namespace on loading. Then you unload it but the
program still requires that symbol. This might cause your problem.

Other sources of shared libs crashes are globals
(static or otherwise) or hanging onto any references to objects
instantiated by your plugin. If you do not destroy all globals and/or
refs to objects and then you unload the plugin, the object destructor
is now invalid.

HTH!!
 
D

diegofsantos

Can you explain why you need to load symbols globally instead of


When I try to load symbols locally, I can load and unload libs, but my
application doesnt work fine. I have a base class for all plugins
named moduleBase, as the following:

class moduleBase
{
public:

.
.
.
virtual void setInput (itk::DataObject *in);
virtual void setInput (itk::DataObject *in, int port);
virtual itk::DataObject *getOutput();
virtual itk::DataObject *getOutput(int port);
virtual bool update();
virtual bool run();
void init_module();
.
.
.


The problem is the following: the output of one plugin is an input of
another, and so on... and in the plugin .cxx file I do casting
(itk::DataObject to another type). When I load symbols locally, I
can't do the casting... here is the error:
"cannot cast PKN3itk10DataObjectE to PKN3itk9ImageBaseILJ3EEE"


But if I load the libs with RTLD_GLOBAL, then all works fine.

Could you help me? May I have load the symbols locally ? How can I
solve this problem?

Thanks in advance,
Diego
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top