Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 2000 18:33:58 +0200 (CEST)
From:      Raymond Wiker <Raymond.Wiker@fast.no>
To:        freebsd-hackers@freebsd.org
Subject:   dlopen() and friends from a statically-linked binary?
Message-ID:  <14711.10742.914512.819982@raw.gren.fast.no>

next in thread | raw e-mail | index | archive | help
	[ Re-sent, as it seemed to get lost on my first try. ]

	Is it possible, at all, to use dlopen etc from a
statically-linked executable? My experiments with FreeBSD-4.0 (see
below) indicate that it's 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. On the other
hand, SBCL is severely handicapped if it cannot subsequently use
dlopen() to load foreign code into the running lisp system.


raw : ~ $ cat dltest.c
#include <dlfcn.h>
#include <stdio.h>

main()
{
  void *handle;
  void *sym;
  handle = dlopen(0, RTLD_LAZY);
  if (handle == 0)
    {
      fprintf(stderr, "dlopen returned 0: %s\n", dlerror());
    }
  else 
    {
      fprintf(stderr, "Handle: %p, main: %p\n", handle, dlsym(handle, "main"));
    }
  fprintf(stderr, "Handle: %p, main: %p\n", 0, dlsym(0, "main"));
  return 0;
}

raw : ~ $ gcc -static dltest.c -o dltest
raw : ~ $ ./dltest
dlopen returned 0: Service unavailable
Handle: 0x0, main: 0x0

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. ]

-- 
Raymond Wiker


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?14711.10742.914512.819982>