From owner-freebsd-current Tue Nov 5 8:53:51 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 87A9737B404 for ; Tue, 5 Nov 2002 08:53:48 -0800 (PST) Received: from k6.locore.ca (k6.locore.ca [198.96.117.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id C6FD843E88 for ; Tue, 5 Nov 2002 08:53:47 -0800 (PST) (envelope-from jake@k6.locore.ca) Received: from k6.locore.ca (jake@localhost.locore.ca [127.0.0.1]) by k6.locore.ca (8.12.5/8.12.5) with ESMTP id gA5H8Ybd058511; Tue, 5 Nov 2002 12:08:34 -0500 (EST) (envelope-from jake@k6.locore.ca) Received: (from jake@localhost) by k6.locore.ca (8.12.5/8.12.5/Submit) id gA5H8Yen058509; Tue, 5 Nov 2002 12:08:34 -0500 (EST) Date: Tue, 5 Nov 2002 12:08:33 -0500 From: Jake Burkholder To: Max Khon Cc: current@FreeBSD.ORG Subject: Re: libc size Message-ID: <20021105120833.V22677@locore.ca> References: <3DC17C7F.9020308@acm.org> <20021031140542.W86715-100000@volatile.chemikals.org> <20021031220633.3acd0b53.flynn@energyhq.homeip.net> <3DC1AB26.5020708@acm.org> <20021103155858.3be6eda9.flynn@energyhq.homeip.net> <3DC6CB56.8090809@acm.org> <20021104215734.GA47193@dragon.nuxi.com> <20021105125454.A51180@iclub.nsu.ru> <20021105021823.T22677@locore.ca> <20021105132142.A52607@iclub.nsu.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20021105132142.A52607@iclub.nsu.ru>; from fjoe@iclub.nsu.ru on Tue, Nov 05, 2002 at 01:21:42PM +0600 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Apparently, On Tue, Nov 05, 2002 at 01:21:42PM +0600, Max Khon said words to the effect of; > hi, there! > > On Tue, Nov 05, 2002 at 02:18:23AM -0500, Jake Burkholder wrote: > > > > > Before someone says you can dlopen() from static binaries in order to > > > > implement nsswitch, please provide the patch proving it. Our best > > > > FreeBSD minds don't think it can be done properly and sanely. > > > > > > I have the patch. Currently it is made against RELENG_4 and I have a couple > > > of questions about alpha (however it works on alpha too with a few hacks). > > > Unfortunately, jdp does not have enough time to review it and I have > > > lack of time to port it to -current (that would not be that hard but > > > since sparc64 is now Tier-1 platform the patch should be ported to > > > sparc64 too but I do not have sparc64 hardware and access to > > > panther is very slow from my home). > > > > > > What is the right place to post the patch and test program > > > demonstrating dlopen for statically linked programs? > > > > Put it up somehere on the web or email it to the list. I'd > > be interested in looking at it. > > Ok, I put the patch and test program to > http://people.freebsd.org/~fjoe/libdl.tar.bz2. > > Patches are made against RELENG_4 (and all tests were done on RELENG_4) > but it will not be that hard to port everything to -CURRENT. > This is just a proof-of-concept work-in-progress. > > The plan is to add this stuff (rtld sources with -DLIBDL) to libc.a > so statically linked programe will have dlopen/dlsym etc. > > Problems with current patches are: > - I do not know what to do on alpha with _GOT_END_ and > _GLOBAL_OFFSET_TABLE_ symbols. I had to use ld.so.script > to solve missing _GOT_END_ problem and ifdef out _GLOBAL_OFFSET_TABLE_ > usage from alpha/reloc.c for second problem. An advice from alpha rtld > guru will be very useful > - gdb support for shared objects dlopened from statically linked > program is broken > - rtld_exit() is not called on exit so fini functions are not > called on exit > - probably more stuff could be #ifdef'ed out from rtld when it is compiled > with -DLIBDL > - xmalloc and friends names in rtld sources probably should be prepended > with an underscore to prevent name clashes (if this stuff will be included > in libc.a) > > Any comments, suggestions, patches will be very appreciated. I think there are more problems than you realize. They are very hard to fix. You've basically hacked rtld to bits. All the ifdefs make it hard to read and maintain. This statically links rtld into any static binary that wants to use dlopen. What was that about saving space on the root partition? -rwxr-xr-x 1 jake wheel 143177 Nov 5 11:57 hello This is more than twice as big as a normal static binary which just calls printf on my system. ~90K bloat just for dlopen. I don't see that you've dealt with getting the linker to generate the tables that rtld needs; an _DYNAMIC section, a dynsym table, a dynstr table etc. These are needed in order to look up symbols in the statically linked binary itself. Getting the linker to do this is not overly difficult, we do it for the kernel, but it bloats the static binaries more. It also creates a special case in the makefiles, unless we do this for all static binaries, which would cause a lot of bloat. As a result of the above, how do you deal with multiple implementations of library services being present? For example a statically linked binary calls malloc, so it has a copy of malloc linked into it. It tries to dlopen a library which also calls malloc. Which copy of malloc does the library use? How does it locate the malloc that's linked into the static binary without the dynamic tables? What happens when the application tries to free a pointer allocated by the library, or vice versa? When David said we didn't think it could be done properly or sanely, we meant it. It must work exactly like it would in a dynamic binary. Jake To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message