dlopen() fails on Android but works on Linux

1.1k Views Asked by At

I'm trying to dynamically load a specific shared library using dlopen() in lazy mode. There are of course unresolved symbols in the shared library, but the lazy mode supposed to ignore them. It does ignore them on Linux, and the resolving actually happens once the symbols are used in run time.

But in Android, it doesn't work, although I use lazy mode, dlopen() fails because of unresolved symbols.

this is the code I'm talking about

retval = dlopen(LOADLIB, RTLD_LAZY); 

What's going on ?

2

There are 2 best solutions below

0
On

maybe because Android bionic DOES NOT support RTLD_LAZY mode even if you dlopen with RTLD_LAZY flag, you can check bionic source code for details.

below is marshmallow bionic code piece:

bool soinfo::prelink_image() {
...
case DT_PLTGOT:
#if defined(__mips__)
     // used by mips and mips64
     plt_got_ = reinterpret_cast<ElfW(Addr)**>(load_bias + d->d_un.d_ptr);
#endif
     // Ignore for other platforms... (because RTLD_LAZY is not supported)
     break;
...
}
1
On

Usually the bionic linker looks for shared libs in cur dir, in system/lib and in vendor/lib. You can check if LD_LIBRARY path is set to include folder in which lib you are trying to link is located.