threading and dlopen()

Markus Hoenicka markus.hoenicka at
Tue Dec 18 12:36:03 PST 2007


please bear with me if the issue below sounds familiar[1]. I've done some
more experiments to find out why the firebird client library crashes
on my box. If you're familiar with threads and dynamic linking, please
read on.

I'm trying to fix the libdbi driver for the firebird database engine
on FreeBSD. libdbi is a C library that your application can link
to. libdbi dlopen()s drivers which are shared objects themselves and
provide the specific code to talk to the database client
libraries. libdbi works across several platforms and supports a
variety of database engines - with the notable exception of firebird
on FreeBSD.

I can create and access firebird databases using the isql command line
tool. I can build and run a simple test program which creates a
firebird database, opens it, and closes it again. Now, if I use pretty
much the same code, compile it into a shared object, and dlopen() it,
the firebird client library invariably crashes with the following
gdb output:

#0  0x28535b36 in ThreadData::restoreSpecific() from /usr/local/lib/
#1  0x2852ceb4 in return_success () from /usr/local/lib/
#2  0x28525179 in REM_attach_database () from /usr/local/lib/
#3  0x2851386a in isc_attach_database () from /usr/local/lib/
#4  0x284ece8e in _dbd_real_connect ()
   from /usr/local/lib/dbd/
#5  0x284eba19 in dbd_connect () from /usr/local/lib/dbd/
#6  0x2808011d in dbi_conn_connect () from /usr/local/lib/
#7  0x0804982a in main (argc=1, argv=0xbfbfea2c) at test_dbi.c:91

My (limited) analysis makes me think this is some sort of a threading
issue aggravated by the fact that the code is dlopen()ed (remember the
same code works ok if compiled into a standalone app). BTW the
firebird client library is the only library supported by libdbi which
uses threads. All other drivers do not use threads and work ok.

The firebird driver works ok on a variety of other platforms,
including Linux and as weird ones as Windows. It somehow hurts my
pride that it fails on FreeBSD.

Does anyone out there have an idea how to fix this odd problem?

System is 6.1-RELEASE, firebird2-client 2.0.3_1 was built as a port,
libdbi and libdbi-drivers (both current cvs versions) were built from
the sources (not as ports).



Markus Hoenicka
markus.hoenicka at
(Spam-protected email: replace the quadrupeds with "mhoenicka")

More information about the freebsd-questions mailing list