Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 9 Dec 2012 10:11:08 -0500
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: static linking and dlopen

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

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.