Date: Tue, 09 Jan 1996 13:12:18 -0800 From: John Polstra <jdp@polstra.com> To: "Jordan K. Hubbard" <jkh@time.cdrom.com> Cc: dfr@render.com, freebsd-hackers@freebsd.org Subject: Re: Anyone got GNU `dld' ported to FreeBSD? Message-ID: <199601092112.NAA14462@austin.polstra.com> In-Reply-To: Your message of "Tue, 09 Jan 1996 12:31:02 PST." <1480.821219462@time.cdrom.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601092112.NAA14462>