I am getting issues with dlmopen, but I have successfully used dlopen and dlsym in my cpp program (in linux)
void *lib_handle = dlopen(lib_path, RTLD_NOW);
After this I used dlsym to get the function
function_type = (function_type)dlsym(lib_handle, "function_name")
and this worked fine, I have even successfully called this method.
But when tried to use dlmopen instead of dlopen to get the lib handle, then I am facing issues while calling dlsym on the handle. dlmopen needs an extra param for specifying the namespace where the library should be loaded. I have tried using both the values available (LM_ID_BASE, LM_ID_NEWLM).
void *lib_handle = dlmopen(LM_ID_NEWLM, lib_path, RTLD_NOW)
It fails when we call dlsym to get the symbol address
dlsym(lib_handle, "function_name")
The error is segmentation fault
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7de019b in _dl_lookup_symbol_x (undef_name=0x555555556818 "function_name",
undef_map=0xfffffffff7ff5ae0, ref=0x7fffffffdf98, symbol_scope=0xfffffffff7ff5e68,
version=0x0, type_class=0, flags=2, skip_map=0x0) at dl-lookup.c:805
805 dl-lookup.c: No such file or directory.
Full stack trace
#0 0x00007ffff7de019b in _dl_lookup_symbol_x (undef_name=0x555555556818 "function_name",
undef_map=0xfffffffff7ff5ae0, ref=0x7fffffffdf98,
symbol_scope=0xfffffffff7ff5e68, version=0x0, type_class=0, flags=2, skip_map=0x0) at dl-
lookup.c:805
#1 0x00007ffff6704fe6 in do_sym (flags=<optimized out>, vers=0x0, who=0x555555555fcf
<bind+31>, name=0x555555556818 "function_name",
handle=0xfffffffff7ff5ae0) at dl-sym.c:151
#2 _dl_sym (handle=0xfffffffff7ff5ae0, name=0x555555556818 "function_name", who=0x555555555fcf
<bind+31>) at dl-sym.c:254
#3 0x00007ffff7bd20e4 in dlsym_doit (a=a@entry=0x7fffffffe1e0) at dlsym.c:50
#4 0x00007ffff670551f in __GI__dl_catch_exception
(exception=exception@entry=0x7fffffffe170, operate=0x7ffff7bd20d0 <dlsym_doit>,
args=0x7fffffffe1e0)
at dl-error-skeleton.c:196
#5 0x00007ffff67055af in __GI__dl_catch_error (objname=0x7ffff7dd40f0 <last_result+16>,
errstring=0x7ffff7dd40f8 <last_result+24>,
mallocedp=0x7ffff7dd40e8 <last_result+8>, operate=<optimized out>, args=<optimized out>) at
dl-error-skeleton.c:215
#6 0x00007ffff7bd2745 in _dlerror_run (operate=operate@entry=0x7ffff7bd20d0 <dlsym_doit>,
args=args@entry=0x7fffffffe1e0) at dlerror.c:162
#7 0x00007ffff7bd2166 in __dlsym (handle=<optimized out>, name=0x555555556818 "function_name") at
dlsym.c:70
#8 0x0000555555555fcf in bind ()
#9 0x000055555555621c in test ()
#10 0x0000555555556313 in main ()
I have tried searching but didn't able to find a solution. Am I missing here something or not calling dlmopen in proper manner, please help me out here. Any leads or suggestion will also be helpful.