在同一进程中同时加载 musl libc.so 和 gcc libc.so?

Load both musl libc.so and gcc libc.so in the same process?

我有一个用 musl libc 编译的共享库

$ readelf -d ./libinterop_d.so 

Dynamic section at offset 0x8ecb0 contains 22 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
 0x000000000000000f (RPATH)              Library rpath: [/usr/local/musl/lib]
 0x000000000000000c (INIT)               0x46350
 0x000000000000000d (FINI)               0x7664a
 0x0000000000000019 (INIT_ARRAY)         0x28e700
 0x000000000000001b (INIT_ARRAYSZ)       64 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x28e740
 0x000000000000001c (FINI_ARRAYSZ)       16 (bytes)
 0x0000000000000004 (HASH)               0x158
 0x0000000000000005 (STRTAB)             0xc940
 0x0000000000000006 (SYMTAB)             0x2bc0
 0x000000000000000a (STRSZ)              203286 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x28f000
 0x0000000000000002 (PLTRELSZ)           28056 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x3f5b8
 0x0000000000000007 (RELA)               0x3e358
 0x0000000000000008 (RELASZ)             4704 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffff9 (RELACOUNT)          46
 0x0000000000000000 (NULL)               0x0

它链接到 musl 的 libc.so

$ ldd ./libinterop_d.so 
    linux-vdso.so.1 =>  (0x00007fff566c9000)
    libc.so => /usr/local/musl/lib/libc.so (0x00007f111398c000)

现在我无法将此共享对象加载到 java 应用程序中。 但是,如果我将链接恢复到 GNU 的 libc.so,它就可以工作了。

是否可以在同一个进程中同时使用 GNU 和 musl libc.so? java 应用程序依赖于 GNU 的 libc.so,但我希望我的共享对象使用 musl 的 libc.so

也许有办法将 musl 的 libc.so 重命名为 musl-libc.so

Is it possible to have both GNU and musl libc.so in the same process?

可以同时加载它们,是的。但是结果会立即崩溃,所以这样做是没有用的。

but I want my shared object use musl's libc.so

但是为什么呢?

无论如何,musl 和 glibc 永远不会合作,您的选择是要么全部使用 glibc,要么全部使用 musl。

Maybe there is a way to rename musl's libc.so to musl-libc.so

它们已经 命名不同:libc.solibc.so.6。图书馆的命名并不重要。它们都提供相同(冲突)符号这一事实才是最重要的。

绝对有可能但是您需要编写自己的加载程序。这是一项重要的任务 - 尽管您可以从现有的 'musl' 和 'glibc' 加载程序中复制其中的大部分内容。