From owner-freebsd-hackers Tue Jan 9 13:14:54 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id NAA07372 for hackers-outgoing; Tue, 9 Jan 1996 13:14:54 -0800 (PST) Received: from austin.polstra.com (austin.polstra.com [206.213.73.10]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id NAA07366 for ; Tue, 9 Jan 1996 13:14:45 -0800 (PST) Received: from austin.polstra.com (jdp@localhost) by austin.polstra.com (8.6.12/8.6.12) with ESMTP id NAA14462; Tue, 9 Jan 1996 13:12:18 -0800 Message-Id: <199601092112.NAA14462@austin.polstra.com> To: "Jordan K. Hubbard" cc: dfr@render.com, freebsd-hackers@freebsd.org Subject: Re: Anyone got GNU `dld' ported to FreeBSD? In-reply-to: Your message of "Tue, 09 Jan 1996 12:31:02 PST." <1480.821219462@time.cdrom.com> Date: Tue, 09 Jan 1996 13:12:18 -0800 From: John Polstra Sender: owner-hackers@freebsd.org Precedence: bulk Jordan wrote: > Well, do you have any suggestions for building a dynamic linked > binary with *no* dependencies? There isn't room on the boot floppy > for a binary and its shared library ... > > I've tried to link dynamic bins with libc non-shared and it just > doesn't seem to work! :( I can tell you how to do _almost_ what you want, and I bet it's close enough. Is your kludge-tolerance control set fairly high? Apparently, if you don't use any shared libraries, "ld" won't make your executable dynamically-linked. You can get around this if you're willing to have your executable "depend" on a tiny do-nothing shared library. First create a file "tiny.c" that contains this: void a_real_kludge() { } Now make a shared library "libtiny.so.1.0" out of it: cc -fpic -c tiny.c ld -Bshareable -o libtiny.so.1.0 tiny.o strip libtiny.so.1.0 You'll have to put this library on the installation disk, but it's pretty small: -rwxr-xr-x 1 jdp jdp 8192 Jan 9 12:53 libtiny.so.1.0 Now build your executable like this: cc hello.c libtiny.so.1.0 -Xlinker -Bstatic strip a.out That will give you what you need. "ldd a.out" says: a.out: libtiny.so.1.0 => libtiny.so.1.0 (0x8025000) And "file a.out" says: a.out: FreeBSD/i386 demand paged dynamically linked executable And it even runs: Hello, world! You should be able to use dlopen and friends from this executable. Be sure, when you build the shared libraries that you want to load later with dlopen, that you specify all needed libraries on the "ld" command line. I.e.: ld -Bshareable -o libbig.so.1.0 big1.o big2.o ... -lc That will ensure that needed libraries (such as libc.so.x.x in this example) will get loaded too, at dlopen time. -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Self-knowledge is always bad news." -- John Barth