Search code examples
clinuxdbusdlopen

Crash in dlopen ( receiving SIGBUS )


One of my applications is crashing because of SIGBUS signal. The following is the stack trace from the gdb. Basically, the dlopen call is failing. I am running CentOS 6.3 64 bit.

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")

I tried writing a simple program with these two lines which works just fine:

void * h = dlopen( "libdbus-glib-1.so.2", RTLD_LAZY );
dlclose( h );

I also tried running my original application under valgrind and it worked without any problem.

Any help/pointers are really appreciated.


Solution

  • It appears that one of the static library ( from third-party vedor ) was doing the shady memory management which somehow lead my dlopen call to crash. The code was written to delect the virtual environment. The problem could have been easily detected on valgrind but if application run under valgrind the third-party library would take a different code path ( considering that valgrind is physical machine )

    unfortunatly, I do not know what they fixed in their static library but it seems to work. I am writing this answer ( and accepting it ) to avoid further confusion.