Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: undefined reference to 'pthread_cond_timedwait_monotonic_np' for android-14 and android-15 #708

Closed
ilyatal opened this issue May 29, 2018 · 7 comments
Assignees
Milestone

Comments

@ilyatal
Copy link

ilyatal commented May 29, 2018

Description

Linker failure happens when building a c file with pthread_cond_timedwait_monotonic_np function using NDK 17:

 /opt/android-ndk/android-ndk-r17/ndk-build V=1 -B APP_ABI=armeabi-v7a APP_PLATFORM=android-
14
rm -f ./libs/arm64-v8a/* ./libs/armeabi-v7a/* ./libs/x86/* ./libs/x86_64/*
rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
[armeabi-v7a] Compile thumb  : pthreadtest <= pthreadtest.c
/opt/android-ndk/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -MMD -MP -MF ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o.d -gcc-toolchain /opt/android-ndk/android-ndk-r17/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -g -target armv7-none-linux-androideabi14 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -DNDEBUG  -Ijni   -DANDROID -DHAVE_PTHREADS -D__ANDROID_API__=14 -Wa,--noexecstack -Wformat -Werror=format-security  --sysroot /opt/android-ndk/android-ndk-r17/sysroot -isystem /opt/android-ndk/android-ndk-r17/sysroot/usr/include/arm-linux-androideabi -c  jni/pthreadtest.c -o ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o
[armeabi-v7a] Executable     : pthreadtest
/opt/android-ndk/android-ndk-r17/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/opt/android-ndk/android-ndk-r17/platforms/android-14/arch-arm -Wl,-rpath-link=/opt/android-ndk/android-ndk-r17/platforms/android-14/arch-arm/usr/lib -Wl,-rpath-link=./obj/local/armeabi-v7a ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o -lgcc -Wl,--exclude-libs,libgcc.a -latomic -Wl,--exclude-libs,libatomic.a  -gcc-toolchain /opt/android-ndk/android-ndk-r17/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -no-canonical-prefixes -target armv7-none-linux-androideabi14 -Wl,--fix-cortex-a8  -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings    -lc -lm -o ./obj/local/armeabi-v7a/pthreadtest
jni/pthreadtest.c:5: error: undefined reference to 'pthread_cond_timedwait_monotonic_np'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/armeabi-v7a/pthreadtest] Error 1

pthreadtest.c file conents:

#include <stdio.h>
#include <pthread.h>

int main(int argc, char ** argv){
        pthread_cond_timedwait_monotonic_np(NULL, NULL, NULL);
        return 0;
}

Android.mk file contents:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_CFLAGS += -DHAVE_PTHREADS
LOCAL_MODULE    := pthreadtest
LOCAL_SRC_FILES := pthreadtest.c

include $(BUILD_EXECUTABLE)

Environment Details

NDK:
Pkg.Desc = Android NDK
Pkg.Revision = 17.0.4754217

@enh
Copy link
Contributor

enh commented May 29, 2018

seems WAI... this function wasn't added until API 16. or are you asking "why wasn't this a compile-time error rather than a link-time error"?

here's the complete truth from the map:

libc/libc.map.txt:    pthread_cond_timedwait_monotonic_np; # introduced-arm=16 introduced-x86=16 introduced-mips=16 introduced-arm64=28 introduced-x64_64=28 introduced-mips64=28

but the header file just has

int pthread_cond_timedwait_monotonic_np(pthread_cond_t* __cond, pthread_mutex_t* __mutex,
                                        const struct timespec* __timeout) __INTRODUCED_IN_64(28);

i'm not sure why there's no __INTRODUCED_IN_32(16) there... maybe https://android-review.googlesource.com/c/platform/bionic/+/695276 will tell us...

@ilyatal
Copy link
Author

ilyatal commented May 29, 2018

Thanks for clarification! Before, using NDK 16b, I was able to compile this function, that's why issue was raised.

/opt/android-ndk/android-ndk-r16b/ndk-build V=1 -B APP_ABI=armeabi-v7a APP_PLATFORM=android-14
rm -f ./libs/arm64-v8a/* ./libs/armeabi/* ./libs/armeabi-v7a/* ./libs/mips/* ./libs/mips64/* ./libs/x86/* ./libs/x86_64/*
rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/mips64/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/mips64/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
[armeabi-v7a] Compile thumb  : pthreadtest <= pthreadtest.c
/opt/android-ndk/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -MMD -MP -MF ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o.d -gcc-toolchain /opt/android-ndk/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -g -target armv7-none-linux-androideabi14 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -DNDEBUG  -Ijni   -DANDROID -DHAVE_PTHREADS -D__ANDROID_API__=14 -Wa,--noexecstack -Wformat -Werror=format-security  --sysroot /opt/android-ndk/android-ndk-r16b/sysroot -isystem /opt/android-ndk/android-ndk-r16b/sysroot/usr/include/arm-linux-androideabi -c  jni/pthreadtest.c -o ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o
[armeabi-v7a] Executable     : pthreadtest
/opt/android-ndk/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/opt/android-ndk/android-ndk-r16b/platforms/android-14/arch-arm -Wl,-rpath-link=/opt/android-ndk/android-ndk-r16b/platforms/android-14/arch-arm/usr/lib -Wl,-rpath-link=./obj/local/armeabi-v7a ./obj/local/armeabi-v7a/objs/pthreadtest/pthreadtest.o -latomic -Wl,--exclude-libs,libatomic.a  -gcc-toolchain /opt/android-ndk/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -no-canonical-prefixes -target armv7-none-linux-androideabi14 -Wl,--fix-cortex-a8  -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings    -lc -lm -o ./obj/local/armeabi-v7a/pthreadtest
[armeabi-v7a] Install        : pthreadtest => libs/armeabi-v7a/pthreadtest
install -p ./obj/local/armeabi-v7a/pthreadtest ./libs/armeabi-v7a/pthreadtest
/opt/android-ndk/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-unneeded  ./libs/armeabi-v7a/pthreadtest

@ilyatal ilyatal closed this as completed May 29, 2018
@enh
Copy link
Contributor

enh commented May 29, 2018

yeah, in NDK r16 this was in a __ANDROID_API__ < 21 block (because we didn't really keep good data for very old API levels, and no-one had ever noticed that this test wasn't exactly right).

in NDK r17 we added the 64-bit guard but accidentally dropped the 32-bit guard.

https://android-review.googlesource.com/c/platform/bionic/+/695276 fixes this, but given that API 16 is the lowest API level supported by NDK r17 i'm not sure i'll actually get +2 on that change :-)

@enh enh reopened this May 29, 2018
@enh
Copy link
Contributor

enh commented May 29, 2018

actually, we did screw up here... my earlier claim assumed that the map was correct, but it's been pointed out to me by @rprichard that the active ingredient that caused your problem is that we accidentally changed the map.

from the git history, this function wasn't in cupcake (which was our earlier claim), but was definitely in gingerbread (which pre-dates our current claim). so i'll abandon my earlier change and upload a new one to fix the map to admit that this function was available in at least gingerbread. hopefully there's still time to get this into r17b...

@enh
Copy link
Contributor

enh commented May 29, 2018

@enh enh self-assigned this May 29, 2018
@enh enh added this to the r17b milestone May 29, 2018
hubot pushed a commit to aosp-mirror/platform_bionic that referenced this issue May 30, 2018
Bug: android/ndk#708
Test: builds
Change-Id: Icaa1f8cb796a0a117cbe2e10391c965c857d6d37
@DanAlbert DanAlbert assigned DanAlbert and unassigned enh May 30, 2018
@DanAlbert
Copy link
Member

@enh fixed the map, over to me to update the NDK's sysroot.

@DanAlbert
Copy link
Member

Updates merged into r17.

sepehrst pushed a commit to spsforks/android-bionic-libc that referenced this issue Apr 22, 2024
Bug: android/ndk#708
Test: N/A
Change-Id: Ic72bbae7ab98182731a706348a8ddb6e8e28f59e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants