c - Segmentation fault when calling dlopen from Lua -



c - Segmentation fault when calling dlopen from Lua -

i have library opens library calling dlopen, crashes seg fault. involvement comment doesn't happen time, when it's called lua scheme i'm maintaining, if phone call lua interpreter, works no error.

lua call:

cmdtmpfile = "/home/msv/ericaflr/teste_slurm/echoandsleepjob.sh" local slurmlibopen = assert(package.loadlib("/home/msv/ericaflr/sga-slurm/drmaaloader.so", "luaopen_drmaaloader")) slurmlibopen() -- open library submitjob(cmdtmpfile) --function drmaa.so

drmaaloader.so source code:

#include <lua.h> #include <lauxlib.h> #include <lualib.h> #include <stdio.h> #include <dlfcn.h> typedef void register(lua_state*); int luaopen_drmaaloader(lua_state *l){ fprintf(stderr, "in loader c\n"); void* lib; lib = dlopen("/home/msv/ericaflr/sga-slurm/drmaa.so", rtld_now | rtld_global | rtld_deepbind); if(!lib){ printf("%s\n", dlerror()); homecoming 1; } fprintf(stderr, "loaded library\n"); register* loadfunc = (register*)dlsym(lib, "luaopen_drmaa"); if(!loadfunc){ printf("%s\n", dlerror()); homecoming 1; } fprintf(stderr, "got load funtion\n"); loadfunc(l); fprintf(stderr, "loaded library\n"); homecoming 0; }

drmaaloader.so compilation:

gcc -g drmaa_lib_loader.c -shared -fpic -i /usr/include/lua5.1 -i /usr/local/include -l /usr/local/lib -llua5.1 -ldl -o drmaaloader.so

here valgrind output:

==28683== syscall param set_robust_list(head) points uninitialised byte(s) ==28683== @ 0x65ddbbc: __pthread_initialize_minimal (nptl-init.c:346) ==28683== 0x65dc538: ??? (in /lib/x86_64-linux-gnu/libpthread-2.19.so) ==28683== address 0x4000bb0 not stack'd, malloc'd or (recently) free'd ==28683== ==28683== jump invalid address stated on next line ==28683== @ 0x0: ??? ==28683== 0x65dddd7: __pthread_initialize_minimal (nptl-init.c:433) ==28683== 0x65dc538: ??? (in /lib/x86_64-linux-gnu/libpthread-2.19.so) ==28683== address 0x0 not stack'd, malloc'd or (recently) free'd ==28683== ==28683== ==28683== process terminating default action of signal 11 (sigsegv) ==28683== bad permissions mapped part @ address 0x0 ==28683== @ 0x0: ??? ==28683== 0x65dddd7: __pthread_initialize_minimal (nptl-init.c:433) ==28683== 0x65dc538: ??? (in /lib/x86_64-linux-gnu/libpthread-2.19.so) ==28683== ==28683== heap summary: ==28683== in utilize @ exit: 0 bytes in 0 blocks ==28683== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==28683== ==28683== heap blocks freed -- no leaks possible ==28683== ==28683== counts of detected , suppressed errors, rerun with: -v ==28683== utilize --track-origins=yes see uninitialised values come ==28683== error summary: 40067 errors 136 contexts (suppressed: 0 0) segmentation fault (core dumped)

gdb output:

warning: couldn't activate thread debugging using libthread_db: cannot find new threads: generic error warning: file "/lib/x86_64-linux-gnu/libthread_db-1.0.so" auto-loading has been declined `auto-load safe-path' set "$debugdir:$datadir/auto-load". enable execution of file add together add-auto-load-safe-path /lib/x86_64-linux-gnu/libthread_db-1.0.so line configuration file "/home/msv/ericaflr/.gdbinit". disable security protection add together set auto-load safe-path / line configuration file "/home/msv/ericaflr/.gdbinit". more info security protection see "auto-loading safe path" section in gdb manual. e.g., run shell: info "(gdb)auto-loading safe path" warning: unable find libthread_db matching inferior's thread library, thread debugging not available. programme received signal sigsegv, segmentation fault. 0x0000000000000000 in ?? () (gdb) #1 0x00007ffff600edd8 in __pthread_initialize_minimal_internal () @ nptl-init.c:433 433 nptl-init.c: no such file or directory. (gdb) #2 0x00007ffff600d539 in _init () @ ../sysdeps/x86_64/crti.s:72 72 ../sysdeps/x86_64/crti.s: no such file or directory. (gdb) #3 0x0000000000000070 in ?? () (gdb) #4 0x000000000051d3ab in call_init.part () (gdb) #5 0x000000000051d599 in _dl_init () (gdb) #6 0x00000000004e95ca in dl_open_worker () (gdb) #7 0x00000000004e76c6 in _dl_catch_error () (gdb) #8 0x00000000004e8e0e in _dl_open () (gdb) #9 0x00000000004990ec in dlopen_doit () (gdb) #10 0x00000000004e76c6 in _dl_catch_error () (gdb) #11 0x0000000000499573 in _dlerror_run () (gdb) #12 0x000000000049913e in __dlopen () (gdb) #13 0x00007ffff6eb00da in __dlopen (file=<optimized out>, mode=<optimized out>) @ dlopen.c:78 78 dlopen.c: no such file or directory. (gdb) #14 0x00007ffff70b3895 in luaopen_drmaaloader (l=0xb972d0) @ drmaa_lib_loader.c:13 13 lib = dlopen("/home/msv/ericaflr/sga-slurm/drmaa.so", rtld_now | rtld_global | rtld_deepbind);

i wonder if execution of dlopen may vary according environment variables. has experienced before or know might problem?

thanks in advance

--edit

creating drmaaloader.so solves linking problem because drmaa.so uses 2 libraries reference each other. adding phone call ldopen open these libraries in luaopen_drmaa works if loadlib called lua interpreter, doesn't work if it's called lua scheme mentioned above, gives seg fault, different trace:

program received signal sigsegv, segmentation fault. 0x0000000000000000 in ?? () (gdb) #1 0x00007ffff6210dd8 in __pthread_initialize_minimal_internal () @ nptl-init.c:433 433 nptl-init.c: no such file or directory. (gdb) #2 0x00007ffff620f539 in _init () @ ../sysdeps/x86_64/crti.s:72 72 ../sysdeps/x86_64/crti.s: no such file or directory. (gdb) #3 0x0000000000000003 in ?? () (gdb) #4 0x000000000051d3ab in call_init.part () (gdb) #5 0x000000000051d599 in _dl_init () (gdb) #6 0x00000000004e95ca in dl_open_worker () (gdb) #7 0x00000000004e76c6 in _dl_catch_error () (gdb) #8 0x00000000004e8e0e in _dl_open () (gdb) #9 0x00000000004990ec in dlopen_doit () (gdb) #10 0x00000000004e76c6 in _dl_catch_error () (gdb) #11 0x0000000000499573 in _dlerror_run () (gdb) #12 0x000000000049913e in __dlopen () (gdb) #13 0x000000000041fe0d in ll_loadfunc () (gdb) #14 0x00000000004200d5 in ll_loadlib () (gdb) #15 0x000000000040c2d4 in luad_precall () (gdb) #16 0x0000000000415758 in luav_execute () (gdb) #17 0x000000000040b97a in luad_rawrunprotected () (gdb) #18 0x000000000040c79a in lua_resume () (gdb) #19 0x00000000004189ca in auxresume () (gdb) #20 0x0000000000418bf1 in luab_coresume () (gdb) #21 0x000000000040c2d4 in luad_precall () (gdb) #22 0x0000000000415758 in luav_execute () (gdb) #23 0x000000000040b97a in luad_rawrunprotected () (gdb) #24 0x000000000040c79a in lua_resume () (gdb) #25 0x00000000004189ca in auxresume () (gdb) #26 0x0000000000418bf1 in luab_coresume () (gdb) #27 0x000000000040c2d4 in luad_precall () (gdb) #28 0x0000000000415758 in luav_execute () (gdb) #29 0x000000000040c6fd in luad_call () (gdb) #30 0x000000000040b97a in luad_rawrunprotected () (gdb) #31 0x000000000040c8af in luad_pcall () (gdb) #32 0x0000000000409ef1 in lua_pcall () (gdb) #33 0x00000000004015f3 in _dofile(lua_state*, char*) () (gdb) #34 0x000000000040159e in main ()

c lua segmentation-fault valgrind dlopen

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -