mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
To: musl@lists.openwall.com
Subject: Re: [musl] building statically linked DSOs with musl
Date: Sat, 01 Jan 2022 08:58:32 -0500	[thread overview]
Message-ID: <1641045086.i0hohehzro.none@localhost> (raw)
In-Reply-To: <YdBPdmFLDFeMB/Ik@wirbelwind.zhasha.com>

Excerpts from Joakim Sindholt's message of January 1, 2022 7:56 am:
> clock_gettime(), which gettimeofday() uses internally now, wants to
> check if linux provides a user space fast path through the
> injected-into-every-process VDSO.
> When the dynamic linker, in this case glibc's ld.so, loads your binary
> it will do a bunch of internal setup in addition to symbol stitchup and
> whatever else needs to be done. Here you've run into the first of many
> brick walls. Musl will set up its own internal global libc structure
> with a bunch of values during the initial dynamic loading phase; among
> the members is libc.auxv, which is what __vdsosym will look through when
> trying to find the VDSO. Since you never ran musl's dynamic linker (and
> even if your host binary was musl-based, not the one that would have
> initialized the libc.auxv baked in to your statically linked DSO) it
> won't have set up this and a whole host of other things.
> 
> It's not just a question of "just run this setup code and it will work"
> either, as a lot of libc functionality by necessity depends on exclusive
> access and implementation details that can't cross the barrier you've
> set up.
> 
> Best I can figure your only solution, if you want to ship your own
> ecosystem, is to start another process and talk to it over a
> socket/pipe.
> I'm sure this wasn't a very helpful post. Maybe someone else on this
> list has a solution that better fits your needs.
> 
> Joakim
> 

Yes, this is fundamentally impossible. You could avoid much of this 
difficulty by attempting to statically link or otherwise forcibly bind 
your library's dependencies to your alternative malloc; however, this 
merely decreases the size of the issue rather than removing it. First, 
malloc implementations (may) use a process-global resource: (s)brk. It 
will cause havoc if multiple implementations attempt to simultaneously 
manipulate it. Second, even if no more than one implementation uses 
(s)brk, they will still have incompatible metadata. Consider the case 
where your plugin allocates some memory with malloc, then passes the 
pointer to Python which then frees it. Since an incompatible 
implementation is processing it, it will most likely destroy the heap or 
crash.

In conclusion, without extremely careful preparation of the entire 
program and all its DSOs, it is mandatory to use a single libc and 
malloc implementation in all DSOs.

Cheers,
Alex.

  reply	other threads:[~2022-01-01 13:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01  9:32 Sebastien Bourdeauducq
2022-01-01 12:56 ` Joakim Sindholt
2022-01-01 13:58   ` Alex Xu (Hello71) [this message]
2022-01-01 14:31     ` Sebastien Bourdeauducq
2022-01-02 21:41       ` Markus Wichmann
2022-01-03  1:37   ` Sebastien Bourdeauducq
2022-01-03  7:05     ` Markus Wichmann

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=1641045086.i0hohehzro.none@localhost \
    --to=alex_y_xu@yahoo.ca \
    --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).