cancel
Showing results for 
Search instead for 
Did you mean: 

shl_load problem

yangk
Frequent Advisor

shl_load problem

Hi all,

I just want to shl_load a dynamic library just with the name of libray, but it not work.

I load the dynamic library as following:

shl_load("libxxx.sl",BIND_IMMEDIATE,0);

but it will not load library successfully.

When using shl_load with absolute path is will load successfully.

shl_loa("/usr/lib/libxxx.sl",BIND_IMMEDIATE,0);


So is there way to load the dynamic library not with absolute path?
Thanks!
10 REPLIES
Dennis Handly
Acclaimed Contributor

Re: shl_load problem

>So is there way to load the dynamic library not with absolute path?

Check shl_load(3):
shl_load("libxxx.sl", DYNAMIC_PATH|BIND_IMMEDIATE, 0);
yangk
Frequent Advisor

Re: shl_load problem

Hi dennis,

I have try your method but it seems that it also does not work.

shl = shl_load("libcrypto.sl",DYNAMIC_PATH|BIND_IMMEDIATE, 0);

even if I use the putenv to set the SHLIB_PATH=/usr/lib and dld_getenv befor calling the shl_load, it also don't work.

Here is my code:
....
sprintf(strpath, "%s%s","SHLIB_PATH=",argv[1]);
printf("strpath is %s\n",strpath);
putenv(strpath);
str=getenv("SHLIB_PATH");
printf("str is %s\n",str);
dld_getenv();
shl = shl_load("libcrypto.sl",DYNAMIC_PATH | BIND_IMMEDIATE ,0);
if(!shl)
{
printf("shl_load failed\n");
printf("shl_load.rc=%s\n",strerror(errno));
exit(-1);
}
printf("shl_load successed\n");
...


compile the code as following:
cc -g -o shl_load shl_load.c
and run shl_load with /usr/lib args

But it can not load successfully.



yangk
Frequent Advisor

Re: shl_load problem

I have done the test on PA 11.23 system

Re: shl_load problem

you should also do a "chatr +s enable" your program so that dynamic loader honours SHLIB_PATH. see chatr_pa(1) for more info on +s and +b options. or you can pass the linker option +s (-Wl,+s to the compiler) and you dont have to use chatr later.
Dennis Handly
Acclaimed Contributor

Re: shl_load problem

>if I use the putenv to set the SHLIB_PATH=/usr/lib

Since this is the default, it is a waste of time doing that. And if you know it, why not add it to the library string?

As Suprateeka mentioned, the PA default is not to enable SHLIB_PATH. For Integrity, LD_LIBRARY_PATH is enabled by default.
yangk
Frequent Advisor

Re: shl_load problem

hi dennis and Suprateeka,

Ok, now in the code , there is just some lines:

shl_t shl;
shl = shl_load("libcrypto.sl",DYNAMIC_PATH|BIND_IMMEDIATE, 0);
if(shl)
{
printf("shl_load ok\n");
return 0;
}
else
printf("shl_load error\n");



and I compile the code like:
cc -g -o shl_load shl_load.c
and chatr +s enable shl_load
and run ./shl_load

and the error : error: No such file or directory.

It seems that the shl_load is try to load the libcrypto.sl in the current directory,but there is no libcrypto.sl then
it says that no such files.

Dennis Handly
Acclaimed Contributor

Re: shl_load problem

>It seems that the shl_load is try to load the libcrypto.sl in the current directory but there is no libcrypto.sl

Have you exported SHLIB_PATH where it should look? Perhaps I was incorrect about a default.
yangk
Frequent Advisor

Re: shl_load problem

yes,
I have try to export SHLIB_LIB=/usr/lib/,
then it works.

But I just want to know why I use the putenv to set the SHLIB_LIB, it does not work well
as export SHLIB_PATH.

It is so weird to me.

Dennis Handly
Acclaimed Contributor

Re: shl_load problem

>want to know why I use the putenv to set the SHLIB_LIB, it does not work

dld has already read the value of SHLIB_LIB, why should it look again?
yangk
Frequent Advisor

Re: shl_load problem

Ok , i know. Thank you very much!
I will close it!