-
Notifications
You must be signed in to change notification settings - Fork 13.3k
crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64 #135815
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
Comments
What is the difference between the problem in this issue and the one in #134820? |
134820 compile rust src to .a, then link to a c++ so. Additionally, we have provided some new information, which we thought is very important. for android/ohos,
But the whole path we still not figure out. |
issue will be fix and the annoying |
Most libc implementations I know of silently refuse to unload shared libraries when they make use of native TLS support as |
However, in the Rust code compiled with the Android and OHOS build options, simply calling println! implicitly generates a thread-local key. This seems to suggest that calling Rust code via dlopen/dlclose is not supported on Android/OHOS, which clearly seems unreasonable. |
dlopen is supported, dlclose is not. Maybe we should just set the ELF flag to prevent shared libraries from getting unloaded on dlclose. |
Is there a way to support dlclose for so with Rust code on Android/OHOS platforms? This is important because in terminal scenarios, there is a strict requirement for persistent memory, and many usage patterns of so involve dlclose and dlopen. |
A dlopen of the same shared library without dlclose in between will not increase memory usage. It will just increase the reference count of the already loaded copy of the shared library. Dlclose is unfortunately simply not supported when thread local storage is used. And even without thread local storage there are various restrictions you need to follow to safely support dlclose. For example you may not spawn a background thread that outlives the dlclose, you may not register an atexit handler or similar from your shared library, you may not keep any function pointers alive that could be called after dlclose and more. Running your code in a separate process which gets terminated at the point where you currently try to use dlclose is likely much easier to implement. |
crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64
Senario:
Related issues #134820
reproduction code
Here's the translation of the provided text:
Known Information:
TPIDR_EL0
.has_thread_local=true and tls-model=emulated
, but these two compilation options do not seem to take effect when compiling the shared object (suspected that the standard library needs to be recompiled with these options). The implementation ofprintl
is part of the Rust standard library.tls-model=emulated
option affects the rustc compilation behavior (either usingTPIDR_EL0
or emulated TLS, by affecting the LLVM backend).This seems to be a bug in the rustc implementation. In the combination of Android and OHOS target platform options, during the println process, a thread-local variable is implicitly created, and the thread-local resources initialized through lazy_init are not properly released when dlclose is called.
The text was updated successfully, but these errors were encountered: