我的一个应用程序因 SIGBUS 信号而崩溃。 以下是来自 gdb 的堆栈跟踪。基本上,dlopen 调用失败了。我正在运行 CentOS 6.3 64 位。
Program received signal SIGBUS, Bus error.
0x0000003cfc6175de in strcpy () from /lib64/ld-linux-x86-64.so.2
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.9.x86_64 libgcc-4.4.7-11.el6.x86_64 libstdc++-4.4.7-11.el6.x86_64
(gdb) bt
#0 0x0000003cfc6175de in strcpy () from /lib64/ld-linux-x86-64.so.2
#1 0x0000003cfc6090b2 in _dl_load_cache_lookup () from /lib64/ld-linux-x86-64.so.2
#2 0x0000003cfc608612 in _dl_map_object () from /lib64/ld-linux-x86-64.so.2
#3 0x0000003cfc612b05 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#4 0x0000003cfc60e266 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#5 0x0000003cfc6125aa in _dl_open () from /lib64/ld-linux-x86-64.so.2
#6 0x0000003cfca00f66 in dlopen_doit () from /lib64/libdl.so.2
#7 0x0000003cfc60e266 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#8 0x0000003cfca0129c in _dlerror_run () from /lib64/libdl.so.2
#9 0x0000003cfca00ee1 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2
#10 0x00000000004b4425 in my_open_dbus_func (f_name=0x558f2d "libdbus-glib-1.so.2")
我试着用这两行写了一个简单的程序,效果很好:
void * h = dlopen( "libdbus-glib-1.so.2", RTLD_LAZY );
dlclose( h );
我还尝试在 valgrind 下运行我原来的应用程序,它没有任何问题。
非常感谢任何帮助/指点。
最佳答案
尝试在dlopen
之后检查h
是否不为NULL。我可以假设 dlclose
可能会因作为参数给出的 NULL 指针而崩溃。
关于dlopen 崩溃(接收 SIGBUS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31544567/