stdcall
stdcall

Reputation: 28900

dlopen() fails on Android but works on Linux

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 ?

Upvotes: 0

Views: 1184

Answers (2)

user14330934
user14330934

Reputation: 11

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;
...
}

Upvotes: 1

Kinjal
Kinjal

Reputation: 21

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.

Upvotes: 0

Related Questions