From: Ilia K <ki.stfu@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] Cannot dlopen() an already loaded shared library by its SONAME name
Date: Tue, 11 Jan 2022 12:50:33 +0100 [thread overview]
Message-ID: <CAMmqxguXGa2cswmRgVLnX=-4CvA8uRzRmfgXjNdTp73CrBXvrQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1648 bytes --]
Hi!
It turns out that `dlopen()` in musl cannot find the already loaded shared
library using the library soname from the dynamic section, unlike glibc.
Here is a simple demo app:
```
# cat main.c
#include <dlfcn.h>
#include <stdio.h>
#define SOMELIB_DIR "/root/dlopen_file_name_test/somelib/"
#define SOMELIB_NAME "libsomelib.so"
int main() {
void* library_handle = dlopen(SOMELIB_DIR SOMELIB_NAME, RTLD_LAZY |
RTLD_LOCAL);
printf("dlopen first load: %p\n", library_handle);
{
void* library_handle2 = dlopen(SOMELIB_DIR SOMELIB_NAME, RTLD_LAZY
| RTLD_LOCAL | RTLD_NOLOAD);
printf("dlopen by file path: %p\n", library_handle2);
if (library_handle2) dlclose(library_handle2);
}
{
void* library_handle3 = dlopen(SOMELIB_NAME, RTLD_LAZY |
RTLD_LOCAL); // RTLD_NOLOAD doesn't work either
printf("dlopen by file name: %p %s\n", library_handle3,
library_handle3 ? NULL : dlerror());
if (library_handle3) dlclose(library_handle3);
}
if (library_handle) dlclose(library_handle);
return 0;
}
# cat somelib.c
int somelib_func() { return 0; }
# cat Makefile
all:
mkdir -p somelib
gcc -shared somelib.c -Wl,-soname,libsomelib.so -o
somelib/libsomelib.so
gcc main.c -o main -ldl
```
Compile & run:
```
# make
mkdir -p somelib
gcc -shared somelib.c -Wl,-soname,libsomelib.so -o somelib/libsomelib.so
gcc main.c -o main -ldl
# ./main
dlopen first load: 0x7f06a28a4ca0
dlopen by file path: 0x7f06a28a4ca0
dlopen by file name: 0 Error loading shared library libsomelib.so: No such
file or directory
```
Do you have any plans to support it?
--
- Ilia
[-- Attachment #2: Type: text/html, Size: 2090 bytes --]
next reply other threads:[~2022-01-11 13:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 11:50 Ilia K [this message]
2022-01-11 17:55 ` Markus Wichmann
2022-01-11 21:30 ` Harmen Stoppels
2022-01-11 22:22 ` Rich Felker
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='CAMmqxguXGa2cswmRgVLnX=-4CvA8uRzRmfgXjNdTp73CrBXvrQ@mail.gmail.com' \
--to=ki.stfu@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).