mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [musl] Shared library loading
Date: Thu, 21 May 2020 17:21:21 +0200	[thread overview]
Message-ID: <20200521152121.GA6521@voyager> (raw)
In-Reply-To: <f8fc13a9-7af4-193f-9554-41f7fda36c85@bell-sw.com>

On Thu, May 21, 2020 at 02:27:24PM +0300, Alexander Scherbatiy wrote:
> Hello,
>
> I use Alpine Linux 3.11.6 with musl libc (x86_64) version 1.1.24.
>
> I have two shared libraries "a" and "b" each of which is placed in its own
> directory and lib "b" depends on "a".
> First, I use dlopen to load lib "a" with "RTLD_NOW | RTLD_GLOBAL" flags.
> Second, I load lib "b" with  flag "RTLD_LAZY".
>
> The "b" library loading works on my Ubuntu 19.10 and fails on Alpine 3.11.6
> with message:
>   dlopen failed: Error loading shared library liba.so: No such file or
> directory (needed by /root/load-lib-sample/bin/b/libb.so)
> Should it work on Alpine with musl libc as well?

[...]

I shall leave the "Should it work" to others who know more about this
than me. But I will tackle the "Why doesn't it work". It appears however
the behavior is intentional (whether the consequences are as well
remains to be seen). Namely in line 1140f. of dynlink.c (revision
72658c65):


|/* Add a shortname only if name arg was not an explicit pathname. */
|if (pathname != name) p->shortname = strrchr(p->name, '/')+1;

This means, in your case, the DSO handle for liba does not get a short
name, so when libb is loaded, it is not detected that liba has already
been loaded (only the shortname is used for that purpose). And since
your files are in different directories, liba is also not found to be
loaded again. To work around this, you can set LD_LIBRARY_PATH to the
directory containing liba. In that case, when loading libb, the
dependency will be found with the environment search, and since liba was
already loaded, the loop in lines 1085ff. will find the handle and even
assign a shortname. The shortname is only used for checking of
duplicates.

Ciao,
Markus

  reply	other threads:[~2020-05-21 15:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 11:27 Alexander Scherbatiy
2020-05-21 15:21 ` Markus Wichmann [this message]
2020-05-22 18:07   ` Alexander Scherbatiy
2020-05-22 18:25     ` Rich Felker
2020-05-23 14:12       ` Florian Weimer
2020-05-23 16:05         ` Rich Felker
2020-05-25 17:26       ` Alexander Scherbatiy
2020-05-25 17:46         ` Rich Felker
2020-05-27 18:10           ` Dmitry Samersoff
2020-05-28 18:53             ` Szabolcs Nagy
2020-05-28 19:20             ` Jeffrey Walton
2020-05-28 19:29               ` Rich Felker
2020-06-04 19:37           ` Alexander Scherbatiy
2020-06-04 19:48             ` 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=20200521152121.GA6521@voyager \
    --to=nullplan@gmx.net \
    --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).