I'm trying to dynamically load a library from within a chroot. The said library depends on glibc and its version is different from my host (host has 2.26, chroot has 2.23).
Is there a way to achieve that?
Here is what I tried:
$ curl http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/ubuntu-base-16.04-core-amd64.tar.gz | tar -C ubuntu -xz
#include <unistd.h>
#include <dlfcn.h>
int main(int argc, char *argv[])
{
chdir("ubuntu");
chroot(".");
// 1. This will fail
dlopen("libpthread.so.0", RTLD_NOW);
// 2. This will crash
dlmopen(LM_ID_NEWLM, "libpthread.so.0", RTLD_NOW);
return 0;
}
Obviously fails because there is a glibc mismatch:
/lib/x86_64-linux-gnu/libpthread.so.0: symbol __libc_dl_error_tsd, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference
Crashes with the following output from valgrind:
==19923== Process terminating with default action of signal 4 (SIGILL): dumping core ==19923== Illegal opcode at address 0x401D41C ==19923== at 0x401D41C: ??? (in /usr/lib/ld-2.26.so) ==19923== by 0x4013932: dl_open_worker (in /usr/lib/ld-2.26.so) ==19923== by 0x516EB63: _dl_catch_error (in /usr/lib/libc-2.26.so) ==19923== by 0x4013279: _dl_open (in /usr/lib/ld-2.26.so) ==19923== by 0x4E3A8CF: ??? (in /usr/lib/libdl-2.26.so) ==19923== by 0x516EB63: _dl_catch_error (in /usr/lib/libc-2.26.so) ==19923== by 0x4E3A586: ??? (in /usr/lib/libdl-2.26.so) ==19923== by 0x4E3A9B6: dlmopen (in /usr/lib/libdl-2.26.so)