mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: John Hu <heat0415@gmail.com>
Subject: Re: A question about pure static linking with libdl
Date: Sat, 10 Jun 2017 15:54:38 -0400	[thread overview]
Message-ID: <20170610195438.GT1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <20170610163733.GU9350@port70.net>

On Sat, Jun 10, 2017 at 06:37:33PM +0200, Szabolcs Nagy wrote:
> * Jon Chesterfield <jonathanchesterfield@gmail.com> [2017-06-10 12:19:43 +0100]:
> > I think using dlopen in static binaries is an interesting (though niche)
> > use case. I'm subscribed to this list with a vague intention of
> > implementing it but haven't found the time.
> > 
> > The application of interest to me is a plugin architecture where the main
> > executable is static, mostly so it's easier to distribute, and the plugged
> > in components are independent of any libc. Essentially trying to use elf as
> > part of a jit loading mechanism.
> > 
> > No eta on this work though. Could be years :(
> 
> to do that the application must contain everything from libc
> that may be needed by the loaded plugins (since you dont want
> to load another libc when one is already static linked)
> 
> the easiest way is to just put all of libc into your application
> (or put your application into libc: e.g. put your application code
> into the musl repo and change the dynamic linker startup code to
> jump to your app, then the produced libc.so will do dynamic linking
> and then runs your app, dlopen works and it's a self-contained binary)
> 
> otoh this wont work well for loading jited code: if you generate
> lot of executable code, then you will need unload support too to
> get rid of the unused contents, in musl dlclose is a noop so the
> address space will keep filling up.

For the jit'd code usage case I think it makes more sense to just
write your own minimal ELF loader that's not tied into the global
symbol table and dynamic linking semantics. Then you can unload it
freely and don't have to worry about interaction with other things.
Perhaps someday I should write a poc for doing this. It should only
take a few hundred loc and should be essentially arch-independent just
like musl's relocation code (just needing arch-reloc-to-generic
mappings like musl uses).

Rich


  reply	other threads:[~2017-06-10 19:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16  7:40 John Hu
2017-05-16 10:30 ` Szabolcs Nagy
2017-05-17  4:28   ` John Hu
2017-06-10 11:19   ` Jon Chesterfield
2017-06-10 16:37     ` Szabolcs Nagy
2017-06-10 19:54       ` Rich Felker [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-05-16  6:46 John Hu

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=20170610195438.GT1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=heat0415@gmail.com \
    --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).