-
Notifications
You must be signed in to change notification settings - Fork 266
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
[BUG] __cxa_get_globals() does not use thread_local and __cxa_thread_atexit() is not called #1200
Comments
My first guess was that this was because bionic doesn't have I'm building/testing with that flag flipped right now. It looks like you're correct and it should Just Work. This might also be somewhat related to #360 (comment), in which case there will be at least a corner of this bug that's unfixable for old releases. Thanks for the detailed report and investigation, btw! Assuming this fix does work, I'll get your test case added to our regression suite. |
Thanks @DanAlbert for looking into it and adding to the r22 milestone. Issue #360 does look related. Since newer bionic releases delay the library unloading while there are pending |
I did get as far as running all our existing tests with that flag set and encountered no issues. Still need to verify your test case though. |
Confirmed that your test case fails with r21 (not that I didn't believe you, just wanted to make sure I'd integrated it into our test suite right!) and that it passes with the change you suggested. https://android-review.googlesource.com/c/platform/ndk/+/1285595 Thanks again for making this easy on us :) |
Glad I could contribute something useful :-) |
After NDK r22 it longer crashes after dlclose, see: android/ndk#1200 Fix supertuxkart#3000
After NDK r22 it longer crashes after dlclose, see: android/ndk#1200 Fix supertuxkart#3000
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). [1] https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Reviewed By: #libc_abi, MaskRay, ldionne Differential Revision: https://reviews.llvm.org/D138461
Bug: android/ndk#1200 Test: None Change-Id: Ib37c85f2e99a1869206a0dcb6542dc0f386bba73
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). This is a re-application of https://reviews.llvm.org/D138461. Fixes llvm#78207. [1]: https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Co-Authored-By: Shoaib Meenai <smeenai@fb.com>
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). This is a re-application of https://reviews.llvm.org/D138461. Fixes llvm#78207. [1]: https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Co-Authored-By: Shoaib Meenai <smeenai@fb.com>
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). This is a re-application of https://reviews.llvm.org/D138461. Fixes llvm#78207. [1]: https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Co-Authored-By: Shoaib Meenai <smeenai@fb.com>
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). This is a re-application of https://reviews.llvm.org/D138461. Fixes llvm#78207. [1]: https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Co-Authored-By: Shoaib Meenai <smeenai@fb.com>
This was previously guarded by HAS_THREAD_LOCAL, which was never set by CMake and had to be specified manually. Android has been setting this to solve android/ndk#1200 [1], but every compiler and platform libc++abi supports should have thread_local by now, so we can just get rid of the fallback implementation and simplify things significantly (including removing the now unused fallback calloc). [1] https://android-review.googlesource.com/c/toolchain/llvm-project/+/1285596 Reviewed By: #libc_abi, MaskRay, ldionne Differential Revision: https://reviews.llvm.org/D138461
I am having this issue with a dynamically loaded library that uses the static STL (libc++_static.a).
When code from another library calls code in the loaded library that in turn calls the STL
__cxa_get_globals()
function (like when throwing an exception), and the loaded library and its STL is unloaded before the thread exits, the process crashes.Here is code to reproduce this issue:
testlib.cpp
test.cpp
and the crash trace:
I tracked down the issue to the implementation of
__cxa_get_globals()
incxa_exception_storage.cpp
. The STL is compiled withHAS_THREAD_LOCAL
undefined (shouldn't it be defined?) and the fallback implementation for__cxa_get_globals()
that is used in that case installs a pthread key with a destructor directly and without calling__cxa_thread_atexit()
. Since it doesn't, the library gets unloaded before the thread exits with the code above and when the thread does exit, the now gone pthread key destructor is then called and the crash happens.Recompiling the STL with
HAS_THREAD_LOCAL
defined uses thethread_local
implementation of__cxa_get_globals()
and thus__cxa_thread_atexit()
is called behind the scenes and the crash does not happen and the library is unloaded after the thread exits.Environment Details
The text was updated successfully, but these errors were encountered: