mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: static linking and dlopen
Date: Sun, 9 Dec 2012 10:11:08 -0500	[thread overview]
Message-ID: <20121209151108.GB20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <20121209114608.GG23126@port70.net>

On Sun, Dec 09, 2012 at 12:46:08PM +0100, Szabolcs Nagy wrote:
> * croco@openwall.com <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


  reply	other threads:[~2012-12-09 15:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-08 18:09 Paul Schutte
2012-12-08 20:47 ` Szabolcs Nagy
2012-12-09 20:02   ` Rob Landley
2012-12-08 22:52 ` Rich Felker
2012-12-08 23:17   ` Charlie Kester
2012-12-08 23:23     ` Rich Felker
2012-12-09  0:04       ` Paul Schutte
2012-12-09  0:16         ` Rich Felker
2012-12-09 15:24           ` Paul Schutte
2012-12-09 17:54             ` Rich Felker
2012-12-09 19:07               ` Szabolcs Nagy
2012-12-09 19:24                 ` Rich Felker
2012-12-09  2:39         ` Szabolcs Nagy
2012-12-09  6:36     ` croco
2012-12-09  7:25       ` Isaac Dunham
2012-12-09  8:10         ` Charlie Kester
2012-12-09 10:08         ` croco
2012-12-09 11:46           ` Szabolcs Nagy
2012-12-09 15:11             ` Rich Felker [this message]
2012-12-09 20:43           ` Rob Landley
2012-12-08 23:29   ` Paul Schutte
2012-12-09  2:55   ` Szabolcs Nagy
2012-12-09  3:10     ` Rich Felker
2012-12-09  7:30     ` Isaac Dunham
2012-12-09 20:09   ` Rob Landley
2012-12-09 21:53     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121209151108.GB20323@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).