mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Cannot dlopen() an already loaded shared library by its SONAME name
@ 2022-01-11 11:50 Ilia K
  2022-01-11 17:55 ` Markus Wichmann
  0 siblings, 1 reply; 6+ messages in thread
From: Ilia K @ 2022-01-11 11:50 UTC (permalink / raw)
  To: musl

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-12 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11 11:50 [musl] Cannot dlopen() an already loaded shared library by its SONAME name Ilia K
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

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).