Operating System - Linux
1748232 Members
3320 Online
108759 Solutions
New Discussion юеВ

Regarding behaviour of dlopen in HP-UX

 
sarram
Occasional Advisor

Regarding behaviour of dlopen in HP-UX

I am trying to run an application on HPUX11.11 platform. I am using aCC(c++ Compiler) and its version is A.03.55.

While starting of the application, it will load some .sl(for example a.sl, b.sl, c.sl etc) files using shl_load.

In the middle of the application, I will once again try to load a.sl and b.sl and get some information and will close. This we are doing with dlopen() and dlclose().

As far as i know , if we try to load shared library file which is already loaded, again it will not load the library but it will increase the reference count. This behaviour is in solaris. Is the Same behaviour for HP-UX?

When trying to do dlclose(), a.sl is still there in memory but b.sl is unloaded completely. But this is not happening on the solaris, both shared libraries are still present. Our requirement is in HP-UX also both libraries should be present.

Can anyone tell me why this is happening? Do i need to specify any special flags?

Quick response is appreciated.

Thanks





4 REPLIES 4
harry d brown jr
Honored Contributor

Re: Regarding behaviour of dlopen in HP-UX

from "man dlclose":

WARNINGS
>>A successful invocation of dlclose does not guarantee that the objects associated with handle have actually been removed from the address space of the process. Objects loaded by one invocation of dlopen may also be loaded by another invocation of dlopen. The same object may also be opened multiple times. An object is not removed from the address space until all references to that object through an explicit dlopen invocation have been closed and all other objects implicitly referencing that object have also been closed.

>>Once an object has been closed by dlclose, referencing symbols contained in that object can cause undefined behavior.

Also, can I assume you are using the -ldl flag with the compiler or with the loader?

live free or die
harry d brown jr
Live Free or Die
sarram
Occasional Advisor

Re: Regarding behaviour of dlopen in HP-UX

Thanks Harry.

Whether i have to compile the application with -ldl or compile the shared library(a.sl) with -ldl?

Application is not compiled with -ldl.
But if i want to compile what is the path of libdl.sl file?

Regards
harry d brown jr
Honored Contributor

Re: Regarding behaviour of dlopen in HP-UX

/usr/lib/pa20_64/libdl.1
with symbolic links pointing to it:

/usr/lib/pa20_64/libdl.sl -> ./libdl.1

live free or die
harry d brown jr
Live Free or Die
Peter Nikitka
Honored Contributor

Re: Regarding behaviour of dlopen in HP-UX

Hi,

you should add
-ldl
to the linker commandline for all executables or shared objects calling dlopen().

In Solaris (as in HP-UX or Linux) you get a handle after with a successful call to dlopen - even when opening the same more than once.

Using a (once) valid handle after a dlcose() may succeed, when another handle of the same shared object is open. But you won't do that.neither in Solaris or HP-UX.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"