From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2448 Path: news.gmane.org!not-for-mail From: Rob Landley Newsgroups: gmane.linux.lib.musl.general Subject: Re: static linking and dlopen Date: Sun, 09 Dec 2012 14:43:31 -0600 Message-ID: <1355085811.9353.4@driftwood> References: <20121209100846.GB2925@openwall.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1355085826 14193 80.91.229.3 (9 Dec 2012 20:43:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2012 20:43:46 +0000 (UTC) Cc: musl@lists.openwall.com To: musl@lists.openwall.com Original-X-From: musl-return-2449-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 09 21:44:00 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 1ThnjD-0000JV-0V for gllmg-musl@plane.gmane.org; Sun, 09 Dec 2012 21:43:59 +0100 Original-Received: (qmail 32502 invoked by uid 550); 9 Dec 2012 20:43:46 -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 32494 invoked from network); 9 Dec 2012 20:43:46 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:subject:to:cc:in-reply-to:x-mailer:message-id :mime-version:content-type:content-disposition :content-transfer-encoding:x-gm-message-state; bh=Ipebd0fuxp+dy5mIs/63pKapwe/8mbBVnZt+xXtEE5o=; b=Dq4fqZwXivisPmFxCLSlL9nsT2qXS5V6Hk6gc/O0rjERqbVtuMycRigQzrmpl9q0Ji SFqfN+Nu6+gnFU2F8ArZ/k+v9MRDFiT3JGgeEdM6rWhgUCaWxaU9zv8uUL2dh06iq9Fd fGG4CvPtMhwxUnX5KF8AebvXiKBYy9GoMmPljZJPW7KOgYSLFO3KaMlPj5g3p/40Z5JZ JVTHFqZH5jOj24DOA+ktjmwJmM6DDypa07swONznE2f6ugZM+RAThi8A7DWgBXyER28+ V3BWkig88A+t0ZqVQ3pzJf3OcjhzCQANGEk8PvZhC2wuEezR/OG0/sVg7G2QD12ihWfK kz8w== In-Reply-To: <20121209100846.GB2925@openwall.com> (from croco@openwall.com on Sun Dec 9 04:08:46 2012) X-Mailer: Balsa 2.4.11 Content-Disposition: inline X-Gm-Message-State: ALoCoQmjLHpILdNFA7Qaxr6IuZHAb+NtxrjJ56M1ESZN/Wts5wfzZLSrhkPazw5o/P1aZyy5K/+a Xref: news.gmane.org gmane.linux.lib.musl.general:2448 Archived-At: On 12/09/2012 04:08:46 AM, croco@openwall.com wrote: > On Sat, Dec 08, 2012 at 11:25:29PM -0800, Isaac Dunham wrote: > > I think there's a misunderstanding here: > > > > musl includes a dlopen function. > > When a binary is statically linked, it is a stub. > > When a binary is dynamically linked, it loads the shared library =20 > requested. >=20 > Oh, well, I didn't catch the situation; if this is the case, the =20 > things are > definitely better. However, to my mind, static linkage is good for > creating portable binaries (besides all the other advantages), And musl has good support for static linking. Musl has good support for =20 dynamic linking. Mixing the two is a bad idea at the design level, =20 which posix does not guarantee to work. > and I can > easily imagine a situation in which I dislike the idea of a > dynamically-linked main binary (e.g. I ship some unusual software to > endusers, and they have different Linux distros but are not going to =20 > build > the soft from sources - yes, there are such Linux users who panic =20 > when they > hear the word "compiler" - and I've got no hope someone else will =20 > package > my soft for different distros, because it is too unusual, so either I =20 > spend > my time installing 20+ different versions of various distros and =20 > prepare > packages for them all, or I opt for -static). Yay static linking. > So, I'd like to have all the > libs inside the binary of, e.g., my interpreter (actually, this can =20 > be a > program which does its job being controlled by embedded =20 > interpreter). But, > at the same time, it is very possible I need these loadable modules, =20 > which > extend the functionality of the interpreter. If you need dynamic linking, then you need dynamic linking. > Surely it is not a > catastrophe, as I can link all libs but musl statically, and provide > libmusl.so along with the binary, also having a script which sets > LD_LIBRARY_PATH and then runs the binary; but it is a bit, errr... > /strange/ :) You want a statically, dynamically linked program. Presumably combining =20 PIC and non-PIC code. Good luck. > Actually, when it comes to -static, the linker only picks the modules =20 > that > contain unresolved symbols, so it should (am I right?) be easy to =20 > break the > things down to modules so that all the dynamic linkage mechanics is =20 > linked > into the binary only in case it calls dlopen. And, okay, to mention =20 > in the > man 3 dlopen that using it from within a statically-linked binary will > increase the size of the binary by another megabyte, and that the .so =20 > to be > loaded must itself use statically-linked version of libraries so that =20 > some > functions will be loaded to the code segment twice. Such practice =20 > should > be discouraged but I don't think it should be made impossible at all. >=20 > I realize, however, that it is possible I simply miss something. You're confusing "possible" with "a good idea". Many truly horrible =20 ideas aren't actually impossible, as Windows extensively demonstrates. Possibly what you want is large chunks of the musl dynamic loader =20 factored out so you can easily suck them into your program and keep the =20 pieces when it breaks. Rob=