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

时间:2022-03-01 05:52:49

I have a shared library compiled with musl libc

我有一个用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

It links to musl's libc.so

它链接到musl的libc.so

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

Now I have problem to load this shared object into java application. But if I restore the linking back to GNU's libc.so, it works.

现在我有问题将这个共享对象加载到java应用程序中。但是如果我将链接恢复到GNU的libc.so,它就可以了。

Is it possible to have both GNU and musl libc.so in the same process? The java application relies on GNU's libc.so, but I want my shared object use musl's libc.so.

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

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

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

2 个解决方案

#1


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

是否有可能在同一过程中同时拥有GNU和musl libc.so?

It's possible to load them both, yes. But the result will promptly crash, so it's a useless thing to do.

可以加载它们,是的。但结果会立即崩溃,所以这是一件无用的事情。

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

但我希望我的共享对象使用musl的libc.so

But why?

In any case, you'll never get musl and glibc to cooperate, your choices are to either use glibc for everything, or use musl for everything.

无论如何,你永远不会让musl和glibc合作,你的选择是要么将glibc用于一切,要么将musl用于一切。

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

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

They are already named differently: libc.so vs. libc.so.6. Naming of the library doesn't matter. The fact that they both provide the same (conflicting) symbols is what matters.

它们的命名方式不同:libc.so与libc.so.6。库的命名无关紧要。它们都提供相同(冲突)符号的事实才是最重要的。

#2


Most definitely it is possible but you will need to write your own loader. This is a significant task - although you will be able to copy most of it from the existing 'musl' and 'glibc' loaders.

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

#1


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

是否有可能在同一过程中同时拥有GNU和musl libc.so?

It's possible to load them both, yes. But the result will promptly crash, so it's a useless thing to do.

可以加载它们,是的。但结果会立即崩溃,所以这是一件无用的事情。

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

但我希望我的共享对象使用musl的libc.so

But why?

In any case, you'll never get musl and glibc to cooperate, your choices are to either use glibc for everything, or use musl for everything.

无论如何,你永远不会让musl和glibc合作,你的选择是要么将glibc用于一切,要么将musl用于一切。

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

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

They are already named differently: libc.so vs. libc.so.6. Naming of the library doesn't matter. The fact that they both provide the same (conflicting) symbols is what matters.

它们的命名方式不同:libc.so与libc.so.6。库的命名无关紧要。它们都提供相同(冲突)符号的事实才是最重要的。

#2


Most definitely it is possible but you will need to write your own loader. This is a significant task - although you will be able to copy most of it from the existing 'musl' and 'glibc' loaders.

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