Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jul 2000 22:34:10 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        Raymond.Wiker@fast.no
Cc:        stable@freebsd.org
Subject:   Re: dlopen() and friends from a statically-linked binary?
Message-ID:  <200007220534.WAA47605@vashon.polstra.com>
In-Reply-To: <14711.10742.914512.819982@raw.gren.fast.no>
References:  <14711.10742.914512.819982@raw.gren.fast.no>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <14711.10742.914512.819982@raw.gren.fast.no>,
Raymond Wiker  <Raymond.Wiker@fast.no> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007220534.WAA47605>