From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2441 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: static linking and dlopen Date: Sun, 9 Dec 2012 10:11:08 -0500 Message-ID: <20121209151108.GB20323@brightrain.aerifal.cx> References: <20121208225237.GV20323@brightrain.aerifal.cx> <50C3CA75.8000504@comcast.net> <20121209063658.GA2925@openwall.com> <20121208232529.79bab53a.idunham@lavabit.com> <20121209100846.GB2925@openwall.com> <20121209114608.GG23126@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1355065891 17193 80.91.229.3 (9 Dec 2012 15:11:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2012 15:11:31 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2442-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 09 16:11:44 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ThiXZ-00026d-Kt for gllmg-musl@plane.gmane.org; Sun, 09 Dec 2012 16:11:37 +0100 Original-Received: (qmail 9395 invoked by uid 550); 9 Dec 2012 15:11:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9387 invoked from network); 9 Dec 2012 15:11:23 -0000 Content-Disposition: inline In-Reply-To: <20121209114608.GG23126@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2441 Archived-At: On Sun, Dec 09, 2012 at 12:46:08PM +0100, Szabolcs Nagy wrote: > * croco@openwall.com [2012-12-09 14:08:46 +0400]: > > packages for them all, or I opt for -static). So, I'd like to have all the > > libs inside the binary of, e.g., my interpreter (actually, this can be a > > program which does its job being controlled by embedded interpreter). But, > > at the same time, it is very possible I need these loadable modules, which > > dalias just described why static linking with dlopen is not possible To clarify, it's not possible right now, and difficult or impossible to do "right". There are various partly-working approaches though. > so you can use dlopen only if you can ensure you don't use > the same libraries as the dlopened code or all shared code > is pure (no writeable global state, no sideeffects), but if > you use dlopen you already depend on libc and if the dlopened > code also uses libc you have a problem The dynamic linker/libc already refuses to load itself, so in musl there's not really the danger of libc being loaded twice. The issue is that we would have to ensure that the whole libc gets linked into the main program so it's available to loaded modules -- and that the symbols are all kept so that they can be used. Both of these, while possible, are not entirely trivial to do. I'm not against consideration of support for this, but I would like to first explore the alternative design I suggested: initially linking as a dynamic-linked program, then using a special utility to combine all of the shared libraries into a single file. While this approach does have some disadvantages (PIC code, startup time cost, etc. much like dynamic linking), it has some of the advantages of static linking (not searching/loading multiple files all over the filesystem, single-file distribution, etc.) and an additional benefit is that, with support from the dynamic linker, even the .so files intended for loading with dlopen could be packed into the main file. Rich