I need to load functions from a custom library on an embedded platform that does not have a lot of the usual tools (e.g. no ldd, no gdb, etc). I'm cross compiling to that platform.
Suppose I want to use the function foo
from libx.so
. Now the platform has libx.so
included in the system libs directory, but I want my program to pick it up from another location. I've set the LD_LIBRARY_PATH accordingly, but I strongly suspect my program is still picking up the system one.
I tried the following:
Dl_info dl_info;
dladdr((void*)foo, &dl_info);
fprintf(stdout, "module %s loaded\n", dl_info.dli_fname);
But this returns a.out
, which is not helpful.
I also tried:
Dl_info dl_info;
link_map* lm;
int code = dladdr1((void*)foo, &dl_info, (void**)(&lm), RTLD_DL_LINKMAP);
if (code == 0)
{
std::cout << "Failed" << std::endl;
return 0;
}
fprintf(stdout, "module %s loaded\n", lm->l_name);
And I get an empty string. Note, the return code was not 0.
Any other methods I can try?
Thanks.
You can look at
/proc/<pid>/maps
(or/proc/self/maps
to look at the mappings of the current process). This will show all files that are mmaped into the process address space, which will include shared libraries.