Operating System - HP-UX
1834020 Members
2718 Online
110063 Solutions
New Discussion

shl_load function Problem

 
Pravin B
Occasional Contributor

shl_load function Problem

I am having libAmdOra.sl shared library. I wanted to access AmdOraStartup function which is inside that shared library.

FILENAME : TestLib.cpp

#include
#include
#include
#include

int main()
{
int status;
void *value;
shl_t shl_handle = shl_load("libAmdOra.sl",BIND_DEFERRED|DYNAMIC_PATH,0L);
if (shl_handle == NULL)
{
printf("shl_load error. rc = %sn", strerror(errno));
return -1;
}

printf("shl_load successn");

status = shl_findsym(&shl_handle, "AmdOraStartup", 0, value);
if (status == -1)
{
printf("findSym error. rc = %sn",strerror(errno));
return -1;
}
printf("findSym successn");
return 0;
}

I am working on HPUX11.0 machine & using aCC 3.15 compiler.

TESTDIR>aCC +DAportable TestLib.cpp -ldld
TESTDIR>a.out
/usr/lib/dld.sl: Can't shl_load() a library containing Thread Local Storage: /usr/lib/libpthread.1
/usr/lib/dld.sl: Exec format error
shl_load error. rc = Exec format error

----------------------
This shared library libAmdOra.sl contains all oracle related functions including AmdOraStartup function. made using -Z (compile) optio) and -b (link) option of aCC.

If anybody knows answer, please mail me.
Thank You

-Pravin
2 REPLIES 2
Mike Stroyan
Honored Contributor

Re: shl_load function Problem

The libAmdOra.sl library is linked against libpthread.sl.
The libpthread.sl library contains thread local storage variables.
The shl_load call can't bring in shared libraries that declare thread local storage variables.
You will need to link your a.out with at least libpthread.sl so it will be present before shl_load.
You can check what shared libraries are brought in by using "odump -sllibloadlist libAmdOra.sl". You can
check for the use of TLS in a shared library by using nm and grep to look for "$TBSS$" data-
# nm /usr/lib/libpthread.sl | grep TBSS
__self_pthread_d | 0|extern|data |$TBSS$
__self_pthread_t | 8|extern|data |$TBSS$

Thread local storage is discussed in "man pthread",
http://devresource.hp.com/STK/man/11.00/pthread_3t.html
and in "man shl_load",
http://devresource.hp.com/STK/man/11.00/shl_load_3x.html
==========================================================
Kiran N. Mehta
Advisor

Re: shl_load function Problem

I think you are going to get a crash (in shl_findsym) after you get shl_load to return successfully.

Because you want shl_findsym( ) to output a pointer to the stated function (AmdOraStartup), you have to provide it the address of a location where it can write a pointer-to-the-function whose signature should be known. See the nice example in the HP-UX Linker and Libraries User's Guide:
http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B2355-90655/B2355-90655_top.html&con=/hpux/onlinedocs/B2355-90655/00/00/55-con.html&toc=/hpux/onlinedocs/B2355-90655/00/00/55-toc.html&searchterms=shl_findsym&queryid=20001023-045431

Kiran