问题
I have a shared library compiled with 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
$ 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.
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
.
Maybe there is a way to rename musl's libc.so
to musl-libc.so
?
回答1:
Is it possible to have both GNU and musl libc.so in the same process?
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
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.
Maybe there is a way to rename musl's libc.so to 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.
回答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.
来源:https://stackoverflow.com/questions/30151808/load-both-musl-libc-so-and-gcc-libc-so-in-the-same-process