npth finds pthread_mutex_timedlock() which android does not have
Hans-Christoph Steiner
hans at guardianproject.info
Tue Feb 21 21:03:36 CET 2012
On 02/20/2012 05:16 PM, Hans-Christoph Steiner wrote:
>
> On 02/20/2012 03:07 PM, Hans-Christoph Steiner wrote:
>>
>> Apparently, Android's NDK defines pthread_mutex_timedlock() in the
>> headers but then does not implement it. And it seems they aren't close
>> to implementing it:
>> http://code.google.com/p/android/issues/detail?id=2138
>>
>> This is of course a really crappy situation since it means that you
>> can't do simple things like AC_CHECK_FUNCS([pthread_mutex_timedlock])
>> because that actually finds the function. I made a quick patch which
>> works for getting a build, and I'm building the whole gnupg suite again
>> with npth now. The patch is attached, its not pretty. Let me know if
>> it should be done in another way.
>>
>> npth build on Android currently dies with:
>>
>> /bin/bash ../libtool --tag=CC --mode=link
>> /usr/local/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
>> --sysroot=/usr/local/android-ndk/platforms/android-9/arch-arm -DANDROID
>> -I/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/include
>> -fdata-sections -ffunction-sections -Os
>> -L/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/lib
>> -Wl,--rpath,/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/lib
>> -Wl,--gc-sections -o t-mutex t-mutex.o ../src/libnpth.la
>> libtool: link:
>> /usr/local/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
>> --sysroot=/usr/local/android-ndk/platforms/android-9/arch-arm -DANDROID
>> -I/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/include
>> -fdata-sections -ffunction-sections -Os -Wl,--rpath
>> -Wl,/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/lib
>> -Wl,--gc-sections -o .libs/t-mutex t-mutex.o
>> -L/var/lib/jenkins/jobs/gnupg-for-android/workspace/external/data/data/info.guardianproject.gpg/app_opt/lib
>> ../src/.libs/libnpth.so -Wl,-rpath
>> -Wl,/data/data/info.guardianproject.gpg/app_opt/lib
>> ../src/.libs/libnpth.so: undefined reference to `pthread_mutex_timedlock'
>> collect2: ld returned 1 exit status
>
> Turns out there is another issue with npth on Android. npth_yield is a
> macro for pthread_yield, which Android does not seem to have. I cannot
> find another confirmation of this besides pthread_yield() not being any
> headers.
>
> You can see in this build log that the build says both:
>
> ldap-wrapper.c:471: warning: implicit declaration of function
> 'pthread_yield'
> ldap-wrapper.c:(.text.ldap_wrapper_wait_connections+0x28): undefined
> reference to `pthread_yield'
>
> https://build.safermobile.org/job/gnupg-for-android/12/console
pthread_yield also does not exist on Mac OS X. sched_yield() seems to
be the replacement for Android and Mac OS X. This lets gnupg build on
Android for me:
--- a/npth/src/npth.h.in
+++ b/npth/src/npth.h.in
@@ -55,6 +55,7 @@
#@INSERT_SYS_SELECT_H@
#include <pthread.h>
+#include <sched.h>
#ifdef __cplusplus
extern "C" {
@@ -110,7 +111,7 @@ int npth_create(npth_t *thread, const npth_attr_t *attr,
/* No can do! */
/* pth_suspend, pth_resume */
-#define npth_yield pthread_yield
+#define npth_yield sched_yield
/* Not needed. */
/* pth_nap */
More information about the Gnupg-devel
mailing list