From owner-freebsd-questions@FreeBSD.ORG Thu Nov 13 08:00:24 2008 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 58D2F106568D for ; Thu, 13 Nov 2008 08:00:24 +0000 (UTC) (envelope-from markus.hoenicka@mhoenicka.de) Received: from webmailfront01.ispgateway.de (webmailfront01.ispgateway.de [80.67.16.111]) by mx1.freebsd.org (Postfix) with ESMTP id DC5F58FC13 for ; Thu, 13 Nov 2008 08:00:23 +0000 (UTC) (envelope-from markus.hoenicka@mhoenicka.de) Received: from webmailfront01.ispgateway.de (localhost [127.0.0.1]) by webmailfront01.ispgateway.de (8.14.0/8.14.0) with ESMTP id mAD80LRl011257; Thu, 13 Nov 2008 09:00:21 +0100 Received: (from nobody@localhost) by webmailfront01.ispgateway.de (8.14.0/8.14.0/Submit) id mAD80LxF011254; Thu, 13 Nov 2008 09:00:21 +0100 Received: from pc51997.klinik.uni-regensburg.de (pc51997.klinik.uni-regensburg.de [132.199.174.149]) by webmail.df.eu (Horde MIME library) with HTTP; Thu, 13 Nov 2008 09:00:21 +0100 Message-ID: <20081113090021.less3h5iwwsgwsg4@webmail.df.eu> Date: Thu, 13 Nov 2008 09:00:21 +0100 From: Markus Hoenicka To: Jeremy Chadwick References: <18715.28127.306511.577084@yeti.mininet> <20081113042912.GA10018@icarus.home.lan> In-Reply-To: <20081113042912.GA10018@icarus.home.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: domainFACTORY X-Originating-IP: 132.199.174.149 X-Df-WSender: 472582 Cc: freebsd-questions@FreeBSD.org Subject: Re: dlsym can't use handle returned by 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: Thu, 13 Nov 2008 08:00:24 -0000 Quoting Jeremy Chadwick : > I know that the .so's you're loading with dlopen() need to be built a > specific way/with certain arguments, otherwise they won't work (I > believe what I saw was dlsym() returning NULL). My symbol names were > getting stomped on, and there was a compiler flag that addressed that. > Is that a BSD-specific problem? As mentioned previously, I don't run =20 into trouble on other platforms. Is there any documentation available =20 which tells me how to build a dlopen()'able object in a portable way? >> function_pointer =3D dlsym(RTLD_DEFAULT, "function_name"); >> >> Why is that? Or rather: what am I doing wrong? > > This code right here is *completely* wrong. RTLD_DEFAULT is a mode bit > for dlopen(). I'm willing to bet a strict set of warnings would Citing the FreeBSD dlsym(3) man page: "If dlsym is called with the special handle RTLD_DEFAULT, the =20 search for the symbol follows the algorithm used for resolving =20 undefined symbols when objects are loaded." You probably had RTLD_LAZY and RTLD_NOW in mind which are dlopen() =20 flags. BTW RTLD_NEXT works just as well instead of RTLD_DEFAULT. regards, Markus --=20 Markus Hoenicka markus.hoenicka@cats.de (Spam-protected email: replace the quadrupeds with "mhoenicka") http://www.mhoenicka.de