Closed fnwinter closed 2 years ago
@fnwinter I think pthread_getname_np
is supported by bionic, its source code is here: https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/pthread_setname_np.cpp;l=54?q=pthread_getname_np&ss=android. Android also supports pthread_setname_np
too.
It's not exposed in the NDK 21.4 - is it exposed in a newer one? (should we be using dlsym or somehow finding the symbol at runtime?) Even Meta/Facebook is not using it: https://github.com/facebook/folly/blob/main/folly/system/ThreadName.cpp#L122
It's not exposed in the NDK 21.4 - is it exposed in a newer one? Even Meta/Facebook is not using it: https://github.com/facebook/folly/blob/main/folly/system/ThreadName.cpp#L122
I can found related API exposed by pthread.h
under my NDK directory from 21.0.*:
21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.0.6113669/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.0.6113669/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.3.6528147/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.3.6528147/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.4.7075529/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.4.7075529/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
21.1.6352462/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
21.1.6352462/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
23.0.7196353/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:347:int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
23.0.7196353/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/pthread.h:352:int pthread_setname_np(pthread_t __pthread, const char* __name);
But pthread_getname_np
is introduced for Android SDK 26+:
#if __ANDROID_API__ >= 26
int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCED_IN(26);
#endif /* __ANDROID_API__ >= 26 */
If the minimum SDK is less than 26, maybe it will throw an Exception that API not found. I have encountered similar problem when using a NDK API added from higher SDK than project's minimum SDK.
I hope pthread.h
in my search result is the real header file used by NDK.
@rpavlik What about trying changing minimum SDK to 26 at https://gitlab.freedesktop.org/monado/utilities/percetto-android-build/-/blob/main/percetto-lib/build.gradle.kts#L29 and using pthread_getname_np
again?
There is an example of envoy: https://github.com/envoyproxy/envoy/pull/12011/files.
And the minimum NDK version that supports std::atomic_fetch_or
and std::atomic_fetch_and
is 21.0.6113669 found on my laptop:
21.0.6113669/sysroot/usr/include/stdatomic.h:73:using std::atomic_fetch_or;
21.0.6113669/sysroot/usr/include/stdatomic.h:74:using std::atomic_fetch_or_explicit;
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:221:#define atomic_fetch_or_explicit(object, operand, order) \
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:222: __c11_atomic_fetch_or(object, operand, order)
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:248:#define atomic_fetch_or(object, operand) \
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:249: atomic_fetch_or_explicit(object, operand, memory_order_seq_cst)
21.0.6113669/sysroot/usr/include/stdatomic.h:77:using std::atomic_fetch_and;
21.0.6113669/sysroot/usr/include/stdatomic.h:78:using std::atomic_fetch_and_explicit;
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:219:#define atomic_fetch_and_explicit(object, operand, order) \
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:220: __c11_atomic_fetch_and(object, operand, order)
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:246:#define atomic_fetch_and(object, operand) \
21.0.6113669/sysroot/usr/include/bits/stdatomic.h:247: atomic_fetch_and_explicit(object, operand, memory_order_seq_cst)
ah, great, thanks for doing the digging. The atomic_fetch_or/and is just a qualification issue, my #17 fixes that. I just rebased it.
Testing in my new #26 and seems good so far with the platform 26.
Yep, updating the platform to 26 fixes the pthread issue, while #17 fixes the atomic issue. #26 builds on #17 by adding CMake files and scripts to build an AAR file with a single command. Unlike my earlier percetto-android-build repo, this AAR is marked as belonging to this repo (io.github.olvaffe.percetto
).
@utzcoz thank you for finding the symbol. I will close this issue.
there are no pthread_getname_np, std::atomic_fetch_or, std::atomic_fetch_and functions for android.
I am building with clang11 and ndk (21,23)