mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Harmen Stoppels <me@harmenstoppels.nl>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Cannot dlopen() an already loaded shared library by its SONAME name
Date: Tue, 11 Jan 2022 17:22:06 -0500	[thread overview]
Message-ID: <20220111222206.GW7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <D8YsUB86oW8DejmzNJUGU-fcHh7ogVUXNvhGD7HB-ayqu2jdEPf_HbaiqNkRaiVbWNpYXMXHCiiqUFXd4cS2J2foq4xvd-jyrOTtGUHpXDY=@harmenstoppels.nl>

On Tue, Jan 11, 2022 at 09:30:10PM +0000, Harmen Stoppels wrote:
> > Given that this question already surfaced twice and was denied just as
> > 
> 
> > often, I'm guessing no.
> 
> The fact that this is a common request could also imply it's behavior
> people expect. So far I've seen:
> 
> 1. Julia [1] splits binary dependencies into separate packages, so when
>    liba.so depends on libb.so, they live in a different dir, where
>    the absolute and relative paths are only known when the julia
>    interpreter has started, so neither rpaths or LD_LIBRARY_PATH can
>    be used.
> 
>    So they dlopen libb.so, and then dlopen liba.so in that
>    order, and then assume liba.so does not have to locate libb.so
>    again, because its soname is already seens before.
> 
>    The proposed workaround was: don't list libb.so in the
>    DT_NEEDED of liba.so (that is, if you're already doing the work of
>    the linker, you might as well not use the linker at all for locating
>    libs). However, being able to run executables shipped with julia
>    packages would still be nice (e.g. a subprocess with LD_LIBRARY_PATH
>    set properly)
> 2. The Nix / Guix / Spack people are trying to reduce startup time of
>    executables with many shared libraries (as well as fixing library
>    paths once and for all to keep executables run deterministically).
>    In Guix there's a blog post where they call this the "stat storm" [2],
>    and they solve it in a glibc patch: using context dependent ld.so.cache,
>    that is, a reverse mapping soname => library path.
>    In Nix the proposal to fix the "stat storm" is to replace DT_NEEDED
>    in executables with absolute paths of all required libs (also
>    transient ones). This works fine, except on musl, where a dlopen by
>    soname will still do a search.

This could be solved much better by making an application-specific
directory full of symlinks to the libraries it uses and putting that
directory as the first thing in the program binary's rpath.

> 3. Wine is reported to rely on this earlier in the mailing list, but that
>    did not get any responses [3]. It reports the behavior is the same on
>    glibc, FreeBSD, NetBSD, and OpenBSD dynamic loaders; and musl is the
>    exception. 

There is some argument to be made for honoring SONAME as an action to
put the name into a dictonary for future dlopen to use, but having
this happen on libraries without any SONAME is really an anti-feature.
The point of dlopen with an explicit pathname is to load an explicit
file outside of the system library ecosystem, not to subvert the order
of path search for loading other libraries.

Rich

  reply	other threads:[~2022-01-11 22:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 11:50 Ilia K
2022-01-11 17:55 ` Markus Wichmann
2022-01-11 21:30   ` Harmen Stoppels
2022-01-11 22:22     ` Rich Felker [this message]
2022-01-12 14:52       ` Harmen Stoppels
2022-01-12 16:58         ` Farid Zakaria

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=20220111222206.GW7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=me@harmenstoppels.nl \
    --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).