Debugging shared library linking in Android

So Android does let you run command line utilties, but they sure don’t make it easy. I am currently building gnupg for Android, and for some of the binaries I got, they worked fine, others I got this when I ran them:

# ./gpg-agent
link_image[1995]: failed to link gpg-agent-static
CANNOT LINK EXECUTABLE

So my guess was that there was some missing shared libs, I checked that using readelf -d gpg-agent. All of the libraries listed were included in my setup and they were found once I did:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/info.guardianproject.gpg/app_opt/lib

And yet, I still got this error. My final hunch was that my binaries included some symbols which Android’s libs did not provide. But how could I find out which symbols were the problem? I discovered you can use ld, so I did:

hans@palatschinken lib $ adb pull /system/lib /tmp/system-lib
hans@palatschinken lib $ cp *.so* /tmp/system-lib
hans@palatschinken lib $ for so in *.so; do echo $so; arm-linux-androideabi-ld $so -rpath=/tmp/system-lib; done
libassuan.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008254
libgcrypt.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008258
libgpg-error.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008258
libksba.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008254
liblber.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008258
libldap_r.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008258
libldap_r.so: undefined reference to `pthread_rwlock_rdlock'
libldap_r.so: undefined reference to `pthread_rwlock_init'
libldap_r.so: undefined reference to `pthread_rwlock_destroy'
libldap_r.so: undefined reference to `pthread_rwlock_unlock'
libldap_r.so: undefined reference to `pthread_rwlock_wrlock'
libldap_r.so: undefined reference to `pthread_rwlock_trywrlock'
libldap_r.so: undefined reference to `pthread_rwlock_tryrdlock'
libldap.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008258
libnpth.so
arm-linux-androideabi-ld: warning: cannot find entry symbol _start; defaulting to 00008254

And voila! There were the symbols in question. Indeed, Android does not provide pthread_rwlock_*.


You must be logged in to post a comment.

Follow

Get every new post delivered to your Inbox.