Operating System - HP-UX
1830845 Members
2563 Online
110017 Solutions
New Discussion

Re: Use of dlsym() function hangs process

 
Brian Rasmusson
Occasional Contributor

Use of dlsym() function hangs process

Hi,

we're working on porting an application from Solaris to HP-UX. We use shared object libraries, and when we try getting an address of a function in a .sl file, dlsym simply hangs the process and it starts using a full CPU.

Here is a code snippet:

struct stat statbuf;
if (stat(modulename,&statbuf) == -1)
{
continue;
}

if ((statbuf.st_mode&S_IFMT) != S_IFREG)
{
continue;
}

tmp.module = dlopen(modulename, RTLD_NOW);
if (!tmp.module)
{
continue;
}

/* THIS CALL HANGS */
tmp.descriptor = reinterpret_cast(
dlsym(tmp.module, "networking_descriptor"));


Our compiler flags are the following:

aCC -c +DA2.0 -Aa +Z +w +W495 +W887 +W818 +W819 +W392 +W749 +W655 +W361 +W684 +W431 +O0 +inline_level 0 -g1 +objdebug -I/usr/local/ims_tornado_depend/stlport -DUSING_NAMESPACE_STD='using namespace std' -DSTLport -I/usr/local/ims_tornado_depend/include -D_REENTRANT -I../lib -I../lib/hpux/acc -I../lib/hpux -I./Comm -I./Idapi -I./Networking -DSHLIB_EXT=\".sl\" -D_HPUX_SOURCE -D_REENTRANT -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -/lib/hpux/acc -c Networking.cc -o Networking.o


System info:

$ uname -a
HP-UX n4000 B.11.11 U 9000/800 688379372 unlimited-user license


Any input will be greatly appreciated.

Brian
2 REPLIES 2
Carl Erhorn
Advisor

Re: Use of dlsym() function hangs process

Brian,

If you get into any of the if(...) continue loops, of course you would use 100% of the CPU. They will loop forever, until the variable you are testing changes.

It's not clear to me why you are using this approach. Why not load the library, which is a blocking call that will not return until the module is loaded. Once it's loaded without any error codes, you should be able to make the dlsym call, and get the information you want.

If you really want to only read the symbol information once it's available, because you want to do something else in the background,
there are much better ways to do this. Selecting on an interrupt might be a way to block until the file is loaded.

But the time involved should be very short anyway.

Maybe if you provide some information on what you are trying to accomplish, we can provide a better recommendation on how to do it.

--Carl
Brian Rasmusson
Occasional Contributor

Re: Use of dlsym() function hangs process

Hi Carl,

no, the ifs won't hang because this code snippet is from a loop that loops through all files in a folder. The continue statements will cause the loop to process the next file.

I'm simply trying to load a dynamic library and get the address of a function in that library. It's 32bit code. I have seen others use a workaround and drop the dl functions and use shl_ functions instead.

Brian