From owner-freebsd-stable Fri Jul 21 22:34:30 2000 Delivered-To: freebsd-stable@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id 0E10D37B576 for ; Fri, 21 Jul 2000 22:34:13 -0700 (PDT) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.3/8.9.3) with ESMTP id WAA24185; Fri, 21 Jul 2000 22:34:11 -0700 (PDT) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.3/8.9.1) id WAA47605; Fri, 21 Jul 2000 22:34:10 -0700 (PDT) (envelope-from jdp@polstra.com) Date: Fri, 21 Jul 2000 22:34:10 -0700 (PDT) Message-Id: <200007220534.WAA47605@vashon.polstra.com> To: Raymond.Wiker@fast.no Subject: Re: dlopen() and friends from a statically-linked binary? In-Reply-To: <14711.10742.914512.819982@raw.gren.fast.no> References: <14711.10742.914512.819982@raw.gren.fast.no> Organization: Polstra & Co., Seattle, WA Cc: stable@freebsd.org Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <14711.10742.914512.819982@raw.gren.fast.no>, Raymond Wiker wrote: > > Is it possible, at all, to use dlopen etc from a > statically-linked executable? No, it is not possible. > The reason that I'd like this to work is that SBCL (a Common > Lisp implementation, see http://sbcl.sourceforge.net) needs the > addresses of certain library symbols (e.g, errno) when building the > initial lisp image. This seems to require static linking. I am not quite sure what you mean here. But something like static int *p = &errno; works just as well in a dynamically linked program as it does in a statically linked one. BTW, errno is a bad example. Its address is not necessarily a compile-time constant at all. In multithreaded programs on many systems (including FreeBSD) errno is a #define like this: int * __error __P((void)); #define errno (* __error()) This is specifically permitted by the ANSI/ISO C standard. > raw : ~ $ gcc dltest.c -o dltest > raw : ~ $ ./dltest > Handle: 0x2805e000, main: 0x0 > Handle: 0x0, main: 0x0 > > [ Note: this seems wrong; according to the manpage for dlsym, the > second call should give the same output as the first. ] In order to be able to reference symbols in the main program with dlsym, you must link the program using "-Wl,-E" on the cc command line. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Disappointment is a good sign of basic intelligence." -- Chögyam Trungpa To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message