From owner-freebsd-questions@FreeBSD.ORG Tue Dec 18 20:36:03 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 184BC16A417 for ; Tue, 18 Dec 2007 20:36:03 +0000 (UTC) (envelope-from markus.hoenicka@mhoenicka.de) Received: from rrzmta2.rz.uni-regensburg.de (rrzmta2.rz.uni-regensburg.de [194.94.155.53]) by mx1.freebsd.org (Postfix) with ESMTP id 940B813C447 for ; Tue, 18 Dec 2007 20:36:02 +0000 (UTC) (envelope-from markus.hoenicka@mhoenicka.de) Received: from rrzmta2.rz.uni-regensburg.de (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id B87C9B103 for ; Tue, 18 Dec 2007 21:36:07 +0100 (CET) Received: from yeti.mininet (rrzras1-7.rz.uni-regensburg.de [132.199.208.17]) by rrzmta2.rz.uni-regensburg.de (Postfix) with ESMTP id 942F955213 for ; Tue, 18 Dec 2007 21:35:51 +0100 (CET) X-Mailer: emacs 21.3.1 (via feedmail 8 I); VM 7.19 under Emacs 21.3.1 From: "Markus Hoenicka" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18280.11993.211065.843394@yeti.mininet> Date: Tue, 18 Dec 2007 21:34:33 +0100 To: freebsd-questions@freebsd.org Subject: threading and dlopen() X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2007 20:36:03 -0000 Hi, 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/libfbclient.so.2 #1 0x2852ceb4 in return_success () from /usr/local/lib/libfbclient.so.2 #2 0x28525179 in REM_attach_database () from /usr/local/lib/libfbclient.so.2 #3 0x2851386a in isc_attach_database () from /usr/local/lib/libfbclient.so.2 #4 0x284ece8e in _dbd_real_connect () from /usr/local/lib/dbd/libdbdfirebird.so #5 0x284eba19 in dbd_connect () from /usr/local/lib/dbd/libdbdfirebird.so #6 0x2808011d in dbi_conn_connect () from /usr/local/lib/libdbi.so.0 #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). regards, Markus [1] http://lists.freebsd.org/pipermail/freebsd-questions/2007-December/164571.html -- Markus Hoenicka markus.hoenicka@cats.de (Spam-protected email: replace the quadrupeds with "mhoenicka") http://www.mhoenicka.de